196 lines
6.2 KiB
C#
196 lines
6.2 KiB
C#
using System.Globalization;
|
|
using System.Linq;
|
|
using EnVisage.Code;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using MongoDB.Bson;
|
|
using EnVisage.Code.DAL.Mongo;
|
|
using MongoDB.Bson.Serialization;
|
|
|
|
namespace EnVisage.Models
|
|
{
|
|
public class MixSaveModel : MixModelBase
|
|
{
|
|
public MixCalendarModel Calendar { get; set; }
|
|
public MixFilterModel Filter { get; set; }
|
|
|
|
public MixSaveModel()
|
|
: base()
|
|
{
|
|
Calendar = new MixCalendarModel();
|
|
Filter = new MixFilterModel();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts an instance of <see cref="EnVisage.Code.DAL.Mongo.Mix"/> entity to the new instance of <see cref="MixSaveModel"/> entity.
|
|
/// </summary>
|
|
/// <param name="entity">An object of <see cref="EnVisage.Code.DAL.Mongo.Mix"/> type.</param>
|
|
/// <returns>An object of <see cref="MixSaveModel"/> prefilled with values from <paramref name="entity"/>.</returns>
|
|
public static explicit operator MixSaveModel(EnVisage.Code.DAL.Mongo.Mix entity)
|
|
{
|
|
if (entity == null)
|
|
return null;
|
|
|
|
var model = new MixSaveModel()
|
|
{
|
|
Id = entity.Id.ToString(),
|
|
Name = entity.Name,
|
|
StartDate = entity.StartDate,
|
|
EndDate = entity.EndDate,
|
|
CreatedBy = entity.CreatedBy,
|
|
Users = entity.Users,
|
|
Calendar = new MixCalendarModel()
|
|
{
|
|
Teams = entity.Teams.Select(t => new MixTeamModel
|
|
{
|
|
Id = t.Id,
|
|
Name = t.Name,
|
|
CompanyId = t.CompanyId,
|
|
CostCenterId = t.CostCenterId,
|
|
UserId = t.UserId,
|
|
IsNew = t.IsNew,
|
|
PlannedCapacity = (t.PlannedCapacity != null) ? t.PlannedCapacity.ToList() : new List<MixTeamCapacity>(),
|
|
ExpCategories = (t.ExpCategories != null) ? t.ExpCategories.Select(ec => new ActivityExpCategoryFooterModel()
|
|
{
|
|
Id = ec.Value.Id,
|
|
Name = ec.Value.Name,
|
|
UomValue = ec.Value.UomValue,
|
|
ActualCapacityValues = ec.Value.ActualCapacityValues,
|
|
AllocatedCapacity = ec.Value.AllocatedCapacity,
|
|
NeedCapacity = ec.Value.NeedCapacity,
|
|
PlannedCapacityValues = ec.Value.PlannedCapacityValues,
|
|
Resources = (ec.Value.Resources != null) ? ec.Value.Resources.Select(r => new ActivityResourceFooterModel()
|
|
{
|
|
Id = r.Value.Id,
|
|
Name = r.Value.Name,
|
|
AllocatedCapacity = r.Value.AllocatedCapacity,
|
|
TotalCapacity = r.Value.TotalCapacity
|
|
}).ToDictionary(k => k.Id.ToString(), v => v) : null
|
|
}).ToDictionary(k => k.Id.ToString(), v => v) : new Dictionary<string, ActivityExpCategoryFooterModel>()
|
|
}).ToList()
|
|
},
|
|
|
|
Filter = new MixFilterModel()
|
|
{
|
|
Selection = new MixFilterSelectionModel()
|
|
{
|
|
TeamsViews = entity.Teams.Select(t => new MixTeamViewModel
|
|
{
|
|
Id = t.Id,
|
|
TVName = t.Name,
|
|
IsNew = t.IsNew,
|
|
Group = new System.Web.Mvc.SelectListGroup() { Name = t.Group, Disabled = false }
|
|
}).ToList(),
|
|
|
|
StartDate = entity.StartDate,
|
|
EndDate = entity.EndDate
|
|
}
|
|
}
|
|
};
|
|
|
|
return model;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Copies property values from current object of type <see cref="MixSaveModel"/> to <paramref name="obj"/> object of type <see cref="EnVisage.Code.DAL.Mongo.Mix"/> entity.
|
|
/// </summary>
|
|
/// <param name="obj">An object of <see cref="EnVisage.Code.DAL.Mongo.Mix"/> type.</param>
|
|
public void CopyTo(EnVisage.Code.DAL.Mongo.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 Code.DAL.Mongo.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,
|
|
Resources = (e.Value.Resources != null) ? e.Value.Resources.Select(r => new ActivityResource()
|
|
{
|
|
Id = r.Value.Id,
|
|
Name = r.Value.Name,
|
|
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<Guid>();
|
|
obj.UnscheduledProjects = new List<Guid>();
|
|
obj.QueuedProjects = new List<Guid>();
|
|
obj.UnassignedExpProjects = new List<CategoryExpenditureInMongoProject>(); // SA. ENV-1210
|
|
obj.Layout = new List<MixTeamLayoutRowItem>();
|
|
|
|
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);
|
|
|
|
// SA. ENV-1210
|
|
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
|
|
}).ToList();
|
|
|
|
|
|
if (Calendar.Projects != null)
|
|
{
|
|
obj.Projects = Calendar.Projects.Select(p => (MixProject)p.Value).ToDictionary(p => p.Id.ToString(), i => i);
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|
|
}
|
|
} |