using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Web; using EnVisage.Code; namespace EnVisage.Models { public class NoteModel : IBaseModel { public Guid Id { get; set; } public Guid? ParentId { get; set; } [Required] public string Title { get; set; } public string Details { get; set; } public DateTime DateAdded { get; set; } public AspNetUser Author { get; set; } public int NoteType { get; set; } public List ChildNotes { get; set; } public string CreatedBy { get; set; } public Guid? DomainId { get; set; } public NoteModel() { } public NoteModel(Guid parentId) { ParentId = parentId; } /// /// Casts a obect to the object of type . /// /// A object. /// A object filled with data from db. public static explicit operator NoteModel(Note obj) { if (obj == null) return null; var model = new NoteModel { DateAdded = DateTime.Now, Id = obj.Id, ParentId = obj.ParentId, Title = obj.Title, Details = obj.NoteDetail, Author = new EnVisageEntities().AspNetUsers.FirstOrDefault(x => x.Id == obj.UserId.Value.ToString()), NoteType = obj.NoteType ?? -1, DomainId = obj.DomainId }; model.CreatedBy = (model.Author != null) ? model.Author.UserName : String.Empty; model.TrimStringProperties(); return model; } /// /// Copies data from model to DAL object. /// /// A target DAL object. public void CopyTo(Note dbObj) { if (dbObj == null) throw new ArgumentNullException(); if (dbObj.Id == Guid.Empty) dbObj.Id = Id; dbObj.ParentId = ParentId; dbObj.Title = Title; dbObj.DateAdded = DateTime.Now; dbObj.NoteDetail = Details; dbObj.NoteType = NoteType; dbObj.DomainId = DomainId; dbObj.UserId = Author != null ? new Guid(Author.Id) : new Guid(HttpContext.Current.User.Identity.GetID()); } } }