127 lines
4.6 KiB
C#
127 lines
4.6 KiB
C#
using SchoolAgainStudyBusinessLogic.OfficePackage;
|
|
using SchoolAgainStudyContracts.BusinessLogicContracts;
|
|
using SchoolAgainStudyContracts.SearchModel;
|
|
using SchoolAgainStudyContracts.StorageContracts;
|
|
using SchoolAgainStudyContracts.ViewModel;
|
|
using SchoolAgainStudyDataBaseImplements.Models;
|
|
using SchoolAgainStudyDataModels.Models;
|
|
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;
|
|
private readonly ILessonLogic _lesson;
|
|
private readonly IMaterialLogic _material;
|
|
private readonly ITaskLogic _task;
|
|
|
|
public ChartLogic(IInterestLogic interest, IProductLogic product, IDiyLogic diy, ILessonLogic lesson, ITaskLogic task, IMaterialLogic mateial)
|
|
{
|
|
|
|
_interest = interest;
|
|
_product = product;
|
|
_diy = diy;
|
|
_lesson = lesson;
|
|
_task = task;
|
|
_material = mateial;
|
|
}
|
|
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;
|
|
}
|
|
|
|
public List<TopersViewModel> GetTopMaterials(int TeacherId)
|
|
{
|
|
var materials = _material.ReadList(new MaterialSearchModel
|
|
{
|
|
TeacherId = TeacherId,
|
|
});
|
|
var lessons = _lesson.ReadList(new LessonSearchModel
|
|
{
|
|
TeacherId = TeacherId,
|
|
DateFrom = DateTime.SpecifyKind(DateTime.Now.AddMonths(-1), DateTimeKind.Utc),
|
|
DateTo = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc),
|
|
});
|
|
var tasks = _task.ReadList(new TaskSearchModel
|
|
{
|
|
TeacherId = TeacherId,
|
|
DateFrom = DateTime.SpecifyKind(DateTime.Now.AddMonths(-1), DateTimeKind.Utc),
|
|
DateTo = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc),
|
|
});
|
|
Dictionary<IMaterial, int> list = new Dictionary<IMaterial, int>();
|
|
foreach (var material in materials)
|
|
{
|
|
list.Add(material, 0);
|
|
foreach (var lesson in lessons)
|
|
{
|
|
if (lesson.LessonMaterials.ContainsKey(material.Id))
|
|
list[material] += 1;
|
|
}
|
|
foreach (var task in tasks)
|
|
{
|
|
if (task.TaskMaterials.ContainsKey(material.Id))
|
|
list[material] += 1;
|
|
}
|
|
}
|
|
var actList = list.Select(g => new TopersViewModel { Name = g.Key.Title, Count = g.Value }).ToList();
|
|
return actList;
|
|
}
|
|
|
|
public List<TopersViewModel> GetTopStudents(int TeacherId)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
}
|