using System;
using System.Linq;
using System.Collections.Generic;
using EnVisage.Models;
using EnVisage.Code.DAL.Mongo;
namespace EnVisage.Models
{
///
/// Represents a data model for the Mix entity. This model is used to communicat between server and client.
///
public class MixCalendarModel
{
/// Contains ends of all working weeks
public List FiscalCalendarWeekEndings { get; set; }
/// Contains Years->Months->Days
public Dictionary>> WeekEndings { get; set; }
public Dictionary Projects { get; set; }
public List ManagedProjects { get; set; }
public List UnscheduledProjects { get; set; }
public List QueuedProjects { get; set; }
public List UnassignedExpendituresProjects { get; set; } // SA. ENV-1210
public List Layout { get; set; }
///
/// Selected in the filter teams
///
public List Teams { get; set; }
public Dictionary> Vacations { get; set; }
public Dictionary> Trainings { get; set; }
public MixCalendarModel()
{
FiscalCalendarWeekEndings = new List();
WeekEndings = new Dictionary>>();
Teams = new List();
Projects = new Dictionary();
Vacations = new Dictionary>();
Trainings = new Dictionary>();
ManagedProjects = new List();
UnscheduledProjects = new List();
QueuedProjects = new List();
UnassignedExpendituresProjects = new List(); // SA. ENV-1210
Layout = new List();
}
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 = (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(),
ExpCategories = (x.ExpCategories != null) ? x.ExpCategories.Select(ec => new ActivityExpCategoryFooterModel()
{
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,
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) : new Dictionary()
}).ToDictionary(k => k.Id.ToString(), v => v) : new Dictionary()
}).ToList();
}
ManagedProjects = new List();
UnscheduledProjects = new List();
QueuedProjects = new List();
UnassignedExpendituresProjects = new List(); // SA. ENV-1210
if (mongoMix.ManagedProjects != null)
ManagedProjects.AddRange(mongoMix.ManagedProjects);
if (mongoMix.UnscheduledProjects != null)
UnscheduledProjects.AddRange(mongoMix.UnscheduledProjects);
if (mongoMix.QueuedProjects != null)
QueuedProjects.AddRange(mongoMix.QueuedProjects);
// SA. ENV-1210
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();
}
}
// SA. ENV-1210.
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; }
}
}