78 lines
3.0 KiB
C#
78 lines
3.0 KiB
C#
using SchoolAgainStudyBusinessLogic.OfficePackage;
|
|
using SchoolAgainStudyContracts.BusinessLogicContracts;
|
|
using SchoolAgainStudyContracts.SearchModel;
|
|
using SchoolAgainStudyContracts.StorageContracts;
|
|
using SchoolAgainStudyContracts.ViewModel;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace SchoolAgainStudyBusinessLogic.BusinessLogic
|
|
{
|
|
public class ChartLogic : IChartLogic
|
|
{
|
|
private readonly IInterestLogic _interest;
|
|
private readonly IProductLogic _product;
|
|
private readonly IDiyLogic _diy;
|
|
|
|
public ChartLogic(IInterestLogic interest, IProductLogic product, IDiyLogic diy)
|
|
{
|
|
|
|
_interest = interest;
|
|
_product = product;
|
|
_diy = diy;
|
|
|
|
}
|
|
public (int Products, int Diyes) GetDifferenceInCount(int StudentId)
|
|
{
|
|
var products = _product.ReadList(new ProductSearchModel
|
|
{
|
|
StudentId = StudentId,
|
|
DateFrom = DateTime.SpecifyKind(DateTime.Now.AddMonths(-1), DateTimeKind.Utc),
|
|
DateTo = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc),
|
|
});
|
|
var diyes = _diy.ReadList(new DiySearchModel
|
|
{
|
|
StudentId = StudentId,
|
|
DateFrom = DateTime.SpecifyKind(DateTime.Now.AddMonths(-1), DateTimeKind.Utc),
|
|
DateTo = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc),
|
|
});
|
|
return (products.Count, diyes.Count);
|
|
}
|
|
public List<ActivityChartViewModel> GetActivitys(int StudentId)
|
|
{
|
|
var products = _product.ReadList(new ProductSearchModel
|
|
{
|
|
StudentId = StudentId,
|
|
DateFrom = DateTime.SpecifyKind(DateTime.Now.AddMonths(-1), DateTimeKind.Utc),
|
|
DateTo = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc),
|
|
});
|
|
var diyes = _diy.ReadList(new DiySearchModel
|
|
{
|
|
StudentId = StudentId,
|
|
DateFrom = DateTime.SpecifyKind(DateTime.Now.AddMonths(-1), DateTimeKind.Utc),
|
|
DateTo = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc),
|
|
});
|
|
Dictionary<DateTime, int> list = new Dictionary<DateTime, int>();
|
|
for(DateTime date = DateTime.Now.AddMonths(-1); date<= DateTime.Now; date=date.AddDays(1))
|
|
{
|
|
list.Add(date, 0);
|
|
foreach(var product in products)
|
|
{
|
|
if (product.DateCreate.Date == date.Date)
|
|
list[date] += 1;
|
|
}
|
|
foreach (var diy in diyes)
|
|
{
|
|
if (diy.DateCreate.Date == date.Date)
|
|
list[date] += 1;
|
|
}
|
|
}
|
|
var actList = list.Select(g => new ActivityChartViewModel { dateOf = g.Key.ToString("dd/MM"), count = g.Value }).ToList();
|
|
return actList;
|
|
}
|
|
}
|
|
}
|