using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; namespace EnVisage.Models { public class CompanyModel : IBaseModel { public CompanyModel() { Watchers = new List(); Contributors = new List(); } public Guid Id { get; set; } [Required] [MaxLength(100)] public string Name { get; set; } [Display(Name = "Business Unit")] public Guid? ParentCompanyId { get; set; } [Display(Name = "Business Unit")] public string ParentCompanyName { get; set; } [Display(Name = "Number of Projects")] public int ProjectsCount { get; set; } [Display(Name = "Number of Business Units")] public int CompaniesCount { get; set; } [Display(Name = "Number of Teams")] public int TeamsCount { get; set; } public IList ClientId { get; set; } public IList ViewId { get; set; } [Display(Name = "Business Unit Watchers")] public List Watchers { get; set; } public string WatchersAsText { get { string result = String.Empty; if ((this.Watchers != null) && (this.Watchers.Count > 0)) { foreach (Guid userId in this.Watchers) { result += "," + userId.ToString(); } result = result.Substring(1); } return result; } } [Display(Name = "Business Unit Contributors")] public List Contributors { get; set; } public string ContributorsAsText { get { string result = String.Empty; if ((this.Contributors != null) && (this.Contributors.Count > 0)) { foreach (Guid userId in this.Contributors) { result += "," + userId.ToString(); } result = result.Substring(1); } return result; } } /// /// Copies data from model to DAL object. /// /// A target DAL object. public void CopyTo(Company dbObj) { if (dbObj == null) throw new ArgumentNullException(); dbObj.Name = Name; dbObj.ParentCompanyId = ParentCompanyId; } } public class CompanyApiModel { public Guid Id { get; set; } public string Name { get; set; } public Guid? ParentCompanyId { get; set; } #region Constructors public CompanyApiModel() { } public CompanyApiModel(CompanyModel model) : this() { if (model == null) throw new ArgumentNullException("model"); Id = model.Id; Name = model.Name; ParentCompanyId = model.ParentCompanyId; } public CompanyApiModel(Company model) : this() { if (model == null) throw new ArgumentNullException("model"); Id = model.Id; Name = model.Name; ParentCompanyId = model.ParentCompanyId; } #endregion } }