EnVisageOnline/Beta/Source/EnVisage/Code/Charts/TotalCapacity.cs

46 lines
1.4 KiB
C#

using EnVisage.Code.BLL;
using EnVisage.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace EnVisage.Code.Charts
{
/// <summary>
/// Represent 'Total Capacity' line at dashboars chart
/// </summary>
public class TotalCapacity
{
public Dictionary<DateTime, PeopleResourceModel.CapacityValues> Values { get; private set; }
public TotalCapacity(Guid[] teamIds, Dictionary<Guid, ExpenditureCategory> expCats = null, Dictionary<Guid, UOM> uoms = null, bool? isUOMHours = null)
{
Values = new Dictionary<DateTime, PeopleResourceModel.CapacityValues>();
var context = new EnVisageEntities();
var teamManager = new TeamManager(context);
foreach(var teamId in teamIds)
{
//var team = (TeamModel)teamManager.Load(teamId);
TeamModel team = new TeamModel();
team.Id = teamId;
var weeks = team.GetWeeklyTeamCapacity(expCats, uoms, isUOMHours);
foreach(var week in weeks)
{
if (Values.ContainsKey(week.Key))
{
Values[week.Key].Cost += week.Value.Cost;
Values[week.Key].Quantity += week.Value.Quantity;
}
else
Values.Add(week.Key, week.Value);
}
}
}
public List<PeopleResourceModel.CapacityValues> GetDataByDateRange(DateTime startDate, DateTime endDate)
{
return Values.Where(x => x.Key >= startDate && x.Key <= endDate).Select(x => x.Value).ToList();
}
}
}