using System.Linq; using System; using System.Collections.Generic; using EnVisage.Code.DAL.Mongo; namespace EnVisage.Models { public class MixSaveModel : MixModelBase { public MixCalendarModel Calendar { get; set; } public MixFilterModel Filter { get; set; } public bool CanRunResourceRace { get; set; } public bool CanRunTeamRace { get; set; } public bool canDoRace { get; set; } public bool TeamLevelRace { get; set; } public MixSaveModel() : base() { Calendar = new MixCalendarModel(); Filter = new MixFilterModel(); } /// /// Copies property values from current object of type to object of type entity. /// /// An object of type. public void CopyTo(Mix obj) { if (obj == null) throw new ArgumentNullException("obj"); obj.Name = Name; obj.StartDate = StartDate; obj.EndDate = EndDate; obj.CreatedBy = CreatedBy; obj.Teams = Calendar.Teams.Select(t => new MixTeam { Id = t.Id, Name = t.Name, CompanyId = t.CompanyId, CostCenterId = t.CostCenterId, UserId = t.UserId, IsNew = t.IsNew, PlannedCapacity = (t.PlannedCapacity != null) ? t.PlannedCapacity.ToArray() : null, ExpCategories = (t.ExpCategories != null) ? t.ExpCategories.Select(e => new ExpCategoryCapacity() { Id = e.Value.Id, Name = e.Value.Name, NeedCapacity = e.Value.NeedCapacity, PlannedCapacityValues = e.Value.PlannedCapacityValues, AllocatedCapacity = e.Value.AllocatedCapacity, ActualCapacityValues = e.Value.ActualCapacityValues, UomValue = e.Value.UomValue, AllowResourceAssignment = e.Value.AllowResourceAssignment, Resources = (e.Value.Resources != null) ? e.Value.Resources.Select(r => new ActivityResource() { Id = r.Value.Id, AllocatedCapacity = r.Value.AllocatedCapacity, TotalCapacity = r.Value.TotalCapacity, }).ToDictionary(kk => kk.Id.ToString(), vv => vv) : null }).ToDictionary(k => k.Id.ToString(), v => v) : null }).ToList(); obj.Users = Users; obj.ManagedProjects = new List(); obj.UnscheduledProjects = new List(); obj.QueuedProjects = new List(); obj.UnassignedExpProjects = new List(); obj.Layout = new List(); obj.TeamsViews = Filter.Selection.TeamsViews.Select(x => new MixTeamView() { Id = x.Id, IsNew = x.IsNew, Name = x.TVName, Group = x.Group.Name, Data = x.Data, CapacityTeamId = x.CapacityTeamId, CompanyId = x.CompanyId, CopyPlanned = x.CopyPlanned, CostCenterId = x.CostCenterId, UserId = x.UserId }).ToList(); if (this.Calendar.ManagedProjects != null) obj.ManagedProjects.AddRange(this.Calendar.ManagedProjects); if (this.Calendar.UnscheduledProjects != null) obj.UnscheduledProjects.AddRange(this.Calendar.UnscheduledProjects); if (this.Calendar.QueuedProjects != null) obj.QueuedProjects.AddRange(this.Calendar.QueuedProjects); if (this.Calendar.UnassignedExpendituresProjects != null) obj.UnassignedExpProjects = this.Calendar.UnassignedExpendituresProjects.Select(t => new CategoryExpenditureInMongoProject() { ProjectId = t.ProjectId, ExpCatId = t.ExpCatId, TargetTeamId = t.TargetTeamId, Name = t.Name, AllowResourceAssignment = t.AllowResourceAssignment }).ToList(); if (Calendar.Projects != null) { obj.Projects = Calendar.Projects.Where(x => x.Value != null) .Select(p => (new MixProject(p.Value))) .ToDictionary(p => p.Id.ToString()); } if (Calendar.Layout != null) { obj.Layout = this.Calendar.Layout.Select(l => new MixTeamLayoutRowItem() { TeamId = l.TeamId, Row = l.Row, Index = l.Index, ProjectId = l.ProjectId }).ToList(); } } } }