skip to content
  • 16 June 2013

    Three Steps to Get Fat-Razor MVC Views on Diet

    Fat Razor in MVC

    Let me first define the terms that I will be referring to:

    Presentation Code: Is the minimal code in a view that is necessary to display visual elements, but does not take any business decision. This is a fictional simple example:

        // Business Logic Code. This code understands how the business works
        // (don't do this)
        @if (Model.IsMonthly && !Model.IsPaid && Model.Payment >= 12 && ...)
        {
    	    <p>Some warning message</p>
        }
        
        // Presentation Code. This code is only concerned with whether to
        // show or hide a UI element.
        @if (Model.ShouldWarn)
        {
    	    <p>Some warning message</p>
        }
    

    Fat-Razor: I’ve coined this term to define ASP.NET Razor views with a lot of Razor/C# code that is not presentation code. This is about the Razor/C# code specifically and not about HTML/CSS/JS.

    Model: This is an overloaded term. However, in this context, it is an object of data representation such as a record in the database.

    Viewmodel: They are data transfer objects that are meant to be view-specific and to carry exactly what the view needs, no less and no more. Generally, viewmodels are non-reusable and each vm is meant to to be tightly coupled to one view, however, there are exceptions depending on what you are doing.

    To give you a flavour of a model and a viewmodel:

    // An example of a model
    public class Person
    {
        public Guid PersonId { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public short YearOfBirth { get; set; }
        public DateTime LastAuth { get; set; }
        // This might represent a one-to-many db relationship
        public Order[] Orders { get; set; }
    }
    
    // An example of a viewmodel
    public class ProfileViewModel
    {
        // Doesn't necessarily need an id
    
        // Combined first and last name
        public string Name { get; set; }
        // Calculated from YearOfBirth
        public short Age { get; set; }
        // E.g. "One day ago" and constructed from LastAuth
        public string LastSeen { get; set; }
        // Calculated by projections on Orders
        public short NumberOfAllOrders { get; set; }
        public short NumberOfUndeliveredOrders { get; set; }
    }
    

    Read the rest of this entry »

  • 30 July 2012

    Using C# .NET User Defined Functions (UDF) in Excel

    N.B.Throughout this post I am using Excel 2010 and Visual Studio 2010.

    Writing a UDF in VBA to be exposed to Excel cells is straight forward, just write the function in a VBA module and Bob’s your uncle. However, it is slightly trickier to expose your functions to Excel in a managed language, such as C# or F#.

    Read the rest of this entry »

  • 20 September 2010

    PayPal Charity Hack 2010 and JustGiving REST APIs

    Speaking to the developers about JustGiving’s RESTful APIs

    Charity Hack is an annual event held and sponsored by PayPal UK at their venue in Richmond, London on a Saturday and a Sunday. It is an event where developers from different backgrounds are invited and introduced to different charity-relaled organisations APIs where developers are encouraged to hack useful apps using these APIs.

    We introduced, as JustGiving, our new RESTful APIs and demonstrated how to use them.

    Having a discussion with JustGiving developers (back to camera)

    Tagged under: | 1 comment
  • 30 September 2008

    Three C# 2.0/3.0 Syntaxes That You Didn’t Know But Were Afraid to Ask

    Working with other colleagues, I found these C# syntaxes are still not well-known and used, so I thought of blogging on them.

    1 – Properties Without Members

    In the old days, before C# 3.0, we used to write syntax like:

    Read the rest of this entry »

    Tagged under: | 14 comments
  • 30 September 2008

    UK Software Consultant Nightmare: The IT Recruiting Agents

    UK Software Consultant and Recruiting Agent

    Working as a .NET software consultant in UK, I spent ages with the IT recruiting agents on the phone and had suffered their tricks. So, in this post, I thought of educating my software consultant colleagues of the agents’ sneaky tricks and dodgy tactics.

    Recruiting agents, especially in the current credit crunch, are having less ‘productive’ work to do due to the reduced demands in the market, so they are spending more time wasting our “software consultants” time and resources rather than doing their actual role which is, obviously, recruiting!

    Below are some of their tricks, tactics and some commonly used phrases on the phone:

    Read the rest of this entry »