48 lines
1.5 KiB
C#
48 lines
1.5 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>
|
|
/// Represents view capacity lines on charts
|
|
/// </summary>
|
|
public class ViewCapacity
|
|
{
|
|
public Dictionary<DateTime, PeopleResourceModel.CapacityValues> Values { get; private set; }
|
|
|
|
public ViewCapacity(Guid viewId, 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);
|
|
var teamIds = (from t in context.Teams
|
|
join tv in context.Team2View on t.Id equals tv.TeamId
|
|
where tv.ViewId == viewId
|
|
select t.Id);
|
|
foreach (var teamId in teamIds)
|
|
{
|
|
var team = (TeamModel)teamManager.Load(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();
|
|
}
|
|
}
|
|
} |