Created
February 8, 2018 12:39
-
-
Save tusmester/3ae368d1579fca2e10cd802ae9466983 to your computer and use it in GitHub Desktop.
#sn #mvc #model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel.DataAnnotations; | |
using System.Linq; | |
using SenseNet.ContentRepository; | |
using SenseNet.ContentRepository.Storage.Security; | |
using SenseNet.Search; | |
namespace SnWebApplication.Models | |
{ | |
public class TaskViewModel | |
{ | |
public readonly Task Task; | |
private int _id; | |
public int Id | |
{ | |
get { return _id > 0 ? _id : Task?.Id ?? 0; } | |
set { _id = value; } | |
} | |
private string _displayName; | |
[Required] | |
[Display(Name = "Short description")] | |
public string DisplayName | |
{ | |
get { return _displayName ?? Task?.DisplayName; } | |
set | |
{ | |
if (Task != null) | |
Task.DisplayName = value; | |
_displayName = value; | |
} | |
} | |
private string _description; | |
[Display(Name = "Details")] | |
public string Description | |
{ | |
get { return _description ?? Task?.Description; } | |
set | |
{ | |
if (Task != null) | |
Task.Description = value; | |
_description = value; | |
} | |
} | |
[Display(Name = "Assigned to")] | |
public string AssignedToText => SystemAccount.Execute(() => Task?.GetReference<User>("AssignedTo")?.DisplayName) ?? string.Empty; | |
private int _assignedTo; | |
[Display(Name = "Assigned to")] | |
public int AssignedToId | |
{ | |
get { return _assignedTo > 0 ? _assignedTo : SystemAccount.Execute(() => Task?.GetReference<User>("AssignedTo")?.Id) ?? 0; } | |
set { _assignedTo = value; } | |
} | |
public DateTime DueDate => (DateTime)(Task?["DueDate"] ?? DateTime.MaxValue); | |
public static IEnumerable<User> Users => ContentQuery.Query("+TypeIs:User .SORT:Name .TOP:10").Nodes.Cast<User>(); | |
public TaskViewModel() | |
{ | |
} | |
public TaskViewModel(Task task) | |
{ | |
Task = task; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment