diff --git a/University/UniversityBusinessLogics/BusinessLogic/ClientLogic.cs b/University/UniversityBusinessLogics/BusinessLogic/ClientLogic.cs index 40e33da..0f52d66 100644 --- a/University/UniversityBusinessLogics/BusinessLogic/ClientLogic.cs +++ b/University/UniversityBusinessLogics/BusinessLogic/ClientLogic.cs @@ -28,17 +28,17 @@ namespace UniversityBusinessLogics.BusinessLogic { return; } - if (string.IsNullOrEmpty(model.Login)) + if (string.IsNullOrEmpty(model.PhoneNumber)) { - throw new ArgumentNullException(nameof(model.Login), "Нет логина клиента"); + throw new ArgumentNullException(nameof(model.PhoneNumber), "Нет логина клиента"); } if (string.IsNullOrEmpty(model.Password)) { throw new ArgumentNullException(nameof(model.Password), "Нет пароля клиента"); } - if (model.Login.Length is < 5) + if (model.PhoneNumber.Length is < 11) { - throw new ArgumentException(nameof(model.Login), "Длина логина должна быть 5 символов"); + throw new ArgumentException(nameof(model.PhoneNumber), "Длина номера телефона должна быть 11 цифр"); } if (model.Password.Length < 5) @@ -54,11 +54,11 @@ namespace UniversityBusinessLogics.BusinessLogic _logger.LogDebug("{level} Проверка логина пользователя на уникальность {@Client}", model); var element = _clientStorage.GetElement(new ClientSearchModel { - Login = model.Login, + PhoneNumber = model.PhoneNumber, }); if (element != null && element.Id != model.Id) { - _logger.LogWarning("С номером {Login}, уже есть пользователь: {@ExistClient}", model.Login, element); + _logger.LogWarning("С номером {PhoneNumber}, уже есть пользователь: {@ExistClient}", model.PhoneNumber, element); throw new InvalidOperationException($"Клиент с таким номером телефона уже есть"); } } diff --git a/University/UniversityBusinessLogics/BusinessLogic/EmployeeLogic.cs b/University/UniversityBusinessLogics/BusinessLogic/EmployeeLogic.cs index 7f72c78..4c1b36c 100644 --- a/University/UniversityBusinessLogics/BusinessLogic/EmployeeLogic.cs +++ b/University/UniversityBusinessLogics/BusinessLogic/EmployeeLogic.cs @@ -15,6 +15,7 @@ namespace UniversityBusinessLogics.BusinessLogic { public class EmployeeLogic : IEmployeeLogic { + private readonly ILogger _logger; private readonly IEmployeeStorage _employeeStorage; public EmployeeLogic(ILogger logger, IEmployeeStorage employeeStorage) @@ -33,17 +34,17 @@ namespace UniversityBusinessLogics.BusinessLogic { return; } - if (string.IsNullOrEmpty(model.Login)) + if (string.IsNullOrEmpty(model.PhoneNumber)) { - throw new ArgumentNullException(nameof(model.Login), "Нет логина клиента"); + throw new ArgumentNullException(nameof(model.PhoneNumber), "Нет логина клиента"); } if (string.IsNullOrEmpty(model.Password)) { throw new ArgumentNullException(nameof(model.Password), "Нет пароля клиента"); } - if (model.Login.Length is < 5) + if (model.PhoneNumber.Length is < 12) { - throw new ArgumentException(nameof(model.Login), "Длина номера телефона должна быть 11 цифр"); + throw new ArgumentException(nameof(model.PhoneNumber), "Длина номера телефона должна быть 11 цифр"); } if (model.Password.Length < 5) @@ -59,12 +60,12 @@ namespace UniversityBusinessLogics.BusinessLogic _logger.LogDebug("{level} Проверка логина пользователя на уникальность {@Employee}", model); var element = _employeeStorage.GetElement(new EmployeeSearchModel { - Login = model.Login, + PhoneNumber = model.PhoneNumber, }); if (element != null && element.Id != model.Id) { - _logger.LogWarning("С номером {Login}, уже есть пользователь: {@ExistEmployee}", model.Login, element); - throw new InvalidOperationException($"Сотрудник с таким логином уже есть"); + _logger.LogWarning("С номером {PhoneNumber}, уже есть пользователь: {@ExistEmployee}", model.PhoneNumber, element); + throw new InvalidOperationException($"Сотрудник с таким номером телефона уже есть"); } } @@ -107,4 +108,5 @@ namespace UniversityBusinessLogics.BusinessLogic } } } + } diff --git a/University/UniversityBusinessLogics/BusinessLogic/ClassLogic.cs b/University/UniversityBusinessLogics/BusinessLogic/OperationLogic.cs similarity index 69% rename from University/UniversityBusinessLogics/BusinessLogic/ClassLogic.cs rename to University/UniversityBusinessLogics/BusinessLogic/OperationLogic.cs index 0c9d0d8..8d70d40 100644 --- a/University/UniversityBusinessLogics/BusinessLogic/ClassLogic.cs +++ b/University/UniversityBusinessLogics/BusinessLogic/OperationLogic.cs @@ -1,74 +1,72 @@ -using System; +using Microsoft.Extensions.Logging; +using System; using System.Collections.Generic; using System.Linq; -using System.Reflection; using System.Text; using System.Threading.Tasks; -using UniversityContracts.BusinessLogicContracts; using UniversityContracts.BindingModels; - +using UniversityContracts.BusinessLogicContracts; using UniversityContracts.SearchModels; using UniversityContracts.StoragesContracts; using UniversityContracts.ViewModels; -using Microsoft.Extensions.Logging; namespace UniversityBusinessLogics.BusinessLogic { - public class ClassLogic : IClassLogic + public class OperationLogic : IOperationLogic { private readonly ILogger _logger; - private readonly IClassStorage _carStorage; + private readonly IOperationStorage _carStorage; - public ClassLogic(ILogger logger, IClassStorage carStorage) + public OperationLogic(ILogger logger, IOperationStorage carStorage) { _logger = logger; _carStorage = carStorage; } - public void CheckOnlyModel(ClassBindingModel model) + public void CheckOnlyModel(OperationBindingModel model) { if (model == null) { - throw new ArgumentNullException(nameof(model), "Произошла ошибка на уровне проверки ClassBindingModel"); + throw new ArgumentNullException(nameof(model), "Произошла ошибка на уровне проверки OperationBindingModel"); } } - private void CheckUpdateModel(ClassBindingModel model) + private void CheckUpdateModel(OperationBindingModel model) { CheckOnlyModel(model); if (model.Price <= 0) { - throw new ArgumentException($"Произошла ошибка на уровне проверки ClassBindingModel. Стоимость операции (Price={model.Price}) должна быть больше 0"); + throw new ArgumentException($"Произошла ошибка на уровне проверки OperationBindingModel. Стоимость операции (Price={model.Price}) должна быть больше 0"); } } - public void CheckFullModel(ClassBindingModel model) + public void CheckFullModel(OperationBindingModel model) { CheckOnlyModel(model); CheckUpdateModel(model); - if (string.IsNullOrEmpty(model.Name) && string.IsNullOrEmpty(model.Time)) + if (string.IsNullOrEmpty(model.Model) && string.IsNullOrEmpty(model.Mark)) { - throw new ArgumentNullException($"Произошла ошибка на уровне проверки ClassBindingModel.Вид и тип операции не должна быть нулевыми или пустыми."); + throw new ArgumentNullException($"Произошла ошибка на уровне проверки OperationBindingModel.Вид и тип операции не должна быть нулевыми или пустыми."); } } - public List ReadList(ClassSearchModel? model) + public List ReadList(OperationSearchModel? model) { try { var results = model != null ? _carStorage.GetFilteredList(model) : _carStorage.GetFullList(); - _logger.LogDebug("Список операций: {@classes}", results); - _logger.LogInformation("Извлечение списка операций по {@ClassSearchModel} модели", model); + _logger.LogDebug("Список операций: {@operations}", results); + _logger.LogInformation("Извлечение списка операций по {@OperationSearchModel} модели", model); return results; } catch (Exception e) { - _logger.LogError(e, "Произошла ошибка при попытки получить список по {@ClassSearchModel} модели", model); + _logger.LogError(e, "Произошла ошибка при попытки получить список по {@OperationSearchModel} модели", model); throw; } } - public ClassViewModel ReadElement(ClassSearchModel model) + public OperationViewModel ReadElement(OperationSearchModel model) { try { @@ -77,17 +75,17 @@ namespace UniversityBusinessLogics.BusinessLogic { throw new ArgumentNullException($"Не получилось получить эдемент с id {model.Id}"); } - _logger.LogInformation("Извлечение элемента {@ClassViewModel} c обследований по {@ClassSearchModel} модели", result, model); + _logger.LogInformation("Извлечение элемента {@OperationViewModel} c обследований по {@OperationSearchModel} модели", result, model); return result; } catch (Exception e) { - _logger.LogError(e, "Произошла ошибка при попытки получить элемент по {@ClassSearchModel} модели:", model); + _logger.LogError(e, "Произошла ошибка при попытки получить элемент по {@OperationSearchModel} модели:", model); throw; } } - public bool Create(ClassBindingModel model) + public bool Create(OperationBindingModel model) { try { @@ -97,17 +95,17 @@ namespace UniversityBusinessLogics.BusinessLogic { throw new ArgumentNullException($"Не получилось создать операцию"); } - _logger.LogInformation("Создана сущность {@ClassViewModel}", result); + _logger.LogInformation("Создана сущность {@OperationViewModel}", result); return true; } catch (Exception e) { - _logger.LogError(e, "Произошла ошибка при попытки создать элемент по {@ClassBindingModel} модели", model); + _logger.LogError(e, "Произошла ошибка при попытки создать элемент по {@OperationBindingModel} модели", model); throw; } } - public bool Update(ClassBindingModel model) + public bool Update(OperationBindingModel model) { try { @@ -117,17 +115,17 @@ namespace UniversityBusinessLogics.BusinessLogic { throw new ArgumentNullException($"Результат обновления обследований оказался нулевым"); } - _logger.LogInformation("Была обновлена сущность на: {@ClassViewModel}", result); + _logger.LogInformation("Была обновлена сущность на: {@OperationViewModel}", result); return true; } catch (Exception e) { - _logger.LogError(e, "Произошла ошибка при попытки обновить элемент по модели: {@ClassBindingModel}", model); + _logger.LogError(e, "Произошла ошибка при попытки обновить элемент по модели: {@OperationBindingModel}", model); throw; } } - public bool Delete(ClassBindingModel model) + public bool Delete(OperationBindingModel model) { try { @@ -137,12 +135,12 @@ namespace UniversityBusinessLogics.BusinessLogic { throw new ArgumentNullException($"Не получилось удалить операциб"); } - _logger.LogInformation("Удалена сущность {@ClassViewModel}", result); + _logger.LogInformation("Удалена сущность {@OperationViewModel}", result); return true; } catch (Exception e) { - _logger.LogError(e, "Произошла ошибка при попытки удалить элемент по {@ClassBindingModel} модели", model); + _logger.LogError(e, "Произошла ошибка при попытки удалить элемент по {@OperationBindingModel} модели", model); throw; } } diff --git a/University/UniversityBusinessLogics/BusinessLogic/PaymentLogic.cs b/University/UniversityBusinessLogics/BusinessLogic/PaymentLogic.cs index e536dcf..aceaa7a 100644 --- a/University/UniversityBusinessLogics/BusinessLogic/PaymentLogic.cs +++ b/University/UniversityBusinessLogics/BusinessLogic/PaymentLogic.cs @@ -16,8 +16,8 @@ namespace UniversityBusinessLogics.BusinessLogic { private readonly ILogger _logger; private readonly IPaymentStorage _paymentStorage; - private readonly IClassStorage _carStorage; - public PaymentLogic(ILogger logger, IPaymentStorage paymentStorage, IClassStorage carStorage) + private readonly IOperationStorage _carStorage; + public PaymentLogic(ILogger logger, IPaymentStorage paymentStorage, IOperationStorage carStorage) { _logger = logger; _paymentStorage = paymentStorage; @@ -101,13 +101,13 @@ namespace UniversityBusinessLogics.BusinessLogic var payments = ReadList(model); // Вызываем метод из бизнес логики, чтобы залогировать доп информацию if (payments == null || payments.Count == 0) { - fullPrice = _carStorage.GetElement(new() { Id = model.ClassId })?.Price ?? throw new InvalidOperationException("Не получена операция для оплаты"); ; + fullPrice = _carStorage.GetElement(new() { Id = model.OperationId })?.Price ?? throw new InvalidOperationException("Не получена операция для оплаты"); ; paidPrice = 0; return true; } fullPrice = payments[0].FullPrice; paidPrice = payments.Sum(x => x.PaidPrice); - _logger.LogInformation("По покупке({Id}) и операцийе({Id}) получена полная стоимостиь {fullPrice} и оплаченная стоимость {paidPrice}", model.PurchaseId, model.ClassId, fullPrice, paidPrice); + _logger.LogInformation("По покупке({Id}) и операцийе({Id}) получена полная стоимостиь {fullPrice} и оплаченная стоимость {paidPrice}", model.PurchaseId, model.OperationId, fullPrice, paidPrice); return true; } catch (Exception e) diff --git a/University/UniversityBusinessLogics/BusinessLogic/ReportLogic.cs b/University/UniversityBusinessLogics/BusinessLogic/ReportLogic.cs index 4026815..6acc41d 100644 --- a/University/UniversityBusinessLogics/BusinessLogic/ReportLogic.cs +++ b/University/UniversityBusinessLogics/BusinessLogic/ReportLogic.cs @@ -15,14 +15,14 @@ namespace UniversityBusinessLogics.BusinessLogic { private readonly AbstractSaveToWord _saveToWord; private readonly IPurchaseStorage _purchaseStorage; - private readonly IClassStorage _carStorage; + private readonly IOperationStorage _carStorage; private readonly AbstractSaveToExcel _saveToExcel; private readonly IPaymentStorage _paymentStorage; private readonly AbstractMailWorker _mailWorker; private readonly AbstractSaveToPdf _saveToPdf; public ReportLogic(AbstractSaveToWord saveToWord, IPurchaseStorage purchaseStorage, AbstractSaveToExcel saveToExcel, - AbstractMailWorker mailWorker, IPaymentStorage paymentStorage, AbstractSaveToPdf saveToPdf, IClassStorage carStorage) + AbstractMailWorker mailWorker, IPaymentStorage paymentStorage, AbstractSaveToPdf saveToPdf, IOperationStorage carStorage) { _mailWorker = mailWorker; _paymentStorage = paymentStorage; @@ -40,7 +40,7 @@ namespace UniversityBusinessLogics.BusinessLogic FileName = option.FileName, Stream = option.Stream, Title = "Список сделок вместе с операциями", - ReportObjects = _purchaseStorage.GetFilteredList(new() { ClassesIds = option.Ids.ToList() }) + ReportObjects = _purchaseStorage.GetFilteredList(new() { OperationsIds = option.Ids.ToList() }) .Select(x => (object)x).ToList(), }); } @@ -52,7 +52,7 @@ namespace UniversityBusinessLogics.BusinessLogic FileName = option.FileName, Stream = option.Stream, Title = "Список сделок вместе с операциями", - ReportObjects = _purchaseStorage.GetFilteredList(new() { ClassesIds = option.Ids.ToList() }) + ReportObjects = _purchaseStorage.GetFilteredList(new() { OperationsIds = option.Ids.ToList() }) .Select(x => (object)x).ToList(), Headers = new() { "Сделка", "Дата сделки", } }); @@ -135,3 +135,4 @@ namespace UniversityBusinessLogics.BusinessLogic } } } + diff --git a/University/UniversityBusinessLogics/OfficePackage/AbstractSaveToExcel.cs b/University/UniversityBusinessLogics/OfficePackage/AbstractSaveToExcel.cs index 4fd09b2..27f1c29 100644 --- a/University/UniversityBusinessLogics/OfficePackage/AbstractSaveToExcel.cs +++ b/University/UniversityBusinessLogics/OfficePackage/AbstractSaveToExcel.cs @@ -71,7 +71,7 @@ namespace UniversityBusinessLogics.OfficePackage StyleInfo = ExcelStyleInfoType.Text }); int i = 0; - foreach (var car in purchase.ClassViewModels) + foreach (var car in purchase.OperationViewModels) { if (info.Ids != null && !info.Ids.Contains(car.Id)) { @@ -81,7 +81,7 @@ namespace UniversityBusinessLogics.OfficePackage { ColumnName = ((char)('C' + i)).ToString(), RowIndex = rowIndex, - Text = $"{car.Time} {car.Name} в количестве {purchase.ClassModel[car.Id].CountClass}", + Text = $"{car.Mark} {car.Model} в количестве {purchase.OperationsModel[car.Id].CountOperations}", StyleInfo = ExcelStyleInfoType.TextWithBroder }); if (info.Ids != null) @@ -103,7 +103,7 @@ namespace UniversityBusinessLogics.OfficePackage uint rowIndex = 3; foreach (var pc in info.ReportObjects) { - var car = pc as ClassViewModel; + var car = pc as OperationViewModel; if (car == null) { throw new ArgumentException($"Передан некорректный тип в отчет: " + @@ -119,21 +119,21 @@ namespace UniversityBusinessLogics.OfficePackage { ColumnName = "A", RowIndex = rowIndex, - Text = car.Time, + Text = car.Mark, StyleInfo = ExcelStyleInfoType.Text }); InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "B", RowIndex = rowIndex, - Text = car.Name, + Text = car.Model, StyleInfo = ExcelStyleInfoType.Text }); InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "C", RowIndex = rowIndex, - Text = purchase.ClassModel[car.Id].CountClass.ToString(), + Text = purchase.OperationsModel[car.Id].CountOperations.ToString(), StyleInfo = ExcelStyleInfoType.Text }); InsertCellInWorksheet(new ExcelCellParameters @@ -172,6 +172,5 @@ namespace UniversityBusinessLogics.OfficePackage /// /// protected abstract void SaveExcel(ExcelInfo info); - } } diff --git a/University/UniversityBusinessLogics/OfficePackage/AbstractSaveToPdf.cs b/University/UniversityBusinessLogics/OfficePackage/AbstractSaveToPdf.cs index cae9ad9..23362d1 100644 --- a/University/UniversityBusinessLogics/OfficePackage/AbstractSaveToPdf.cs +++ b/University/UniversityBusinessLogics/OfficePackage/AbstractSaveToPdf.cs @@ -40,7 +40,7 @@ namespace UniversityBusinessLogics.OfficePackage $"ожидается Payment; Получен объект типа: {pc.GetType()}", nameof(info)); } - if (payment.Operation == null || payment.ClassByPurchase == null) + if (payment.Operation == null || payment.OperationByPurchase == null) { throw new ArgumentNullException($"Получена модель оплаты c нулевыми полями"); } @@ -49,8 +49,8 @@ namespace UniversityBusinessLogics.OfficePackage { Texts = new List { - payment.ClassByPurchase.PurchaseId.ToString(), - payment.Operation.Time + " " + payment.Operation.Name, + payment.OperationByPurchase.PurchaseId.ToString(), + payment.Operation.Mark + " " + payment.Operation.Model, payment.Date.ToShortDateString(), payment.PaidPrice.ToString(), payment.FullPrice.ToString(), @@ -145,6 +145,5 @@ namespace UniversityBusinessLogics.OfficePackage /// /// protected abstract void SavePdf(PdfInfo info); - } } diff --git a/University/UniversityBusinessLogics/UniversityBusinessLogics.csproj b/University/UniversityBusinessLogics/UniversityBusinessLogics.csproj index b40a49f..9efa965 100644 --- a/University/UniversityBusinessLogics/UniversityBusinessLogics.csproj +++ b/University/UniversityBusinessLogics/UniversityBusinessLogics.csproj @@ -8,18 +8,7 @@ - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - diff --git a/University/UniversityClientApp/Program.cs b/University/UniversityClientApp/Program.cs index 6d657e2..eb9612c 100644 --- a/University/UniversityClientApp/Program.cs +++ b/University/UniversityClientApp/Program.cs @@ -19,7 +19,7 @@ builder.Services.AddSession(); // builder.Services.AddTransient(); builder.Services.AddTransient(); -builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); @@ -29,7 +29,7 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); -builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddSingleton(); diff --git a/University/UniversityClientApp/UniversityClientApp.csproj b/University/UniversityClientApp/UniversityClientApp.csproj index bce63d1..49fe398 100644 --- a/University/UniversityClientApp/UniversityClientApp.csproj +++ b/University/UniversityClientApp/UniversityClientApp.csproj @@ -7,17 +7,10 @@ - all runtime; build; native; contentfiles; analyzers; buildtransitive - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - diff --git a/University/UniversityContracts/BindingModels/ClientBindingModel.cs b/University/UniversityContracts/BindingModels/ClientBindingModel.cs index 3bc00e4..71bad7e 100644 --- a/University/UniversityContracts/BindingModels/ClientBindingModel.cs +++ b/University/UniversityContracts/BindingModels/ClientBindingModel.cs @@ -11,7 +11,7 @@ namespace UniversityContracts.BindingModels public string? MiddleName { get; set; } - public string Login { get; set; } = string.Empty; + public string PhoneNumber { get; set; } = string.Empty; public string Password { get; set; } = string.Empty; @@ -19,4 +19,5 @@ namespace UniversityContracts.BindingModels public string Email { get; set; } = string.Empty; } + } diff --git a/University/UniversityContracts/BindingModels/CostBindingModel.cs b/University/UniversityContracts/BindingModels/CostBindingModel.cs index 2822338..928444e 100644 --- a/University/UniversityContracts/BindingModels/CostBindingModel.cs +++ b/University/UniversityContracts/BindingModels/CostBindingModel.cs @@ -3,11 +3,12 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using UniversityDataModels.Models; +using UniversityDataModels; +using UniversityDataModels.ProxyModels; namespace UniversityContracts.BindingModels { - public class CostBindingModel + public class CostBindingModel : ICostModel { public int EmployeeId { get; set; } diff --git a/University/UniversityContracts/BindingModels/EmployeeBindingModel.cs b/University/UniversityContracts/BindingModels/EmployeeBindingModel.cs index f898046..6818106 100644 --- a/University/UniversityContracts/BindingModels/EmployeeBindingModel.cs +++ b/University/UniversityContracts/BindingModels/EmployeeBindingModel.cs @@ -12,14 +12,12 @@ namespace UniversityContracts.BindingModels public string? MiddleName { get; set; } - public string Login { get; set; } = string.Empty; + public string PhoneNumber { get; set; } = string.Empty; public string Password { get; set; } = string.Empty; public int Id { get; set; } + public string Email { get; set; } = string.Empty; - - - } } diff --git a/University/UniversityContracts/BindingModels/ClassBindingModel.cs b/University/UniversityContracts/BindingModels/OperationBindingModel.cs similarity index 60% rename from University/UniversityContracts/BindingModels/ClassBindingModel.cs rename to University/UniversityContracts/BindingModels/OperationBindingModel.cs index 18b767f..11dd287 100644 --- a/University/UniversityContracts/BindingModels/ClassBindingModel.cs +++ b/University/UniversityContracts/BindingModels/OperationBindingModel.cs @@ -3,14 +3,15 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using UniversityDataModels; namespace UniversityContracts.BindingModels { - public class ClassBindingModel + public class OperationBindingModel : IOperationModel { - public string Name { get; set; } = string.Empty; + public string Model { get; set; } = string.Empty; - public string Time { get; set; } = string.Empty; + public string Mark { get; set; } = string.Empty; public double Price { get; set; } diff --git a/University/UniversityContracts/BindingModels/PaymentBindingModel.cs b/University/UniversityContracts/BindingModels/PaymentBindingModel.cs index 2bad4cf..570ffe3 100644 --- a/University/UniversityContracts/BindingModels/PaymentBindingModel.cs +++ b/University/UniversityContracts/BindingModels/PaymentBindingModel.cs @@ -3,18 +3,18 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using UniversityDataModels; namespace UniversityContracts.BindingModels { - public class PaymentBindingModel + public class PaymentBindingModel : IPaymentModel { - public DateTime DateCreate { get; set; } = DateTime.Now; - + public DateOnly Date { get; set; } = DateOnly.FromDateTime(DateTime.Now); public double PaidPrice { get; set; } public int Id { get; set; } - public int ClassByPurchaseId { get; set; } + public int OperationByPurchaseId { get; set; } } } diff --git a/University/UniversityContracts/BindingModels/PurchaseBindingModel.cs b/University/UniversityContracts/BindingModels/PurchaseBindingModel.cs index a40ccee..fbd15d1 100644 --- a/University/UniversityContracts/BindingModels/PurchaseBindingModel.cs +++ b/University/UniversityContracts/BindingModels/PurchaseBindingModel.cs @@ -1,6 +1,7 @@ using UniversityDataModels; using UniversityDataModels.HelperInterfaces; -using UniversityDataModels.Models; +using UniversityDataModels.ProxyModels; + namespace UniversityContracts.BindingModels { @@ -8,7 +9,7 @@ namespace UniversityContracts.BindingModels { public int ClientId { get; set; } public DateOnly DatePurchase { get; set; } - public Dictionary ClassModel { get; set; } = new(); + public Dictionary OperationsModel { get; set; } = new(); public List CostsModel { get; set; } = new(); public int Id { get; set; } diff --git a/University/UniversityContracts/BusinessLogicContracts/IClassLogic.cs b/University/UniversityContracts/BusinessLogicContracts/IClassLogic.cs deleted file mode 100644 index 6338fb9..0000000 --- a/University/UniversityContracts/BusinessLogicContracts/IClassLogic.cs +++ /dev/null @@ -1,15 +0,0 @@ -using UniversityContracts.BindingModels; -using UniversityContracts.SearchModels; -using UniversityContracts.ViewModels; - -namespace UniversityContracts.BusinessLogicContracts -{ - public interface IClassLogic - { - List ReadList(ClassSearchModel? model = null); - ClassViewModel ReadElement(ClassSearchModel model); - bool Create(ClassBindingModel model); - bool Update(ClassBindingModel model); - bool Delete(ClassBindingModel model); - } -} \ No newline at end of file diff --git a/University/UniversityContracts/BusinessLogicContracts/IOperationLogic.cs b/University/UniversityContracts/BusinessLogicContracts/IOperationLogic.cs new file mode 100644 index 0000000..f579efe --- /dev/null +++ b/University/UniversityContracts/BusinessLogicContracts/IOperationLogic.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityContracts.BindingModels; +using UniversityContracts.SearchModels; +using UniversityContracts.ViewModels; + +namespace UniversityContracts.BusinessLogicContracts +{ + public interface IOperationLogic + { + List ReadList(OperationSearchModel? model = null); + OperationViewModel ReadElement(OperationSearchModel model); + bool Create(OperationBindingModel model); + bool Update(OperationBindingModel model); + bool Delete(OperationBindingModel model); + } +} diff --git a/University/UniversityContracts/BusinessLogicContracts/IReportLogic.cs b/University/UniversityContracts/BusinessLogicContracts/IReportLogic.cs index 432fb66..044b975 100644 --- a/University/UniversityContracts/BusinessLogicContracts/IReportLogic.cs +++ b/University/UniversityContracts/BusinessLogicContracts/IReportLogic.cs @@ -19,6 +19,5 @@ namespace UniversityContracts.BusinessLogicContracts void SaveOperationsToExcel(ReportBindingModel option); void SendCostsToEmail(ReportDateRangeBindingModel option, string email); - } } diff --git a/University/UniversityContracts/SearchModels/ClassSearchModel.cs b/University/UniversityContracts/SearchModels/ClassSearchModel.cs deleted file mode 100644 index 8143fae..0000000 --- a/University/UniversityContracts/SearchModels/ClassSearchModel.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace UniversityContracts.SearchModels -{ - public class ClassSearchModel - { - public int? Id { get; set; } - public int? EmployeeId { get; set; } - public string Name { get; set; } = string.Empty; - public string Time { get; set; } = string.Empty; - public int Price { get; set; } - public List? PurchasesIds { get; set; } - } -} \ No newline at end of file diff --git a/University/UniversityContracts/SearchModels/ClientSearchModel.cs b/University/UniversityContracts/SearchModels/ClientSearchModel.cs index b5d9d50..1a2d559 100644 --- a/University/UniversityContracts/SearchModels/ClientSearchModel.cs +++ b/University/UniversityContracts/SearchModels/ClientSearchModel.cs @@ -3,7 +3,7 @@ public class ClientSearchModel { public int? Id { get; set; } - public string? Login { get; set; } + public string? PhoneNumber { get; set; } public string? Password { get; set; } } } diff --git a/University/UniversityContracts/SearchModels/EmployeeSearchModel.cs b/University/UniversityContracts/SearchModels/EmployeeSearchModel.cs index dbd28df..857cb75 100644 --- a/University/UniversityContracts/SearchModels/EmployeeSearchModel.cs +++ b/University/UniversityContracts/SearchModels/EmployeeSearchModel.cs @@ -3,7 +3,7 @@ public class EmployeeSearchModel { public int? Id { get; set; } - public string? Login { get; set; } + public string? PhoneNumber { get; set; } public string? Password { get; set; } } } diff --git a/University/UniversityContracts/SearchModels/OperationSearchModel.cs b/University/UniversityContracts/SearchModels/OperationSearchModel.cs new file mode 100644 index 0000000..423e50c --- /dev/null +++ b/University/UniversityContracts/SearchModels/OperationSearchModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UniversityContracts.SearchModels +{ + public class OperationSearchModel + { + public int? Id { get; set; } + public int? EmployeeId { get; set; } + public string Model { get; set; } = string.Empty; + public string Mark { get; set; } = string.Empty; + public int Price { get; set; } + public List? PurchasesIds { get; set; } + } +} diff --git a/University/UniversityContracts/SearchModels/PaymentSearchModel.cs b/University/UniversityContracts/SearchModels/PaymentSearchModel.cs index 0f16d22..2bc7e7e 100644 --- a/University/UniversityContracts/SearchModels/PaymentSearchModel.cs +++ b/University/UniversityContracts/SearchModels/PaymentSearchModel.cs @@ -9,10 +9,10 @@ namespace UniversityContracts.SearchModels public class PaymentSearchModel { public int? Id { get; set; } - public int? ClassId { get; set; } + public int? OperationId { get; set; } public int? PurchaseId { get; set; } - public DateTime? DateFrom { get; set; } - public DateTime? DateTo { get; set; } + public DateOnly? DateFrom { get; set; } + public DateOnly? DateTo { get; set; } } } \ No newline at end of file diff --git a/University/UniversityContracts/SearchModels/PurchaseSearchModel.cs b/University/UniversityContracts/SearchModels/PurchaseSearchModel.cs index b4cf671..f7a4ea8 100644 --- a/University/UniversityContracts/SearchModels/PurchaseSearchModel.cs +++ b/University/UniversityContracts/SearchModels/PurchaseSearchModel.cs @@ -4,9 +4,9 @@ { public int? Id { get; set; } public DateOnly? DateTo { get; set; } - public DateOnly? DateFrom { get; set; } - public int? ClientId { get; set; } + public DateOnly? DateFrom { get; set; } + public int? ClientId { get; set; } - public List? ClassesIds { get; set; } - } + public List? OperationsIds { get; set; } + } } diff --git a/University/UniversityContracts/StoragesContracts/IClassStorage.cs b/University/UniversityContracts/StoragesContracts/IClassStorage.cs deleted file mode 100644 index bb43626..0000000 --- a/University/UniversityContracts/StoragesContracts/IClassStorage.cs +++ /dev/null @@ -1,17 +0,0 @@ -using UniversityContracts.BindingModels; -using UniversityContracts.SearchModels; -using UniversityContracts.ViewModels; - - -namespace UniversityContracts.StoragesContracts -{ - public interface IClassStorage - { - List GetFullList(); - List GetFilteredList(ClassSearchModel model); - ClassViewModel? GetElement(ClassSearchModel model); - ClassViewModel? Insert(ClassBindingModel model); - ClassViewModel? Update(ClassBindingModel model); - ClassViewModel? Delete(ClassBindingModel model); - } -} diff --git a/University/UniversityContracts/StoragesContracts/IOperationStorage.cs b/University/UniversityContracts/StoragesContracts/IOperationStorage.cs new file mode 100644 index 0000000..8e4fd0c --- /dev/null +++ b/University/UniversityContracts/StoragesContracts/IOperationStorage.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityContracts.BindingModels; +using UniversityContracts.SearchModels; +using UniversityContracts.ViewModels; + +namespace UniversityContracts.StoragesContracts +{ + public interface IOperationStorage + { + List GetFullList(); + List GetFilteredList(OperationSearchModel model); + OperationViewModel? GetElement(OperationSearchModel model); + OperationViewModel? Insert(OperationBindingModel model); + OperationViewModel? Update(OperationBindingModel model); + OperationViewModel? Delete(OperationBindingModel model); + } +} diff --git a/University/UniversityContracts/StoragesContracts/IPurchaseStorage.cs b/University/UniversityContracts/StoragesContracts/IPurchaseStorage.cs index 28c084f..384697e 100644 --- a/University/UniversityContracts/StoragesContracts/IPurchaseStorage.cs +++ b/University/UniversityContracts/StoragesContracts/IPurchaseStorage.cs @@ -15,6 +15,6 @@ namespace UniversityContracts.StoragesContracts PurchaseViewModel? Update(PurchaseBindingModel model); PurchaseViewModel? Delete(PurchaseBindingModel model); - List GetPaymentsFromPurchaseAndOperation(PurchaseSearchModel modelPurchase, ClassSearchModel modelClass); + List GetPaymentsFromPurchaseAndOperation(PurchaseSearchModel modelPurchase, OperationSearchModel modelOperation); } } diff --git a/University/UniversityContracts/UniversityContracts.csproj b/University/UniversityContracts/UniversityContracts.csproj index 07fb6a1..f587015 100644 --- a/University/UniversityContracts/UniversityContracts.csproj +++ b/University/UniversityContracts/UniversityContracts.csproj @@ -7,17 +7,10 @@ - all runtime; build; native; contentfiles; analyzers; buildtransitive - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - diff --git a/University/UniversityContracts/ViewModels/ClassViewModel.cs b/University/UniversityContracts/ViewModels/ClassViewModel.cs deleted file mode 100644 index 1d827dc..0000000 --- a/University/UniversityContracts/ViewModels/ClassViewModel.cs +++ /dev/null @@ -1,33 +0,0 @@ -using UniversityDataModels; -using System.ComponentModel; -using System.Text; -using System.Text.Json.Serialization; - -namespace UniversityContracts.ViewModels -{ - public class ClassViewModel : IClassModel - { - public int Id { get; set; } - public int EmployeeId { get; set; } - [DisplayName("Логин сотрудника")] - public string EmployeeLogin { get; set; } = string.Empty; - [DisplayName("Стоимость")] - public double Price { get; set; } - [DisplayName("Вид операции")] - public string Name { get; set; } = string.Empty; - [DisplayName("Тип операции")] - public string Time { get; set; } = string.Empty; - [JsonIgnore] - public List Purchases { get; set; } = new(); - public override string ToString() - { - var result = new StringBuilder(); - foreach (var purchase in Purchases) - { - result.Append($"Операция вида {Name},Типа {Time}, Купленная {purchase.DatePurchase.ToShortDateString()}," + - $"в покупе c id: {purchase.Id}\n"); - } - return result.ToString(); - } - } -} \ No newline at end of file diff --git a/University/UniversityContracts/ViewModels/ClientViewModel.cs b/University/UniversityContracts/ViewModels/ClientViewModel.cs index 51e9eb7..9d57f4e 100644 --- a/University/UniversityContracts/ViewModels/ClientViewModel.cs +++ b/University/UniversityContracts/ViewModels/ClientViewModel.cs @@ -14,8 +14,8 @@ namespace UniversityContracts.ViewModels public string FirstName { get; set; } = string.Empty; [DisplayName("Отчество")] public string? MiddleName { get; set; } = string.Empty; - [DisplayName("Логин")] - public string Login { get; set; } = string.Empty; + [DisplayName("Номер телефона")] + public string PhoneNumber { get; set; } = string.Empty; [DisplayName("Пароль")] public string Password { get; set; } = string.Empty; public string Email { get; set; } = string.Empty; diff --git a/University/UniversityContracts/ViewModels/CostViewModel.cs b/University/UniversityContracts/ViewModels/CostViewModel.cs index 498a3d1..ac086fb 100644 --- a/University/UniversityContracts/ViewModels/CostViewModel.cs +++ b/University/UniversityContracts/ViewModels/CostViewModel.cs @@ -1,6 +1,6 @@ -using UniversityDataModels.Models; -using UniversityDataModels; +using UniversityDataModels; using System.ComponentModel; +using UniversityDataModels.ProxyModels; namespace UniversityContracts.ViewModels { @@ -8,9 +8,8 @@ namespace UniversityContracts.ViewModels { public int Id { get; set; } public int EmployeeId { get; set; } - [DisplayName("Логин сотрудника")] - public string Login { get; set; } = string.Empty; - + [DisplayName("Номер телефона сотрудника")] + public string PhoneNumber { get; set; } = string.Empty; [DisplayName("Наименование")] public string NameOfCost { get; set; } = string.Empty; [DisplayName("Стоимость")] diff --git a/University/UniversityContracts/ViewModels/EmployeeViewModel.cs b/University/UniversityContracts/ViewModels/EmployeeViewModel.cs index ed7979b..7632559 100644 --- a/University/UniversityContracts/ViewModels/EmployeeViewModel.cs +++ b/University/UniversityContracts/ViewModels/EmployeeViewModel.cs @@ -11,26 +11,18 @@ namespace UniversityContracts.ViewModels public class EmployeeViewModel : IEmployeeModel { public int Id { get; set; } - [DisplayName("Фамилия")] public string LastName { get; set; } = string.Empty; - [DisplayName("Имя")] public string FirstName { get; set; } = string.Empty; - [DisplayName("Отчество")] public string? MiddleName { get; set; } = string.Empty; - - [DisplayName("Логин")] - public string Login { get; set; } = string.Empty; - + [DisplayName("Номер телефона")] + public string PhoneNumber { get; set; } = string.Empty; [DisplayName("Пароль")] public string Password { get; set; } = string.Empty; - [DisplayName("Должность")] public string Post { get; set; } = string.Empty; - public string Email { get; set; } = string.Empty; - } } diff --git a/University/UniversityContracts/ViewModels/OperationViewModel.cs b/University/UniversityContracts/ViewModels/OperationViewModel.cs new file mode 100644 index 0000000..65b5a05 --- /dev/null +++ b/University/UniversityContracts/ViewModels/OperationViewModel.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Text.Json.Serialization; +using System.Threading.Tasks; +using UniversityDataModels; + +namespace UniversityContracts.ViewModels +{ + public class OperationViewModel : IOperationModel + { + public int Id { get; set; } + public int EmployeeId { get; set; } + [DisplayName("Номер телефона сотрудника")] + public string EmployeePhoneNumber { get; set; } = string.Empty; + [DisplayName("Стоимость")] + public double Price { get; set; } + [DisplayName("Вид операции")] + public string Model { get; set; } = string.Empty; + [DisplayName("Тип операции")] + public string Mark { get; set; } = string.Empty; + [JsonIgnore] + public List Purchases { get; set; } = new(); + public override string ToString() + { + var result = new StringBuilder(); + foreach (var purchase in Purchases) + { + result.Append($"Операция вида {Model},Типа {Mark}, Купленная {purchase.DatePurchase.ToShortDateString()}," + + $"в покупе c id: {purchase.Id}\n"); + } + return result.ToString(); + } + } + +} diff --git a/University/UniversityContracts/ViewModels/PaymentViewModel.cs b/University/UniversityContracts/ViewModels/PaymentViewModel.cs index 7f009a3..93be53c 100644 --- a/University/UniversityContracts/ViewModels/PaymentViewModel.cs +++ b/University/UniversityContracts/ViewModels/PaymentViewModel.cs @@ -6,24 +6,24 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using UniversityContracts.ViewModels; -using UniversityDataModels.Models; +using UniversityDataModels.ProxyModels; namespace BankContracts.ViewModels { public class PaymentViewModel : IPaymentModel { public int Id { get; set; } - public int ClassByPurchaseModelId { get; set; } + public int OperationByPurchaseModelId { get; set; } [DisplayName("Стоимость")] public double FullPrice { get; set; } [DisplayName("Оплаченная стоимость")] public double PaidPrice { get; set; } - public int ClassByPurchaseId { get; set; } + public int OperationByPurchaseId { get; set; } [DisplayName("Дата оплаты")] - public DateTime DateCreate { get; set; } = DateTime.Now; - public ClassByPurchaseModel ClassByPurchase { get; set; } + public DateOnly Date { get; set; } = DateOnly.FromDateTime(DateTime.Now); + public OperationByPurchaseModel OperationByPurchase { get; set; } // Машины для отчета за период - public ClassViewModel Operation { get; set; } + public OperationViewModel Operation { get; set; } } } diff --git a/University/UniversityContracts/ViewModels/PurchaseViewModel.cs b/University/UniversityContracts/ViewModels/PurchaseViewModel.cs index 1e481ca..9d2277e 100644 --- a/University/UniversityContracts/ViewModels/PurchaseViewModel.cs +++ b/University/UniversityContracts/ViewModels/PurchaseViewModel.cs @@ -1,7 +1,10 @@ using UniversityDataModels; using System.ComponentModel; -using UniversityDataModels.Models; using System.Text; +using UniversityDataModels.ProxyModels; +using UniversityContracts.BindingModels; +using UniversityContracts.SearchModels; +using UniversityContracts.StoragesContracts; namespace UniversityContracts.ViewModels { @@ -10,30 +13,30 @@ namespace UniversityContracts.ViewModels public int Id { get; set; } public int ClientId { get; set; } [DisplayName("Логин клиента")] - public string ClientLogin { get; set; } = string.Empty; + public string ClientPhoneNumber { get; set; } = string.Empty; [DisplayName("Дата Покупки")] public DateOnly DatePurchase { get; set; } = DateOnly.FromDateTime(DateTime.Now); - public Dictionary ClassModel { get; set; } = new(); + public Dictionary OperationsModel { get; set; } = new(); public List CostViewModels { get; set; } = new(); - public List ClassViewModels { get; set; } = new(); + public List OperationViewModels { get; set; } = new(); public override string ToString() { var result = new StringBuilder( $"Сделка, созданная {DatePurchase}, включает в себя операции:"); - for (int i = 0; i < ClassViewModels.Count; i++) - { - var car = ClassViewModels[i]; + for (int i = 0; i < OperationViewModels.Count; i++) + { + var car = OperationViewModels[i]; if (car == null) { break; } - result.Append($"\n\t{i + 1}. {car.Time} {car.Name} стоимостью {car.Price}"); - } - return result.ToString(); - } + result.Append($"\n\t{i + 1}. {car.Mark} {car.Model} стоимостью {car.Price}"); + } + return result.ToString(); + } + } } - \ No newline at end of file diff --git a/University/UniversityDataModels/HelperInterfaces/IId.cs b/University/UniversityDataModels/HelperInterfaces/IId.cs index 1b927b0..d820f68 100644 --- a/University/UniversityDataModels/HelperInterfaces/IId.cs +++ b/University/UniversityDataModels/HelperInterfaces/IId.cs @@ -1,4 +1,10 @@ -namespace UniversityDataModels.HelperInterfaces +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UniversityDataModels.HelperInterfaces { public interface IId { diff --git a/University/UniversityDataModels/IClientModel.cs b/University/UniversityDataModels/IClientModel.cs index 78d529c..f12cf3a 100644 --- a/University/UniversityDataModels/IClientModel.cs +++ b/University/UniversityDataModels/IClientModel.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using UniversityDataModels.HelperInterfaces; namespace UniversityDataModels { @@ -12,7 +13,7 @@ namespace UniversityDataModels string FirstName { get; } string LastName { get; } string? MiddleName { get; } - string Login { get; } + string PhoneNumber { get; } string Password { get; } } } diff --git a/University/UniversityDataModels/ICostModel.cs b/University/UniversityDataModels/ICostModel.cs index 762cf8c..2c8b10f 100644 --- a/University/UniversityDataModels/ICostModel.cs +++ b/University/UniversityDataModels/ICostModel.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using UniversityDataModels.HelperInterfaces; namespace UniversityDataModels { diff --git a/University/UniversityDataModels/IId.cs b/University/UniversityDataModels/IId.cs deleted file mode 100644 index 114f99f..0000000 --- a/University/UniversityDataModels/IId.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace UniversityDataModels -{ - public interface IId - { - int Id { get; } - } -} diff --git a/University/UniversityDataModels/IClassModel.cs b/University/UniversityDataModels/IOperationModel.cs similarity index 60% rename from University/UniversityDataModels/IClassModel.cs rename to University/UniversityDataModels/IOperationModel.cs index 21a8a25..0e28305 100644 --- a/University/UniversityDataModels/IClassModel.cs +++ b/University/UniversityDataModels/IOperationModel.cs @@ -3,14 +3,15 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using UniversityDataModels.HelperInterfaces; namespace UniversityDataModels { - public interface IClassModel : IId + public interface IOperationModel : IId { int EmployeeId { get; } - string Name { get; } - string Time { get; } + string Model { get; } + string Mark { get; } double Price { get; } } } diff --git a/University/UniversityDataModels/IPaymentModel.cs b/University/UniversityDataModels/IPaymentModel.cs index 1556bc1..076ce24 100644 --- a/University/UniversityDataModels/IPaymentModel.cs +++ b/University/UniversityDataModels/IPaymentModel.cs @@ -3,13 +3,14 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using UniversityDataModels.HelperInterfaces; namespace UniversityDataModels { public interface IPaymentModel : IId { double PaidPrice { get; } - DateTime DateCreate { get; } - int ClassByPurchaseId { get; } + DateOnly Date { get; } + int OperationByPurchaseId { get; } } } diff --git a/University/UniversityDataModels/IPurchaseModel.cs b/University/UniversityDataModels/IPurchaseModel.cs index e663404..5b63f71 100644 --- a/University/UniversityDataModels/IPurchaseModel.cs +++ b/University/UniversityDataModels/IPurchaseModel.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using UniversityDataModels.HelperInterfaces; namespace UniversityDataModels { diff --git a/University/UniversityDataModels/ProxyModels/ClassByPurchaseModel.cs b/University/UniversityDataModels/ProxyModels/ClassByPurchaseModel.cs deleted file mode 100644 index 2c7814a..0000000 --- a/University/UniversityDataModels/ProxyModels/ClassByPurchaseModel.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace UniversityDataModels.Models -{ - public class ClassByPurchaseModel - { - public virtual int Id { get; set; } - public virtual int ClassId { get; set; } - public virtual int PurchaseId { get; set; } - public virtual int CountClass { get; set; } - } -} diff --git a/University/UniversityDataModels/ProxyModels/CostByPurchaseModel.cs b/University/UniversityDataModels/ProxyModels/CostByPurchaseModel.cs index b2f4771..937c2a2 100644 --- a/University/UniversityDataModels/ProxyModels/CostByPurchaseModel.cs +++ b/University/UniversityDataModels/ProxyModels/CostByPurchaseModel.cs @@ -1,5 +1,11 @@ - -namespace UniversityDataModels.Models +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityDataModels.HelperInterfaces; + +namespace UniversityDataModels.ProxyModels { public class CostByPurchaseModel : IId { diff --git a/University/UniversityDataModels/ProxyModels/OperationByPurchaseModel.cs b/University/UniversityDataModels/ProxyModels/OperationByPurchaseModel.cs new file mode 100644 index 0000000..63ac8c7 --- /dev/null +++ b/University/UniversityDataModels/ProxyModels/OperationByPurchaseModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityDataModels.HelperInterfaces; + +namespace UniversityDataModels.ProxyModels +{ + public class OperationByPurchaseModel : IId + { + public virtual int Id { get; set; } + public virtual int OperationId { get; set; } + public virtual int PurchaseId { get; set; } + public virtual int CountOperations { get; set; } + } +} diff --git a/University/UniversityDataModels/UniversityDataModels.csproj b/University/UniversityDataModels/UniversityDataModels.csproj index 41d945e..68bb9bf 100644 --- a/University/UniversityDataModels/UniversityDataModels.csproj +++ b/University/UniversityDataModels/UniversityDataModels.csproj @@ -7,17 +7,6 @@ - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - diff --git a/University/UniversityDatabaseImplement/Implements/ClientStorage.cs b/University/UniversityDatabaseImplement/Implements/ClientStorage.cs index ffc7b7a..1f2230d 100644 --- a/University/UniversityDatabaseImplement/Implements/ClientStorage.cs +++ b/University/UniversityDatabaseImplement/Implements/ClientStorage.cs @@ -13,9 +13,9 @@ namespace UiversityDatabaseImplement.Implements { if (model == null) throw new ArgumentNullException("Передаваемая модель для поиска равна нулю", nameof(model)); - if (!model.Id.HasValue && string.IsNullOrEmpty(model.Login) && string.IsNullOrEmpty(model.Password)) + if (!model.Id.HasValue && string.IsNullOrEmpty(model.PhoneNumber) && string.IsNullOrEmpty(model.Password)) throw new ArgumentException("Все передаваемые поля поисковой модели оказались пусты или равны null"); - if (!model.Id.HasValue && (string.IsNullOrEmpty(model.Login) && !string.IsNullOrEmpty(model.Password))) + if (!model.Id.HasValue && (string.IsNullOrEmpty(model.PhoneNumber) && !string.IsNullOrEmpty(model.Password))) throw new ArgumentException("Для нахождения соответствующего пользователя вместе с паролем нужен логин"); } public ClientViewModel? GetElement(ClientSearchModel model) @@ -23,7 +23,7 @@ namespace UiversityDatabaseImplement.Implements CheckSearchModel(model); using var context = new UniversityDB(); - return context.Clients.FirstOrDefault(x => x.Login.Equals(model.Login) && (string.IsNullOrEmpty(model.Password) || x.Password.Equals(model.Password)))?.GetViewModel; + return context.Clients.FirstOrDefault(x => x.PhoneNumber.Equals(model.PhoneNumber) && (string.IsNullOrEmpty(model.Password) || x.Password.Equals(model.Password)))?.GetViewModel; } public ClientViewModel? Insert(ClientBindingModel model) { diff --git a/University/UniversityDatabaseImplement/Implements/EmployeeStorage.cs b/University/UniversityDatabaseImplement/Implements/EmployeeStorage.cs index 30f9c9f..56500a4 100644 --- a/University/UniversityDatabaseImplement/Implements/EmployeeStorage.cs +++ b/University/UniversityDatabaseImplement/Implements/EmployeeStorage.cs @@ -12,9 +12,9 @@ namespace UniversityDatabaseImplement.Implements { if (model == null) throw new ArgumentNullException("Передаваемая модель для поиска равна нулю", nameof(model)); - if (!model.Id.HasValue && string.IsNullOrEmpty(model.Login) && string.IsNullOrEmpty(model.Password)) + if (!model.Id.HasValue && string.IsNullOrEmpty(model.PhoneNumber) && string.IsNullOrEmpty(model.Password)) throw new ArgumentException("Все передаваемые поля поисковой модели оказались пусты или равны null"); - if (!model.Id.HasValue && (string.IsNullOrEmpty(model.Login) && !string.IsNullOrEmpty(model.Password))) + if (!model.Id.HasValue && (string.IsNullOrEmpty(model.PhoneNumber) && !string.IsNullOrEmpty(model.Password))) throw new ArgumentException("Для нахождения соответствующего пользователя вместе с паролем нужен логин"); } public EmployeeViewModel? GetElement(EmployeeSearchModel model) @@ -23,7 +23,7 @@ namespace UniversityDatabaseImplement.Implements using var context = new UniversityDB(); return context.Employees - .FirstOrDefault(x => x.Login.Equals(model.Login) && (string.IsNullOrEmpty(model.Password) || x.Password.Equals(model.Password)))?.GetViewModel; + .FirstOrDefault(x => x.PhoneNumber.Equals(model.PhoneNumber) && (string.IsNullOrEmpty(model.Password) || x.Password.Equals(model.Password)))?.GetViewModel; } public EmployeeViewModel? Insert(EmployeeBindingModel model) { diff --git a/University/UniversityDatabaseImplement/Implements/ClassStorage.cs b/University/UniversityDatabaseImplement/Implements/OperationStorage.cs similarity index 70% rename from University/UniversityDatabaseImplement/Implements/ClassStorage.cs rename to University/UniversityDatabaseImplement/Implements/OperationStorage.cs index 5005ca9..16ba8e9 100644 --- a/University/UniversityDatabaseImplement/Implements/ClassStorage.cs +++ b/University/UniversityDatabaseImplement/Implements/OperationStorage.cs @@ -1,15 +1,20 @@ -using UniversityContracts.BindingModels; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityContracts.BindingModels; using UniversityContracts.SearchModels; using UniversityContracts.StoragesContracts; using UniversityContracts.ViewModels; using UniversityDatabaseImplement.Models; -using Microsoft.EntityFrameworkCore; namespace UniversityDatabaseImplement.Implements { - public class ClassStorage : IClassStorage + public class OperationStorage : IOperationStorage { - private void CheckSearchModel(ClassSearchModel model) + private void CheckSearchModel(OperationSearchModel model) { if (model == null) throw new ArgumentNullException("Передаваемая модель для поиска равна нулю", nameof(model)); @@ -17,20 +22,20 @@ namespace UniversityDatabaseImplement.Implements throw new ArgumentException("Все передаваемые поля поисковой модели оказались пусты или равны null"); } - public ClassViewModel? Delete(ClassBindingModel model) + public OperationViewModel? Delete(OperationBindingModel model) { using var context = new UniversityDB(); - var element = context.Classes.FirstOrDefault(x => x.Id == model.Id); + var element = context.Operations.FirstOrDefault(x => x.Id == model.Id); if (element != null) { - context.Classes.Remove(element); + context.Operations.Remove(element); context.SaveChanges(); return element.GetViewModel; } return null; } - public ClassViewModel? GetElement(ClassSearchModel model) + public OperationViewModel? GetElement(OperationSearchModel model) { CheckSearchModel(model); if (!model.Id.HasValue) @@ -38,12 +43,12 @@ namespace UniversityDatabaseImplement.Implements return null; } using var context = new UniversityDB(); - return context.Classes + return context.Operations .Include(x => x.Employee) .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel; } - public List GetFilteredList(ClassSearchModel model) + public List GetFilteredList(OperationSearchModel model) { CheckSearchModel(model); if (model.Id.HasValue) @@ -53,7 +58,7 @@ namespace UniversityDatabaseImplement.Implements } using var context = new UniversityDB(); - var query = context.Classes.Include(x => x.Employee); + var query = context.Operations.Include(x => x.Employee); if (model.EmployeeId.HasValue) { @@ -74,31 +79,31 @@ namespace UniversityDatabaseImplement.Implements return new(); } - public List GetFullList() + public List GetFullList() { using var context = new UniversityDB(); - return context.Classes.Include(x => x.Employee) + return context.Operations.Include(x => x.Employee) .Select(x => x.GetViewModel) .ToList(); } - public ClassViewModel? Insert(ClassBindingModel model) + public OperationViewModel? Insert(OperationBindingModel model) { - var newOperation = Class.Create(model); + var newOperation = Operation.Create(model); if (newOperation == null) { return null; } using var context = new UniversityDB(); - context.Classes.Add(newOperation); + context.Operations.Add(newOperation); context.SaveChanges(); return newOperation.GetViewModel; } - public ClassViewModel? Update(ClassBindingModel model) + public OperationViewModel? Update(OperationBindingModel model) { using var context = new UniversityDB(); - var car = context.Classes.FirstOrDefault(x => x.Id == model.Id); + var car = context.Operations.FirstOrDefault(x => x.Id == model.Id); if (car == null) { return null; @@ -108,4 +113,5 @@ namespace UniversityDatabaseImplement.Implements return car.GetViewModel; } } + } diff --git a/University/UniversityDatabaseImplement/Implements/PaymentStorage.cs b/University/UniversityDatabaseImplement/Implements/PaymentStorage.cs index de0324f..8991329 100644 --- a/University/UniversityDatabaseImplement/Implements/PaymentStorage.cs +++ b/University/UniversityDatabaseImplement/Implements/PaymentStorage.cs @@ -11,8 +11,8 @@ namespace UniversityDatabaseImplement.Implements { public class PaymentStorage : IPaymentStorage { - private static IIncludableQueryable Payments(UniversityDB context) - => context.Payments.Include(x => x.ClassByPurchase).ThenInclude(x => x.Class); + private static IIncludableQueryable Payments(UniversityDB context) + => context.Payments.Include(x => x.OperationByPurchase).ThenInclude(x => x.Operation); public List GetFullList() { @@ -32,9 +32,9 @@ namespace UniversityDatabaseImplement.Implements { throw new ArgumentException("Получена поисковая модель только с началом или концом периода"); } - if (!model.DateFrom.HasValue && !model.ClassId.HasValue) + if (!model.DateFrom.HasValue && !model.OperationId.HasValue) { - throw new ArgumentNullException(nameof(model.ClassId), "Получена поисковая модель без OperationId"); + throw new ArgumentNullException(nameof(model.OperationId), "Получена поисковая модель без OperationId"); } if (!model.DateFrom.HasValue && !model.PurchaseId.HasValue) @@ -44,14 +44,14 @@ namespace UniversityDatabaseImplement.Implements using var context = new UniversityDB(); if (model.DateFrom.HasValue) return Payments(context) - .Where(x => x.DateCreate >= model.DateFrom.Value && x.DateCreate <= model.DateTo.Value) - .Select(x => x.GetViewModel) - .ToList(); + .Where(x => model.DateFrom.Value <= x.Date && x.Date <= model.DateTo.Value) + .Select(x => x.GetViewModel) + .ToList(); return Payments(context) - .Where(x => x.ClassByPurchase != null && - x.ClassByPurchase.ClassId == model.ClassId && - x.ClassByPurchase.PurchaseId == model.PurchaseId) + .Where(x => x.OperationByPurchase != null && + x.OperationByPurchase.OperationId == model.OperationId && + x.OperationByPurchase.PurchaseId == model.PurchaseId) .Select(x => x.GetViewModel) .ToList(); } diff --git a/University/UniversityDatabaseImplement/Implements/PurchaseStorage.cs b/University/UniversityDatabaseImplement/Implements/PurchaseStorage.cs index a2159c0..01bbb12 100644 --- a/University/UniversityDatabaseImplement/Implements/PurchaseStorage.cs +++ b/University/UniversityDatabaseImplement/Implements/PurchaseStorage.cs @@ -15,7 +15,7 @@ namespace UniversityDatabaseImplement.Implements { if (model == null) throw new ArgumentNullException("Передаваемая модель для поиска равна нулю", nameof(model)); - if (!model.Id.HasValue && !model.ClientId.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && model.ClassesIds == null) + if (!model.Id.HasValue && !model.ClientId.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && model.OperationsIds == null) throw new ArgumentException("Все передаваемые поля поисковой модели оказались пусты или равны null"); if (model.DateFrom.HasValue != model.DateTo.HasValue) throw new ArgumentException($"Не указано начало {model.DateFrom} или конец {model.DateTo} периода для поиска по дате."); @@ -34,7 +34,7 @@ namespace UniversityDatabaseImplement.Implements } - public List GetPaymentsFromPurchaseAndOperation(PurchaseSearchModel modelPurchase, ClassSearchModel modelOperation) + public List GetPaymentsFromPurchaseAndOperation(PurchaseSearchModel modelPurchase, OperationSearchModel modelOperation) { if (!modelPurchase.Id.HasValue) { @@ -45,9 +45,9 @@ namespace UniversityDatabaseImplement.Implements throw new ArgumentNullException(nameof(modelOperation), "Получена поисковая модель без Id"); } using var context = new UniversityDB(); - var carByPurchase = context.ClassByPurchases + var carByPurchase = context.OperationByPurchases .Include(x => x.Payments) - .FirstOrDefault(x => x.ClassId == modelOperation.Id && x.PurchaseId == modelPurchase.Id); + .FirstOrDefault(x => x.OperationId == modelOperation.Id && x.PurchaseId == modelPurchase.Id); if (carByPurchase?.Payments == null) { throw new InvalidOperationException( @@ -94,16 +94,16 @@ namespace UniversityDatabaseImplement.Implements if (model.DateTo.HasValue) resultQuery = query .Include(x => x.Operations) - .ThenInclude(x => x.Class) + .ThenInclude(x => x.Operation) .Include(x => x.Costs)! .ThenInclude(x => x.Cost) .Where(x => model.DateFrom <= x.DatePurchase && x.DatePurchase <= model.DateTo); - else if (model.ClassesIds != null) + else if (model.OperationsIds != null) resultQuery = query - .Where(x => x.Operations.Any(x => model.ClassesIds.Contains(x.ClassId))) + .Where(x => x.Operations.Any(x => model.OperationsIds.Contains(x.OperationId))) .Include(x => x.Operations) - .ThenInclude(x => x.Class); + .ThenInclude(x => x.Operation); return resultQuery? .Select(x => x.GetViewModel) @@ -149,4 +149,5 @@ namespace UniversityDatabaseImplement.Implements return purchase.GetViewModel; } } + } diff --git a/University/UniversityDatabaseImplement/Migrations/20240530182928_InitialCreate.Designer.cs b/University/UniversityDatabaseImplement/Migrations/20240530182928_InitialCreate.Designer.cs new file mode 100644 index 0000000..b783cf6 --- /dev/null +++ b/University/UniversityDatabaseImplement/Migrations/20240530182928_InitialCreate.Designer.cs @@ -0,0 +1,376 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using UniversityDatabaseImplement; + +#nullable disable + +namespace UniversityDatabaseImplement.Migrations +{ + [DbContext(typeof(UniversityDB))] + [Migration("20240530182928_InitialCreate")] + partial class InitialCreate + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("text"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("text"); + + b.Property("MiddleName") + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("PhoneNumber") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Cost", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("EmployeeId") + .HasColumnType("integer"); + + b.Property("NameOfCost") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.HasIndex("EmployeeId"); + + b.ToTable("Costs"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.CostByPurchase", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CostId") + .HasColumnType("integer"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("PurchaseId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CostId"); + + b.HasIndex("PurchaseId"); + + b.ToTable("CostByPurchases"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Employee", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("text"); + + b.Property("MiddleName") + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("PhoneNumber") + .IsRequired() + .HasColumnType("text"); + + b.Property("Post") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Employees"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Operation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("EmployeeId") + .HasColumnType("integer"); + + b.Property("Mark") + .IsRequired() + .HasColumnType("text"); + + b.Property("Model") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.HasIndex("EmployeeId"); + + b.ToTable("Operations"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.OperationByPurchase", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CountOperations") + .HasColumnType("integer"); + + b.Property("OperationId") + .HasColumnType("integer"); + + b.Property("PurchaseId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("OperationId"); + + b.HasIndex("PurchaseId"); + + b.ToTable("OperationByPurchases"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Payment", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("date"); + + b.Property("OperationByPurchaseId") + .HasColumnType("integer"); + + b.Property("PaidPrice") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.HasIndex("OperationByPurchaseId"); + + b.ToTable("Payments"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Purchase", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("integer"); + + b.Property("DatePurchase") + .HasColumnType("date"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.ToTable("Purchases"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Cost", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Employee", "Employee") + .WithMany("Costs") + .HasForeignKey("EmployeeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Employee"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.CostByPurchase", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Cost", "Cost") + .WithMany("Purchases") + .HasForeignKey("CostId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDatabaseImplement.Models.Purchase", "Purchase") + .WithMany("Costs") + .HasForeignKey("PurchaseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Cost"); + + b.Navigation("Purchase"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Operation", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Employee", "Employee") + .WithMany("Operations") + .HasForeignKey("EmployeeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Employee"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.OperationByPurchase", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Operation", "Operation") + .WithMany("Purchases") + .HasForeignKey("OperationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDatabaseImplement.Models.Purchase", "Purchase") + .WithMany("Operations") + .HasForeignKey("PurchaseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Operation"); + + b.Navigation("Purchase"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Payment", b => + { + b.HasOne("UniversityDatabaseImplement.Models.OperationByPurchase", "OperationByPurchase") + .WithMany("Payments") + .HasForeignKey("OperationByPurchaseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("OperationByPurchase"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Purchase", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Client", "Client") + .WithMany("Purchases") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Client", b => + { + b.Navigation("Purchases"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Cost", b => + { + b.Navigation("Purchases"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Employee", b => + { + b.Navigation("Costs"); + + b.Navigation("Operations"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Operation", b => + { + b.Navigation("Purchases"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.OperationByPurchase", b => + { + b.Navigation("Payments"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Purchase", b => + { + b.Navigation("Costs"); + + b.Navigation("Operations"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/University/UniversityDatabaseImplement/Migrations/20240530182928_InitialCreate.cs b/University/UniversityDatabaseImplement/Migrations/20240530182928_InitialCreate.cs new file mode 100644 index 0000000..d9384c2 --- /dev/null +++ b/University/UniversityDatabaseImplement/Migrations/20240530182928_InitialCreate.cs @@ -0,0 +1,257 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace UniversityDatabaseImplement.Migrations +{ + public partial class InitialCreate : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Clients", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + FirstName = table.Column(type: "text", nullable: false), + LastName = table.Column(type: "text", nullable: false), + MiddleName = table.Column(type: "text", nullable: true), + Address = table.Column(type: "text", nullable: false), + PhoneNumber = table.Column(type: "text", nullable: false), + Email = table.Column(type: "text", nullable: false), + Password = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Clients", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Employees", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + FirstName = table.Column(type: "text", nullable: false), + LastName = table.Column(type: "text", nullable: false), + MiddleName = table.Column(type: "text", nullable: true), + Post = table.Column(type: "text", nullable: false), + PhoneNumber = table.Column(type: "text", nullable: false), + Password = table.Column(type: "text", nullable: false), + Email = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Employees", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Purchases", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + ClientId = table.Column(type: "integer", nullable: false), + DatePurchase = table.Column(type: "date", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Purchases", x => x.Id); + table.ForeignKey( + name: "FK_Purchases_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Costs", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + EmployeeId = table.Column(type: "integer", nullable: false), + NameOfCost = table.Column(type: "text", nullable: false), + Price = table.Column(type: "double precision", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Costs", x => x.Id); + table.ForeignKey( + name: "FK_Costs_Employees_EmployeeId", + column: x => x.EmployeeId, + principalTable: "Employees", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Operations", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + EmployeeId = table.Column(type: "integer", nullable: false), + Model = table.Column(type: "text", nullable: false), + Price = table.Column(type: "double precision", nullable: false), + Mark = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Operations", x => x.Id); + table.ForeignKey( + name: "FK_Operations_Employees_EmployeeId", + column: x => x.EmployeeId, + principalTable: "Employees", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "CostByPurchases", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + CostId = table.Column(type: "integer", nullable: false), + PurchaseId = table.Column(type: "integer", nullable: false), + Count = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CostByPurchases", x => x.Id); + table.ForeignKey( + name: "FK_CostByPurchases_Costs_CostId", + column: x => x.CostId, + principalTable: "Costs", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_CostByPurchases_Purchases_PurchaseId", + column: x => x.PurchaseId, + principalTable: "Purchases", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "OperationByPurchases", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + OperationId = table.Column(type: "integer", nullable: false), + PurchaseId = table.Column(type: "integer", nullable: false), + CountOperations = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_OperationByPurchases", x => x.Id); + table.ForeignKey( + name: "FK_OperationByPurchases_Operations_OperationId", + column: x => x.OperationId, + principalTable: "Operations", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_OperationByPurchases_Purchases_PurchaseId", + column: x => x.PurchaseId, + principalTable: "Purchases", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Payments", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + OperationByPurchaseId = table.Column(type: "integer", nullable: false), + Date = table.Column(type: "date", nullable: false), + PaidPrice = table.Column(type: "double precision", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Payments", x => x.Id); + table.ForeignKey( + name: "FK_Payments_OperationByPurchases_OperationByPurchaseId", + column: x => x.OperationByPurchaseId, + principalTable: "OperationByPurchases", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_CostByPurchases_CostId", + table: "CostByPurchases", + column: "CostId"); + + migrationBuilder.CreateIndex( + name: "IX_CostByPurchases_PurchaseId", + table: "CostByPurchases", + column: "PurchaseId"); + + migrationBuilder.CreateIndex( + name: "IX_Costs_EmployeeId", + table: "Costs", + column: "EmployeeId"); + + migrationBuilder.CreateIndex( + name: "IX_OperationByPurchases_OperationId", + table: "OperationByPurchases", + column: "OperationId"); + + migrationBuilder.CreateIndex( + name: "IX_OperationByPurchases_PurchaseId", + table: "OperationByPurchases", + column: "PurchaseId"); + + migrationBuilder.CreateIndex( + name: "IX_Operations_EmployeeId", + table: "Operations", + column: "EmployeeId"); + + migrationBuilder.CreateIndex( + name: "IX_Payments_OperationByPurchaseId", + table: "Payments", + column: "OperationByPurchaseId"); + + migrationBuilder.CreateIndex( + name: "IX_Purchases_ClientId", + table: "Purchases", + column: "ClientId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "CostByPurchases"); + + migrationBuilder.DropTable( + name: "Payments"); + + migrationBuilder.DropTable( + name: "Costs"); + + migrationBuilder.DropTable( + name: "OperationByPurchases"); + + migrationBuilder.DropTable( + name: "Operations"); + + migrationBuilder.DropTable( + name: "Purchases"); + + migrationBuilder.DropTable( + name: "Employees"); + + migrationBuilder.DropTable( + name: "Clients"); + } + } +} diff --git a/University/UniversityDatabaseImplement/Migrations/UniversityDBModelSnapshot.cs b/University/UniversityDatabaseImplement/Migrations/UniversityDBModelSnapshot.cs new file mode 100644 index 0000000..b1a841b --- /dev/null +++ b/University/UniversityDatabaseImplement/Migrations/UniversityDBModelSnapshot.cs @@ -0,0 +1,374 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using UniversityDatabaseImplement; + +#nullable disable + +namespace UniversityDatabaseImplement.Migrations +{ + [DbContext(typeof(UniversityDB))] + partial class UniversityDBModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("text"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("text"); + + b.Property("MiddleName") + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("PhoneNumber") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Cost", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("EmployeeId") + .HasColumnType("integer"); + + b.Property("NameOfCost") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.HasIndex("EmployeeId"); + + b.ToTable("Costs"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.CostByPurchase", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CostId") + .HasColumnType("integer"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("PurchaseId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CostId"); + + b.HasIndex("PurchaseId"); + + b.ToTable("CostByPurchases"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Employee", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("text"); + + b.Property("MiddleName") + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("PhoneNumber") + .IsRequired() + .HasColumnType("text"); + + b.Property("Post") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Employees"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Operation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("EmployeeId") + .HasColumnType("integer"); + + b.Property("Mark") + .IsRequired() + .HasColumnType("text"); + + b.Property("Model") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.HasIndex("EmployeeId"); + + b.ToTable("Operations"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.OperationByPurchase", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CountOperations") + .HasColumnType("integer"); + + b.Property("OperationId") + .HasColumnType("integer"); + + b.Property("PurchaseId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("OperationId"); + + b.HasIndex("PurchaseId"); + + b.ToTable("OperationByPurchases"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Payment", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("date"); + + b.Property("OperationByPurchaseId") + .HasColumnType("integer"); + + b.Property("PaidPrice") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.HasIndex("OperationByPurchaseId"); + + b.ToTable("Payments"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Purchase", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("integer"); + + b.Property("DatePurchase") + .HasColumnType("date"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.ToTable("Purchases"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Cost", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Employee", "Employee") + .WithMany("Costs") + .HasForeignKey("EmployeeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Employee"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.CostByPurchase", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Cost", "Cost") + .WithMany("Purchases") + .HasForeignKey("CostId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDatabaseImplement.Models.Purchase", "Purchase") + .WithMany("Costs") + .HasForeignKey("PurchaseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Cost"); + + b.Navigation("Purchase"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Operation", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Employee", "Employee") + .WithMany("Operations") + .HasForeignKey("EmployeeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Employee"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.OperationByPurchase", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Operation", "Operation") + .WithMany("Purchases") + .HasForeignKey("OperationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDatabaseImplement.Models.Purchase", "Purchase") + .WithMany("Operations") + .HasForeignKey("PurchaseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Operation"); + + b.Navigation("Purchase"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Payment", b => + { + b.HasOne("UniversityDatabaseImplement.Models.OperationByPurchase", "OperationByPurchase") + .WithMany("Payments") + .HasForeignKey("OperationByPurchaseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("OperationByPurchase"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Purchase", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Client", "Client") + .WithMany("Purchases") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Client", b => + { + b.Navigation("Purchases"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Cost", b => + { + b.Navigation("Purchases"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Employee", b => + { + b.Navigation("Costs"); + + b.Navigation("Operations"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Operation", b => + { + b.Navigation("Purchases"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.OperationByPurchase", b => + { + b.Navigation("Payments"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Purchase", b => + { + b.Navigation("Costs"); + + b.Navigation("Operations"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/University/UniversityDatabaseImplement/Models/CarByPurchase.cs b/University/UniversityDatabaseImplement/Models/CarByPurchase.cs deleted file mode 100644 index 87973c0..0000000 --- a/University/UniversityDatabaseImplement/Models/CarByPurchase.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using UniversityDataModels.Models; - - -namespace UniversityDatabaseImplement.Models -{ - public class ClassByPurchase : ClassByPurchaseModel - { - [Required] - public Class? Class { get; private set; } - [Required] - public Purchase? Purchase { get; private set; } - [Required] - public List? Payments { get; private set; } - } -} \ No newline at end of file diff --git a/University/UniversityDatabaseImplement/Models/Class.cs b/University/UniversityDatabaseImplement/Models/Class.cs deleted file mode 100644 index 6c603db..0000000 --- a/University/UniversityDatabaseImplement/Models/Class.cs +++ /dev/null @@ -1,61 +0,0 @@ -using UniversityContracts.BindingModels; -using UniversityContracts.SearchModels; -using UniversityContracts.ViewModels; -using UniversityDatabaseImplement.Implements; -using UniversityDataModels; -using System.ComponentModel; -using System.ComponentModel.DataAnnotations; - -namespace UniversityDatabaseImplement.Models -{ - public class Class : IClassModel - { - [Required] - public int EmployeeId { get; private set; } - [Required] - public string Name { get; private set; } = string.Empty; - [Required] - public double Price { get; private set; } - [Required] - public string Time { get; private set; } = string.Empty; - - public int Id { get; private set; } - [Required] - public Employee? Employee { get; private set; } - - [Required] - public List Purchases { get; private set; } = new(); - - public static Class Create(ClassBindingModel model) - { - if (model == null) - { - return null; - } - return new Class() - { - EmployeeId = model.EmployeeId, - Name = model.Name, - Price = model.Price, - Time = model.Time, - Id = model.Id, - }; - } - - public ClassViewModel GetViewModel => new() - { - EmployeeLogin = Employee?.Login??string.Empty, - EmployeeId = EmployeeId, - Name = Name, - Price = Price, - Time = Time, - Id = Id, - Purchases = Purchases.Select(x=>x.Purchase?.GetViewModel2).ToList(), - }; - - public void Update(ClassBindingModel model) - { - Price = model.Price; - } - } -} diff --git a/University/UniversityDatabaseImplement/Models/Client.cs b/University/UniversityDatabaseImplement/Models/Client.cs index 8609ce7..794a982 100644 --- a/University/UniversityDatabaseImplement/Models/Client.cs +++ b/University/UniversityDatabaseImplement/Models/Client.cs @@ -17,26 +17,26 @@ namespace UniversityDatabaseImplement.Models [Required] public string Address { get; private set; } = string.Empty; [Required] - public string Login { get; private set; } = string.Empty; + public string PhoneNumber { get; private set; } = string.Empty; [Required] public string Email { get; set; } = string.Empty; [Required] public string Password { get; private set; } = string.Empty; - [Required] + [Required] public List? Purchases { get; private set; } public static Client Create(ClientBindingModel model) { - if (model == null) - { - return null; - } - return new Client() + if (model == null) + { + return null; + } + return new Client() { FirstName = model.FirstName, LastName = model.LastName, MiddleName = model.MiddleName, - Login = model.Login, + PhoneNumber = model.PhoneNumber, Password = model.Password, Id = model.Id, Email = model.Email, @@ -48,7 +48,7 @@ namespace UniversityDatabaseImplement.Models FirstName = FirstName, LastName = LastName, MiddleName = MiddleName, - Login =Login, + PhoneNumber = PhoneNumber, Password = Password, Id = Id, Email = Email, diff --git a/University/UniversityDatabaseImplement/Models/Cost.cs b/University/UniversityDatabaseImplement/Models/Cost.cs index c2dac5a..3c2648b 100644 --- a/University/UniversityDatabaseImplement/Models/Cost.cs +++ b/University/UniversityDatabaseImplement/Models/Cost.cs @@ -2,7 +2,7 @@ using UniversityContracts.ViewModels; using UniversityDataModels; using System.ComponentModel.DataAnnotations; -using UniversityDataModels.Models; +using UniversityDataModels.ProxyModels; namespace UniversityDatabaseImplement.Models @@ -20,39 +20,40 @@ namespace UniversityDatabaseImplement.Models public Dictionary PurchasesModels => _cachedPurchases ??= Purchases.Select(x => (CostByPurchaseModel)x).ToDictionary(x => x.PurchaseId, x => x); [Required] public Employee? Employee { get; private set; } - [Required] + [Required] public List Purchases { get; private set; } = new(); public static Cost Create(CostBindingModel model) { - if (model == null) - { - return null; - } - return new Cost() - { - EmployeeId = model.EmployeeId, - NameOfCost = model.NameOfCost, - Price = model.Price, - //PurchasesModels = model.PurchasesModels, - Id = model.Id - }; - } + if (model == null) + { + return null; + } + return new Cost() + { + EmployeeId = model.EmployeeId, + NameOfCost = model.NameOfCost, + Price = model.Price, + //PurchasesModels = model.PurchasesModels, + Id = model.Id + }; + } public CostViewModel GetViewModel => new() { + PhoneNumber = Employee?.PhoneNumber ?? string.Empty, PurchaseModels = PurchasesModels, EmployeeId = EmployeeId, - NameOfCost = NameOfCost, - Price = Price, - Id = Id - }; + NameOfCost = NameOfCost, + Price = Price, + Id = Id + }; public void Update(CostBindingModel model) { NameOfCost = model.NameOfCost; Price = model.Price; - } + } /// /// Привязка статей затрат к покупкам @@ -69,8 +70,8 @@ namespace UniversityDatabaseImplement.Models Count = x.Value.Count, } ); - context.RemoveRange(oldPurchases.Where(x => !newPurchases.ContainsKey(x.Key)).Select(x => x.Value)); - context.AddRange (newPurchases.Where(x => !oldPurchases.ContainsKey(x.Key)).Select(x => x.Value)); + context.RemoveRange(oldPurchases.Where(x => !newPurchases.ContainsKey(x.Key)).Select(x => x.Value)); + context.AddRange(newPurchases.Where(x => !oldPurchases.ContainsKey(x.Key)).Select(x => x.Value)); oldPurchases.Where(x => newPurchases.ContainsKey(x.Key)) .Select(x => x.Value).ToList() .ForEach(x => x.Count = newPurchases[x.PurchaseId].Count); diff --git a/University/UniversityDatabaseImplement/Models/CostByPurchase.cs b/University/UniversityDatabaseImplement/Models/CostByPurchase.cs index 5533b60..a213d9e 100644 --- a/University/UniversityDatabaseImplement/Models/CostByPurchase.cs +++ b/University/UniversityDatabaseImplement/Models/CostByPurchase.cs @@ -1,5 +1,5 @@ using System.ComponentModel.DataAnnotations; -using UniversityDataModels.Models; +using UniversityDataModels.ProxyModels; namespace UniversityDatabaseImplement.Models @@ -10,5 +10,5 @@ namespace UniversityDatabaseImplement.Models public Cost? Cost { get; private set; } [Required] public Purchase? Purchase { get; private set; } - } + } } diff --git a/University/UniversityDatabaseImplement/Models/Employee.cs b/University/UniversityDatabaseImplement/Models/Employee.cs index 4a17d66..dbc121e 100644 --- a/University/UniversityDatabaseImplement/Models/Employee.cs +++ b/University/UniversityDatabaseImplement/Models/Employee.cs @@ -16,41 +16,45 @@ namespace UniversityDatabaseImplement.Models [Required] public string Post { get; private set; } = string.Empty; [Required] - public string Login { get; private set; } = string.Empty; + public string PhoneNumber { get; private set; } = string.Empty; [Required] public string Password { get; private set; } = string.Empty; [Required] public string Email { get; set; } = string.Empty; [Required] - public List? Class { get; private set; } + public List? Operations { get; private set; } [Required] public List? Costs { get; private set; } public static Employee Create(EmployeeBindingModel model) { - if (model == null) - { - return null; - } - return new Employee() - { - FirstName = model.FirstName, - LastName = model.LastName, - MiddleName = model.MiddleName, - Password = model.Password, - Id = model.Id, + if (model == null) + { + return null; + } + return new Employee() + { + FirstName = model.FirstName, + LastName = model.LastName, + MiddleName = model.MiddleName, + PhoneNumber = model.PhoneNumber, + Password = model.Password, + Id = model.Id, Post = model.Post, - }; - } + Email = model.Email, + }; + } - public EmployeeViewModel GetViewModel => new() - { - FirstName = FirstName, - LastName = LastName, - MiddleName = MiddleName, - Password = Password, - Id = Id, - Post = Post, - }; - } + public EmployeeViewModel GetViewModel => new() + { + FirstName = FirstName, + LastName = LastName, + MiddleName = MiddleName, + PhoneNumber = PhoneNumber, + Password = Password, + Id = Id, + Post = Post, + Email = Email, + }; + } } \ No newline at end of file diff --git a/University/UniversityDatabaseImplement/Models/Operation.cs b/University/UniversityDatabaseImplement/Models/Operation.cs new file mode 100644 index 0000000..c3d0498 --- /dev/null +++ b/University/UniversityDatabaseImplement/Models/Operation.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityContracts.BindingModels; +using UniversityContracts.ViewModels; +using UniversityDataModels; + +namespace UniversityDatabaseImplement.Models +{ + public class Operation : IOperationModel + { + [Required] + public int EmployeeId { get; private set; } + [Required] + public string Model { get; private set; } = string.Empty; + [Required] + public double Price { get; private set; } + [Required] + public string Mark { get; private set; } = string.Empty; + + public int Id { get; private set; } + [Required] + public Employee? Employee { get; private set; } + + [Required] + public List Purchases { get; private set; } = new(); + + public static Operation Create(OperationBindingModel model) + { + if (model == null) + { + return null; + } + return new Operation() + { + EmployeeId = model.EmployeeId, + Model = model.Model, + Price = model.Price, + Mark = model.Mark, + Id = model.Id, + }; + } + + public OperationViewModel GetViewModel => new() + { + EmployeePhoneNumber = Employee?.PhoneNumber ?? string.Empty, + EmployeeId = EmployeeId, + Model = Model, + Price = Price, + Mark = Mark, + Id = Id, + Purchases = Purchases.Select(x => x.Purchase?.GetViewModel2).ToList(), + }; + + public void Update(OperationBindingModel model) + { + Price = model.Price; + } + } + +} diff --git a/University/UniversityDatabaseImplement/Models/OperationByPurchase.cs b/University/UniversityDatabaseImplement/Models/OperationByPurchase.cs new file mode 100644 index 0000000..c3307d6 --- /dev/null +++ b/University/UniversityDatabaseImplement/Models/OperationByPurchase.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityDataModels.ProxyModels; + +namespace UniversityDatabaseImplement.Models +{ + public class OperationByPurchase : OperationByPurchaseModel + { + [Required] + public Operation? Operation { get; private set; } + [Required] + public Purchase? Purchase { get; private set; } + [Required] + public List? Payments { get; private set; } + } +} diff --git a/University/UniversityDatabaseImplement/Models/Payment.cs b/University/UniversityDatabaseImplement/Models/Payment.cs index 24357cd..e991fe7 100644 --- a/University/UniversityDatabaseImplement/Models/Payment.cs +++ b/University/UniversityDatabaseImplement/Models/Payment.cs @@ -10,10 +10,10 @@ namespace UniversityDatabaseImplement.Models public class Payment : IPaymentModel { [Required] - public int ClassByPurchaseId { get; private set; } + public int OperationByPurchaseId { get; private set; } [Required] - public DateTime DateCreate { get; private set; } + public DateOnly Date { get; private set; } [Required] public double PaidPrice { get; private set; } @@ -21,32 +21,32 @@ namespace UniversityDatabaseImplement.Models public int Id { get; private set; } [Required] - public ClassByPurchase? ClassByPurchase { get; private set; } + public OperationByPurchase? OperationByPurchase { get; private set; } public static Payment Create(PaymentBindingModel model) { - if (model == null) - { - return null; - } + if (model == null) + { + return null; + } return new Payment() { - DateCreate = model.DateCreate, + Date = model.Date, PaidPrice = model.PaidPrice, - Id = model.Id, - ClassByPurchaseId = model.ClassByPurchaseId, - }; - } - public PaymentViewModel GetViewModel => new() - { - Operation = ClassByPurchase?.Class?.GetViewModel, - ClassByPurchase = ClassByPurchase, - FullPrice = ClassByPurchase?.Class?.Price ?? -1, - DateCreate = DateCreate, + Id = model.Id, + OperationByPurchaseId = model.OperationByPurchaseId, + }; + } + public PaymentViewModel GetViewModel => new() + { + Operation = OperationByPurchase?.Operation?.GetViewModel, + OperationByPurchase = OperationByPurchase, + FullPrice = OperationByPurchase?.Operation?.Price ?? -1, + Date = Date, PaidPrice = PaidPrice, - Id = Id, - ClassByPurchaseId = ClassByPurchaseId, - }; - } + Id = Id, + OperationByPurchaseId = OperationByPurchaseId, + }; + } } diff --git a/University/UniversityDatabaseImplement/Models/Purchase.cs b/University/UniversityDatabaseImplement/Models/Purchase.cs index 7c7932c..4f81447 100644 --- a/University/UniversityDatabaseImplement/Models/Purchase.cs +++ b/University/UniversityDatabaseImplement/Models/Purchase.cs @@ -4,7 +4,7 @@ using UniversityDataModels; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq.Expressions; -using UniversityDataModels.Models; +using UniversityDataModels.ProxyModels; namespace UniversityDatabaseImplement.Models @@ -13,17 +13,17 @@ namespace UniversityDatabaseImplement.Models { public int ClientId { get; private set; } public DateOnly DatePurchase { get; private set; } - private Dictionary? _cachedClasses; + private Dictionary? _cachedOperations; [NotMapped] - public Dictionary ClassModel => _cachedClasses ??=Operations.Select(x => (ClassByPurchaseModel)x).ToDictionary(x => x.ClassId, x => x); + public Dictionary OperationsModel => _cachedOperations ??= Operations.Select(x => (OperationByPurchaseModel)x).ToDictionary(x => x.OperationId, x => x); [NotMapped] public List? CostsModel => null; public int Id { get; private set; } - [Required] + [Required] public Client? Client { get; private set; } - [Required] - public List Operations { get; private set; } = new(); - [Required] + [Required] + public List Operations { get; private set; } = new(); + [Required] public List Costs { get; private set; } = new(); public static Purchase Create(PurchaseBindingModel model) @@ -34,36 +34,36 @@ namespace UniversityDatabaseImplement.Models Id = model.Id, DatePurchase = model.DatePurchase, - }; + }; } - public void Update(PurchaseBindingModel model) - { + public void Update(PurchaseBindingModel model) + { DatePurchase = model.DatePurchase; - } + } public PurchaseViewModel GetViewModel => new() { - ClassModel = ClassModel, + OperationsModel = OperationsModel, Id = Id, DatePurchase = DatePurchase, ClientId = ClientId, - ClientLogin = Client?.Login ?? string.Empty, + ClientPhoneNumber = Client?.PhoneNumber ?? string.Empty, CostViewModels = Costs? .Select(x => x.Cost.GetViewModel) .ToList() ?? new(), - ClassViewModels = Operations? - .Select(x => x.Class?.GetViewModel) + OperationViewModels = Operations? + .Select(x => x.Operation?.GetViewModel) .ToList() ?? new() }; public PurchaseViewModel GetViewModel2 => new() { - ClassModel = ClassModel, + OperationsModel = OperationsModel, Id = Id, DatePurchase = DatePurchase, ClientId = ClientId, - ClientLogin = Client?.Login ?? string.Empty, + ClientPhoneNumber = Client?.PhoneNumber ?? string.Empty, CostViewModels = Costs? .Select(x => x.Cost.GetViewModel) @@ -72,25 +72,25 @@ namespace UniversityDatabaseImplement.Models public void UpdateOperations(UniversityDB context, PurchaseBindingModel model) { - var oldOperations = context.ClassByPurchases.Where(x => x.PurchaseId == model.Id).ToDictionary(x => x.ClassId, x => x); - var newOperations = model.ClassModel.ToDictionary( + var oldOperations = context.OperationByPurchases.Where(x => x.PurchaseId == model.Id).ToDictionary(x => x.OperationId, x => x); + var newOperations = model.OperationsModel.ToDictionary( x => x.Key, - x => new ClassByPurchase() - { - ClassId = x.Key, - PurchaseId = Id, - CountClass = x.Value.CountClass - } + x => new OperationByPurchase() + { + OperationId = x.Key, + PurchaseId = Id, + CountOperations = x.Value.CountOperations + } ); - + context.RemoveRange(oldOperations.Where(x => !newOperations.ContainsKey(x.Key)).Select(x => x.Value)); - context.AddRange (newOperations.Where(x => !oldOperations.ContainsKey(x.Key)).Select(x => x.Value)); - oldOperations - .Where(x => newOperations.ContainsKey(x.Key)) - .Select(x => x.Value).ToList() - .ForEach(x => x.CountClass = newOperations[x.ClassId].CountClass); - context.SaveChanges(); - _cachedClasses = null; + context.AddRange(newOperations.Where(x => !oldOperations.ContainsKey(x.Key)).Select(x => x.Value)); + oldOperations + .Where(x => newOperations.ContainsKey(x.Key)) + .Select(x => x.Value).ToList() + .ForEach(x => x.CountOperations = newOperations[x.OperationId].CountOperations); + context.SaveChanges(); + _cachedOperations = null; } } } diff --git a/University/UniversityDatabaseImplement/UniversityDB.cs b/University/UniversityDatabaseImplement/UniversityDB.cs index 172e5b2..eaa6fc7 100644 --- a/University/UniversityDatabaseImplement/UniversityDB.cs +++ b/University/UniversityDatabaseImplement/UniversityDB.cs @@ -11,7 +11,12 @@ namespace UniversityDatabaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=University;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseNpgsql(@" + Host=localhost; + Port=5432; + Database=UniversityFullNew; + Username=postgres; + Password=55256636a;"); } base.OnConfiguring(optionsBuilder); } @@ -20,8 +25,8 @@ namespace UniversityDatabaseImplement public virtual DbSet Costs { set; get; } public virtual DbSet CostByPurchases { set; get; } public virtual DbSet Employees { set; get; } - public virtual DbSet Classes { set; get; } - public virtual DbSet ClassByPurchases { set; get; } + public virtual DbSet Operations { set; get; } + public virtual DbSet OperationByPurchases { set; get; } public virtual DbSet Payments { set; get; } public virtual DbSet Purchases { set; get; } } diff --git a/University/UniversityDatabaseImplement/UniversityDatabaseImplement.csproj b/University/UniversityDatabaseImplement/UniversityDatabaseImplement.csproj index 3e242d3..8c78b7b 100644 --- a/University/UniversityDatabaseImplement/UniversityDatabaseImplement.csproj +++ b/University/UniversityDatabaseImplement/UniversityDatabaseImplement.csproj @@ -12,13 +12,10 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - all runtime; build; native; contentfiles; analyzers; buildtransitive - - diff --git a/University/UniversityEmpoyeeApp/Program.cs b/University/UniversityEmpoyeeApp/Program.cs index 4497a85..cd892b8 100644 --- a/University/UniversityEmpoyeeApp/Program.cs +++ b/University/UniversityEmpoyeeApp/Program.cs @@ -15,7 +15,7 @@ builder.Services.AddControllersWithViews(); builder.Services.AddSession(); // builder.Services.AddTransient(); -builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); @@ -26,7 +26,7 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); -builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); diff --git a/University/UniversityEmpoyeeApp/UniversityEmpoyeeApp.csproj b/University/UniversityEmpoyeeApp/UniversityEmpoyeeApp.csproj index 3dbb0b2..b04db2d 100644 --- a/University/UniversityEmpoyeeApp/UniversityEmpoyeeApp.csproj +++ b/University/UniversityEmpoyeeApp/UniversityEmpoyeeApp.csproj @@ -7,17 +7,10 @@ - all runtime; build; native; contentfiles; analyzers; buildtransitive - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - -