Database Reference
In-Depth Information
" tagstr: p.tagstr, timestamp: p.timestamp, userNameForPost: f.username,
owner: f=u}"))
.OrderByDescending("p.timestamp")
.Skip(page)
.Limit(pagesize)
.Results.ToList();
return graphStory;
}
Using View Models
For many applications, it is necessary to return only certain elements of the model to complete the parts of the view.
In addition, the view sometimes requires display elements that are not provided within the core model objects. In the
case of .NET applications, the solution to this challenge is to add classes known as ViewModels.
For example, the MappedContent shown in Listing 7-31 allows the application to return properties from both
the Content and User classes as well as properties, such as the TimestampAsStr, that are modifications of an existing
property. As you walk through the remainder of the graph examples, you will review a number of the ViewModel
classes that were created to satisfy the needs within the View sections of the application.
Listing 7-31. The View Model Object: Mapped Content
public class MappedContent
{
public string contentId { get; set; }
public string title { get; set; }
public string url { get; set; }
public string tagstr { get; set; }
public long timestamp { get; set; }
public string userNameForPost { get; set; }
private string TimestampAsStr;
public string timestampAsStr
{
get
{
System.DateTime datetime = new DateTime(1970, 1, 1, 0, 0, 0, 0,
System.DateTimeKind.Utc);
datetime = datetime.AddSeconds(this.timestamp).ToLocalTime();
this.timestampAsStr = datetime.ToString("MM/dd/yyyy") + " at " + datetime.
ToString("h:mm tt");
return TimestampAsStr;
}
set
{
TimestampAsStr = value;
}
}
public bool owner { get; set; }
}
 
Search WWH ::




Custom Search