197 lines
7.0 KiB
C#
197 lines
7.0 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Collections.Generic;
|
|
using EnVisage.Models;
|
|
using EnVisage.Code.DAL.Mongo;
|
|
|
|
namespace EnVisage.Models
|
|
{
|
|
/// <summary>
|
|
/// Represents a data model for the Mix entity. This model is used to communicate between server and client.
|
|
/// </summary>
|
|
public class MixCalendarModel
|
|
{
|
|
/// <summary>Contains ends of all working weeks</summary>
|
|
public List<long> FiscalCalendarWeekEndings { get; set; }
|
|
|
|
/// <summary>Contains Years->Months->Days</summary>
|
|
public Dictionary<string, Dictionary<string, List<int>>> WeekEndings { get; set; }
|
|
|
|
public Dictionary<string, MixProjectModel> Projects { get; set; }
|
|
public List<Guid> ManagedProjects { get; set; }
|
|
public List<Guid> UnscheduledProjects { get; set; }
|
|
public List<Guid> QueuedProjects { get; set; }
|
|
public DataModifiedInfo ModifiedObjects { get; set; }
|
|
public List<CategoryExpenditureInProject> UnassignedExpendituresProjects { get; set; }
|
|
public List<MixTeamLayoutRowItem> Layout { get; set; }
|
|
|
|
/// <summary>
|
|
/// Selected teams in the filter
|
|
/// </summary>
|
|
public List<MixTeamModel> Teams { get; set; }
|
|
public Dictionary<string, ExpenditureDetail> SuperExpenditures { get; set; }
|
|
public Dictionary<string, MixAllocationsByECModel> NeedAllocations { get; set; }
|
|
|
|
public MixCalendarModel()
|
|
{
|
|
FiscalCalendarWeekEndings = new List<long>();
|
|
WeekEndings = new Dictionary<string, Dictionary<string, List<int>>>();
|
|
Teams = new List<MixTeamModel>();
|
|
Projects = new Dictionary<string, MixProjectModel>();
|
|
ManagedProjects = new List<Guid>();
|
|
UnscheduledProjects = new List<Guid>();
|
|
QueuedProjects = new List<Guid>();
|
|
UnassignedExpendituresProjects = new List<CategoryExpenditureInProject>();
|
|
Layout = new List<MixTeamLayoutRowItem>();
|
|
ModifiedObjects = new DataModifiedInfo();
|
|
}
|
|
|
|
public void AssignFrom(Mix mongoMix)
|
|
{
|
|
if (mongoMix.Projects != null)
|
|
{
|
|
Projects = mongoMix.Projects.Select(p => new MixProjectModel()
|
|
{
|
|
Id = p.Value.Id,
|
|
Name = p.Value.Name,
|
|
Pinned = p.Value.Pinned,
|
|
Scenario = p.Value.Scenario == null ? null : (new ScenarioCalendarMixModel(p.Value.Scenario)),
|
|
Teams = p.Value.Teams.Select(t => t).ToList()
|
|
}).ToDictionary(k => k.Id.ToString());
|
|
}
|
|
|
|
if (mongoMix.Teams != null)
|
|
{
|
|
Teams = mongoMix.Teams.Select(x => new MixTeamModel
|
|
{
|
|
Id = x.Id,
|
|
Name = x.Name,
|
|
IsNew = x.IsNew,
|
|
CompanyId = x.CompanyId,
|
|
CostCenterId = x.CostCenterId,
|
|
UserId = (x.UserId != null) ? x.UserId : null,
|
|
PlannedCapacity = (x.PlannedCapacity != null) ? x.PlannedCapacity.ToList() : new List<MixTeamCapacity>(),
|
|
ExpCategories = (x.ExpCategories != null) ? x.ExpCategories.Select(ec => new ExpCategorySummaryInfoModel()
|
|
{
|
|
Id = ec.Value.Id,
|
|
Name = ec.Value.Name,
|
|
NeedCapacity = ec.Value.NeedCapacity,
|
|
ActualCapacityValues = ec.Value.ActualCapacityValues,
|
|
AllocatedCapacity = ec.Value.AllocatedCapacity,
|
|
PlannedCapacityValues = ec.Value.PlannedCapacityValues,
|
|
UomValue = ec.Value.UomValue,
|
|
AllowResourceAssignment = ec.Value.AllowResourceAssignment,
|
|
Resources = (ec.Value.Resources != null) ? ec.Value.Resources.Select(r => new ResourceSummaryInfoModel()
|
|
{
|
|
Id = r.Value.Id,
|
|
AllocatedCapacity = r.Value.AllocatedCapacity,
|
|
TotalCapacity = r.Value.TotalCapacity,
|
|
}).ToDictionary(k => k.Id.ToString(), v => v) : new Dictionary<string, ResourceSummaryInfoModel>()
|
|
}).ToDictionary(k => k.Id.ToString(), v => v) : new Dictionary<string, ExpCategorySummaryInfoModel>()
|
|
}).ToList();
|
|
}
|
|
|
|
ManagedProjects = new List<Guid>();
|
|
UnscheduledProjects = new List<Guid>();
|
|
QueuedProjects = new List<Guid>();
|
|
UnassignedExpendituresProjects = new List<CategoryExpenditureInProject>();
|
|
|
|
if (mongoMix.ManagedProjects != null)
|
|
ManagedProjects.AddRange(mongoMix.ManagedProjects);
|
|
|
|
if (mongoMix.UnscheduledProjects != null)
|
|
UnscheduledProjects.AddRange(mongoMix.UnscheduledProjects);
|
|
|
|
if (mongoMix.QueuedProjects != null)
|
|
QueuedProjects.AddRange(mongoMix.QueuedProjects);
|
|
|
|
if (mongoMix.UnassignedExpProjects != null)
|
|
UnassignedExpendituresProjects = mongoMix.UnassignedExpProjects.Select(i =>
|
|
new CategoryExpenditureInProject
|
|
{
|
|
ProjectId = i.ProjectId,
|
|
ExpCatId = i.ExpCatId,
|
|
TargetTeamId = i.TargetTeamId,
|
|
Name = i.Name
|
|
}).ToList();
|
|
|
|
|
|
Layout = mongoMix.Layout.Select(l => new MixTeamLayoutRowItem()
|
|
{
|
|
Index = l.Index,
|
|
Row = l.Row,
|
|
ProjectId = l.ProjectId,
|
|
TeamId = l.TeamId
|
|
}).ToList();
|
|
}
|
|
}
|
|
|
|
public class CategoryExpenditureInProject
|
|
{
|
|
public CategoryExpenditureInProject()
|
|
{
|
|
}
|
|
|
|
public Guid ProjectId { get; set; }
|
|
public Guid ExpCatId { get; set; }
|
|
public Guid? TargetTeamId { get; set; }
|
|
public string Name { get; set; }
|
|
public bool AllowResourceAssignment { get; set; }
|
|
}
|
|
/// <summary>
|
|
/// Represents an information about objects deleted/modified in live database.
|
|
/// </summary>
|
|
public class DataModifiedInfo
|
|
{
|
|
/// <summary>
|
|
/// Gets or sets a list of deleted project names.
|
|
/// </summary>
|
|
public List<string> DeletedProjects { get; set; }
|
|
/// <summary>
|
|
/// Gets or sets a dictionary of delete resources. Key - resource Id, Value - resource Name.
|
|
/// </summary>
|
|
public Dictionary<string, string> DeletedResources { get; set; }
|
|
/// <summary>
|
|
/// Gets a value indicating a number of deleted resources. Getter counts number of elements in <see cref="DeletedResources"/> property.
|
|
/// </summary>
|
|
public int DeletedResourcesCount {
|
|
get {
|
|
return DeletedResources != null ? DeletedResources.Count : 0;
|
|
}
|
|
}
|
|
|
|
public DataModifiedInfo() {
|
|
DeletedProjects = new List<string>();
|
|
DeletedResources = new Dictionary<string, string>();
|
|
}
|
|
}
|
|
|
|
public class MixAllocationsModel
|
|
{
|
|
public Dictionary<string, decimal> Allocations { get; set; }
|
|
|
|
#region Constructors
|
|
|
|
public MixAllocationsModel()
|
|
{
|
|
Allocations = new Dictionary<string, decimal>();
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
|
|
public class MixAllocationsByECModel
|
|
{
|
|
public Dictionary<string, MixAllocationsModel> Expenditures { get; set; }
|
|
|
|
#region Constructors
|
|
|
|
public MixAllocationsByECModel()
|
|
{
|
|
Expenditures = new Dictionary<string, MixAllocationsModel>();
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
|
|
} |