diff --git a/School/SchoolBusinessLogic/BusinessLogics/EmployeeRoleImitationaLogic.cs b/School/SchoolBusinessLogic/BusinessLogics/EmployeeRoleImitationaLogic.cs new file mode 100644 index 0000000..e7f94b3 --- /dev/null +++ b/School/SchoolBusinessLogic/BusinessLogics/EmployeeRoleImitationaLogic.cs @@ -0,0 +1,130 @@ +using SchoolContracts.BusinessLogicsContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SchoolBusinessLogic.BusinessLogics +{ + /// + /// Заглушка для роли сотрудника + /// + public class EmployeeRoleImitationaLogic + { + private readonly IEmployeeLogic _employeeLogic; + private readonly ILessonLogic _lessonLogic; + private readonly IExpenseLogic _ExpenseLogic; + private readonly ICircleLogic _circleLogic; + private readonly ICircleExpenseLogic _circleExpenseLogic; + + public EmployeeRoleImitationaLogic(IEmployeeLogic employeeLogic, + ILessonLogic lessonLogic, IExpenseLogic ExpenseLogic, + ICircleLogic circleLogic, ICircleExpenseLogic circleExpenseLogic) + { + _employeeLogic = employeeLogic; + _lessonLogic = lessonLogic; + _ExpenseLogic = ExpenseLogic; + _circleLogic = circleLogic; + _circleExpenseLogic = circleExpenseLogic; + } + private bool GenerateEmployeeData() + { + if(_employeeLogic.ReadList(null)?.Count != 0 ) + { + return false; + } + using (StreamReader sr = new("employees.txt")) + { + string? currentString; + while ((currentString = sr.ReadLine()) != null) + { + var employeeRecData = currentString.Split(','); + _employeeLogic.Create(new() + { + EmployeeEmail = employeeRecData[0], + EmployeePassword = employeeRecData[1], + EmployeeName = employeeRecData[2], + EmployeePhone = employeeRecData[3] + }); + } + } + return true; + } + private bool GenerateLessonData() + { + if(_lessonLogic.ReadList(null)?.Count != 0) + { + return false; + } + using (StreamReader sr = new("lessons.txt")) + { + string? currentString; + while ((currentString = sr.ReadLine()) != null) + { + var lessonRecData = currentString.Split(','); + _lessonLogic.Create(new() + { + LessonName = Convert.ToString(lessonRecData[0]), + LessonPrice = Convert.ToDouble(lessonRecData[1]) + }); + } + } + return true; + } + public bool GenerateExpense() + { + if (_ExpenseLogic.ReadList(null)?.Count != 0) + { + return false; + } + using (StreamReader sr = new("expenses.txt")) + { + string? currentString; + while ((currentString = sr.ReadLine()) != null) + { + var expenseRecData = currentString.Split(','); + _ExpenseLogic.Create(new() + { + ExpenseName = Convert.ToString(expenseRecData[0]), + Sum = Convert.ToDouble(expenseRecData[1]), + Count = Convert.ToInt32(expenseRecData[2]), + EmployeeId = Convert.ToInt32(expenseRecData[3]) + }); + } + } + return true; + } + public bool GenerateCircleExpense() + { + var ExpenseList = _ExpenseLogic.ReadList(null); + if (ExpenseList == null) + { + return false; + } + if (ExpenseList.Count == 0) + { + return false; + } + var CircleList = _circleLogic.ReadList(null); + if (CircleList == null) + { + return false; + } + if (CircleList.Count == 0) + { + return false; + } + Random rnd = new Random(); + for (int i = 0; i < 2; i++) + { + _circleExpenseLogic.Create(new() + { + ExpenseId = rnd.Next(0, ExpenseList.Count), + CircleId = rnd.Next(0, CircleList.Count) + }); + } + return true; + } + } +} diff --git a/School/SchoolBusinessLogic/BusinessLogics/ReportLessonsLogic.cs b/School/SchoolBusinessLogic/BusinessLogics/ReportLessonsLogic.cs deleted file mode 100644 index 2672ecb..0000000 --- a/School/SchoolBusinessLogic/BusinessLogics/ReportLessonsLogic.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SchoolBusinessLogic.BusinessLogics -{ - public class ReportLessonsLogic - { - - } -} diff --git a/School/SchoolBusinessLogic/BusinessLogics/ReportLogic.cs b/School/SchoolBusinessLogic/BusinessLogics/ReportLogic.cs index d37f3a8..4df0092 100644 --- a/School/SchoolBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/School/SchoolBusinessLogic/BusinessLogics/ReportLogic.cs @@ -1,51 +1,54 @@ using Microsoft.Extensions.Logging; +using Microsoft.Identity.Client; using SchoolContracts.BusinessLogicsContracts; using SchoolContracts.StoragesContracts; using SchoolContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using SchoolDatabaseImplement.Models; +using SchoolDataModels.Models; +using SchoolContracts.BindingModel; namespace SchoolContracts.BusinessLogics { public class ReportLogic : IReportLogic { private readonly ICircleStorage _circleStorage; + private readonly ILogger _logger; + private readonly ICircleExpenseStorage _circleExpenseStorage; - private readonly IExpenseStorage _expenseStorage; - /// - /// Получение списка кружков с указанием списка затрат по ним - /// - /// - public List GetCircles() + public ReportLogic(ILogger logger, ICircleStorage circleStorage, + ICircleExpenseStorage circleExpenseStorage) { - var expenses = _expenseStorage.GetFullList(); - var circles = _circleStorage.GetFullList(); - var list = new List(); - foreach(var circle in circles) - { - var record = new ReportViewModel - { - CircleNumber = circle.Id, - Expenses = new List(), - CircleCount = 0 - - }; - foreach (var expense in expenses) - { - - } - list.Add(record); - } - return list; + _logger = logger; + _circleStorage = circleStorage; + _circleExpenseStorage = circleExpenseStorage; } /// - /// Получение списка занятий за определенный период + /// получение занятий по кружку /// - /// - /// - + public List GetLessonCircles(ReportBindingModel model) + { + return _circleStorage.GetLessonCircles(new() { SelectedCirclesIds = model.SelectedCircles}); + } + /// + /// получение затрат кружку + /// + public List GetExpenses (ReportBindingModel model) + { + return _circleExpenseStorage.GetExpensesInCircles(new() { DateFrom = model.DateFrom, DateTo = model.DateTo }); + } + public void SaveComponentsToWordFile(ReportBindingModel model) + { + throw new NotImplementedException(); + } + + public void SaveManufactureComponentToExcelFile(ReportBindingModel model) + { + throw new NotImplementedException(); + } + + public void SaveOrdersToPdfFile(ReportBindingModel model) + { + throw new NotImplementedException(); + } } } diff --git a/School/SchoolContracts/BindingModels/CircleBindingModel.cs b/School/SchoolContracts/BindingModels/CircleBindingModel.cs index a072e94..becf8ee 100644 --- a/School/SchoolContracts/BindingModels/CircleBindingModel.cs +++ b/School/SchoolContracts/BindingModels/CircleBindingModel.cs @@ -13,7 +13,6 @@ namespace SchoolContracts.BindingModel public DateTime DateStart { get; set; } = DateTime.Now; public int ClientId { get; set; } public int LessonId { get; set; } - public double Remains { get; set; } } } diff --git a/School/SchoolContracts/BindingModels/ExpenseBindingModel.cs b/School/SchoolContracts/BindingModels/ExpenseBindingModel.cs index 4d213f1..aeb560e 100644 --- a/School/SchoolContracts/BindingModels/ExpenseBindingModel.cs +++ b/School/SchoolContracts/BindingModels/ExpenseBindingModel.cs @@ -12,5 +12,7 @@ namespace SchoolContracts.BindingModels public int Id { get; set; } public double Sum { get; set;} public string ExpenseName { get; set;} + public int Count { get; set; } + public int EmployeeId { get; set; } } } diff --git a/School/SchoolContracts/BusinessLogicsContracts/IReportLogic.cs b/School/SchoolContracts/BusinessLogicsContracts/IReportLogic.cs index a46b18f..170041f 100644 --- a/School/SchoolContracts/BusinessLogicsContracts/IReportLogic.cs +++ b/School/SchoolContracts/BusinessLogicsContracts/IReportLogic.cs @@ -12,16 +12,16 @@ namespace SchoolContracts.BusinessLogicsContracts public interface IReportLogic { /// - /// Получение списка кружков + /// Получение списка кружков по занятиям /// /// - List GetCircles(ReportBindingModel model); + List GetLessonCircles(ReportBindingModel model); /// /// Получение списка затрат за определенный период /// /// /// - //List GetExpenses(ReportBindingModel model); + List GetExpenses(ReportBindingModel model); /// /// Сохранение компонент в файл-Word /// diff --git a/School/SchoolContracts/SearchModel/CircleExpenseSearchModel.cs b/School/SchoolContracts/SearchModel/CircleExpenseSearchModel.cs index 01d6ca8..5b5251b 100644 --- a/School/SchoolContracts/SearchModel/CircleExpenseSearchModel.cs +++ b/School/SchoolContracts/SearchModel/CircleExpenseSearchModel.cs @@ -9,5 +9,7 @@ namespace SchoolContracts.SearchModel public class CircleExpenseSearchModel { public int? Id { get; set; } + public DateTime? DateTo { get; set; } + public DateTime? DateFrom { get; set; } } } diff --git a/School/SchoolContracts/StoragesContracts/ICircleExpenseStorage.cs b/School/SchoolContracts/StoragesContracts/ICircleExpenseStorage.cs index ecdabba..33343cb 100644 --- a/School/SchoolContracts/StoragesContracts/ICircleExpenseStorage.cs +++ b/School/SchoolContracts/StoragesContracts/ICircleExpenseStorage.cs @@ -18,5 +18,6 @@ namespace SchoolContracts.StoragesContracts CircleExpenseViewModel? Insert(CircleExpenseBindingModel model); CircleExpenseViewModel? Update(CircleExpenseBindingModel model); CircleExpenseViewModel? Delete(CircleExpenseBindingModel model); + List GetExpensesInCircles(CircleExpenseSearchModel model); } } diff --git a/School/SchoolContracts/ViewModels/ExpenseViewModel.cs b/School/SchoolContracts/ViewModels/ExpenseViewModel.cs index 18e97a5..34b836e 100644 --- a/School/SchoolContracts/ViewModels/ExpenseViewModel.cs +++ b/School/SchoolContracts/ViewModels/ExpenseViewModel.cs @@ -12,5 +12,7 @@ namespace SchoolContracts.ViewModels public int Id { get; set; } public string ExpenseName { get; set; } public double Sum { get; set; } + public int Count { get; set; } + public int EmployeeId { get; set; } } } diff --git a/School/SchoolContracts/ViewModels/ReportCircleLessonsViewModel.cs b/School/SchoolContracts/ViewModels/ReportCircleLessonsViewModel.cs index 54e6200..027c77d 100644 --- a/School/SchoolContracts/ViewModels/ReportCircleLessonsViewModel.cs +++ b/School/SchoolContracts/ViewModels/ReportCircleLessonsViewModel.cs @@ -18,6 +18,6 @@ namespace SchoolContracts.ViewModels /// /// Занятия в кружке /// - public List CircleLessons { get; set; } = new(); + public List Lessons { get; set; } = new(); } } diff --git a/School/SchoolContracts/ViewModels/ReportExpensesViewModel.cs b/School/SchoolContracts/ViewModels/ReportExpensesInCirclesViewModel.cs similarity index 55% rename from School/SchoolContracts/ViewModels/ReportExpensesViewModel.cs rename to School/SchoolContracts/ViewModels/ReportExpensesInCirclesViewModel.cs index 6947c7a..cade0ab 100644 --- a/School/SchoolContracts/ViewModels/ReportExpensesViewModel.cs +++ b/School/SchoolContracts/ViewModels/ReportExpensesInCirclesViewModel.cs @@ -7,12 +7,18 @@ using System.Threading.Tasks; namespace SchoolContracts.ViewModels { - public class ReportExpensesViewModel + public class ReportExpensesInCirclesViewModel { [DisplayName("Название затраты")] public string ExpenseName { get; set; } = string.Empty; [DisplayName("Сумма")] public double Sum { get; set; } + [DisplayName("Номер кружка")] + public int CircleId { get; set; } + [DisplayName("Имя сотрудника")] + public string EmployeeName { get; set; } + [DisplayName("Кол-во затрат")] + public int Count { get; set; } } } diff --git a/School/SchoolContracts/ViewModels/ReportLessonCirclesViewModel.cs b/School/SchoolContracts/ViewModels/ReportLessonCirclesViewModel.cs index 4580c07..141d6e4 100644 --- a/School/SchoolContracts/ViewModels/ReportLessonCirclesViewModel.cs +++ b/School/SchoolContracts/ViewModels/ReportLessonCirclesViewModel.cs @@ -7,17 +7,21 @@ using System.Threading.Tasks; namespace SchoolContracts.ViewModels { /// - /// Модель для получения всех занятий по кружку для отчета + /// Модель для получения одного занятия для отчета /// - public class ReportLessonCircleViewModel + public class ReportLessonCirclesViewModel { /// - /// Номер кружка + /// Номер занятия /// - public int CircleId { get; set; } + public int LessonId { get; set; } /// - /// Занятия в кружке + /// Имя сотрудника /// - public List CircleLessons { get; set; } = new(); + public string EmployeeName{ get; set; } = string.Empty; + /// + /// Стоимость + /// + public double Sum { get; set; } } } diff --git a/School/SchoolContracts/ViewModels/ReportViewModel.cs b/School/SchoolContracts/ViewModels/ReportViewModel.cs deleted file mode 100644 index 18634ee..0000000 --- a/School/SchoolContracts/ViewModels/ReportViewModel.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SchoolContracts.ViewModels -{ - public class ReportViewModel - { - [DisplayName("Имя кружка")] - public int CircleNumber { get; set; } - [DisplayName("Дата записи")] - public DateTime Date { get; set; } - [DisplayName("Сумма затрат")] - public double Sum { get; set; } - [DisplayName("Кол-во занятий")] - public int CircleCount { get; set; } - [DisplayName("Название затраты")] - public List Expenses{ get; set; } - - } -} diff --git a/School/SchoolDataModels/Models/IExpenseModel.cs b/School/SchoolDataModels/Models/IExpenseModel.cs index 70637a4..2448ce2 100644 --- a/School/SchoolDataModels/Models/IExpenseModel.cs +++ b/School/SchoolDataModels/Models/IExpenseModel.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace SchoolDataModels.Models { /// - /// Затрата на кружок + /// Затраты /// public interface IExpenseModel : IId { @@ -19,5 +19,13 @@ namespace SchoolDataModels.Models /// Название /// public string ExpenseName { get; } + /// + /// количество + /// + public int Count { get; set; } + /// + /// Id сотрудника + /// + public int EmployeeId { get; set; } } } diff --git a/School/SchoolDatabaseImplements/Implements/CircleExpenseStorage.cs b/School/SchoolDatabaseImplements/Implements/CircleExpenseStorage.cs index 7457c4e..be03695 100644 --- a/School/SchoolDatabaseImplements/Implements/CircleExpenseStorage.cs +++ b/School/SchoolDatabaseImplements/Implements/CircleExpenseStorage.cs @@ -44,6 +44,27 @@ namespace SchoolDatabaseImplements.Implements return null; } + public List GetExpensesInCircles(CircleExpenseSearchModel model) + { + if (model.DateFrom == null || model.DateTo == null) + { + return new(); + } + using var context = new SchoolDatabase(); + return context.CircleExpenses.Include(x => x.Circle) + .Include(x => x.Expense) + .ThenInclude(x => x.Employee) + .Select(x => new ReportExpensesInCirclesViewModel() + { + EmployeeName = x.Expense.Employee.EmployeeName, + CircleId = x.Circle.Id, + ExpenseName = x.Expense.ExpenseName, + Count = x.Expense.Count, + Sum= x.Expense.Sum + }) + .ToList(); + } + public List GetFilteredList(CircleExpenseSearchModel model) { using var context = new SchoolDatabase(); diff --git a/School/SchoolDatabaseImplements/Implements/CircleStorage.cs b/School/SchoolDatabaseImplements/Implements/CircleStorage.cs index 6eeccd1..ef590cd 100644 --- a/School/SchoolDatabaseImplements/Implements/CircleStorage.cs +++ b/School/SchoolDatabaseImplements/Implements/CircleStorage.cs @@ -26,22 +26,11 @@ namespace SchoolDatabaseImplement.Implements public List GetFilteredList(CircleSearchModel model) { using var context = new SchoolDatabase(); - if (model.DateFrom.HasValue && model.DateTo.HasValue) // если не ищем по айдишнику, значит ищем по диапазону дат - { return context.Circles - .Where(x => model.DateFrom <= x.DateStart.Date && x.DateStart <= model.DateTo) + .Where(x => x.Id == model.Id) .Include(x => x.Client) .Select(x => x.GetViewModel) .ToList(); - } - if (model.ClientId.HasValue) - { - return context.Circles - .Where(x => x.Client.Id == model.ClientId) - .Select(x => x.GetViewModel) - .ToList(); - } - return new(); } public CircleViewModel? GetElement(CircleSearchModel model) { @@ -93,7 +82,11 @@ namespace SchoolDatabaseImplement.Implements } return null; } - + /// + /// Получение списка занятий по выбранному кружку + /// + /// + /// public List GetLessonCircles(CircleSearchModel model) { if (model.SelectedCirclesIds == null) @@ -102,26 +95,23 @@ namespace SchoolDatabaseImplement.Implements } using var context = new SchoolDatabase(); return context.Circles - .Where(c => model.SelectedCirclesIds.Contains(c.Id)) - .Select(c => new ReportCircleLessonsViewModel() + .Where(x => model.SelectedCirclesIds.Contains(x.Id)) + .Select(x => new ReportCircleLessonsViewModel() { - CircleLessons = GetCircleLessons(context, new() { Id = c.Id }) - }) - .ToList(); - } - /// - /// Получение списка занятий по выбранному кружку - /// - /// - /// - private static List GetCircleLessons(SchoolDatabase context, CircleSearchModel model) - { - return context.Circles - .Include(wir => wir.CircleLessons) - .Where(wir => wir.Id == model.Id) - .Select(wir => new ReportLessonCirclesViewModel() - { - LessonId = wir.CircleLessons.Id + CircleId= x.Id, + Lessons = context.CircleLessons + .Include(x => x.Lesson) + .ThenInclude(x => x.Employee) + .Where(x => x.CircleId == x.Id) + .Select(x => new ReportLessonCirclesViewModel() + { + + LessonId = x.Circle.Id, + EmployeeName = x.Lesson.Employee.EmployeeName, + Sum = x.Lesson.LessonPrice + + }) + .ToList() }) .ToList(); } diff --git a/School/SchoolDatabaseImplements/Models/CircleExpense.cs b/School/SchoolDatabaseImplements/Models/CircleExpense.cs index abf5453..9202091 100644 --- a/School/SchoolDatabaseImplements/Models/CircleExpense.cs +++ b/School/SchoolDatabaseImplements/Models/CircleExpense.cs @@ -2,6 +2,7 @@ using SchoolContracts.BindingModel; using SchoolContracts.BindingModels; using SchoolContracts.ViewModels; +using SchoolDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; @@ -11,7 +12,7 @@ using System.Threading.Tasks; namespace SchoolDatabaseImplement.Models { - public class CircleExpense + public class CircleExpense { public int Id { get; set; } [Required] diff --git a/School/SchoolDatabaseImplements/Models/Employee.cs b/School/SchoolDatabaseImplements/Models/Employee.cs index df6c04a..f5cae8b 100644 --- a/School/SchoolDatabaseImplements/Models/Employee.cs +++ b/School/SchoolDatabaseImplements/Models/Employee.cs @@ -23,6 +23,8 @@ namespace SchoolDatabaseImplement.Models [Required] public string EmployeeName { get; set; } = string.Empty; [ForeignKey("EmployeeId")] + public virtual List Expenses { get; set; } = new(); + [ForeignKey("EmployeeId")] public virtual List Lessons { get; set; } = new(); public static Employee? Create(EmployeeBindingModel model) { @@ -51,9 +53,13 @@ namespace SchoolDatabaseImplement.Models EmployeePhone = model.EmployeePhone; } - public ExpenseViewModel GetViewModel => new() + public EmployeeViewModel GetViewModel => new() { - Id = Id + Id = Id, + EmployeeName = EmployeeName, + EmployeeEmail = EmployeeEmail, + EmployeePassword = EmployeePassword, + EmployeePhone = EmployeePhone }; } diff --git a/School/SchoolDatabaseImplements/Models/Expense.cs b/School/SchoolDatabaseImplements/Models/Expense.cs index 86bdb62..0a40115 100644 --- a/School/SchoolDatabaseImplements/Models/Expense.cs +++ b/School/SchoolDatabaseImplements/Models/Expense.cs @@ -18,9 +18,15 @@ namespace SchoolDatabaseImplement.Models public string ExpenseName { get; private set; } = string.Empty; [Required] public double Sum { get; private set; } + [Required] + public int Count { get; private set; } + public int EmployeeId { get; private set; } + public int CircleId { get; private set; } [ForeignKey("ExpenseId")] public virtual List CircleExpenses { get; set; } = new(); - public static Expense? Create(ExpenseBindingModel model) + [ForeignKey("ExpenseId")] + public virtual Employee Employee { get; set; } = new(); + public static Expense? Create(SchoolDatabase context, ExpenseBindingModel model) { if (model == null) { @@ -30,7 +36,9 @@ namespace SchoolDatabaseImplement.Models { Id = model.Id, ExpenseName = model.ExpenseName, - Sum = model.Sum + Sum = model.Sum, + Count = model.Count, + Employee = context.Employees.First(x => x.Id == model.EmployeeId) }; } public void Update(ExpenseBindingModel model)