using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Web; using EnVisage.Code; namespace EnVisage.Models { public class AttachmentModel : IBaseModel { public Guid Id { get; set; } public string Name { get; set; } public int Size { get; set; } public string ContentType { get; set; } public bool IsNew { get; set; } /// /// Casts a obect to the object of type . /// /// An object /// A object filled with data from db public static explicit operator AttachmentModel(Attachment obj) { if (obj == null) return null; var model = new AttachmentModel { Id = obj.Id, Name = obj.SourceFileName, Size = obj.FileSize.HasValue ? obj.FileSize.Value : 0, ContentType = obj.ContentType, IsNew = false, }; model.TrimStringProperties(); return model; } /// /// Copies data from model to DAL object. /// /// A target DAL object public void CopyTo(Attachment dbObj) { if (dbObj == null) throw new ArgumentNullException(); dbObj.Id = Id; dbObj.SourceFileName = Name; dbObj.ContentType = ContentType; dbObj.FileSize = Size; } } }