diff --git a/BussinesLogic/BusinessLogic/OrderLogic.cs b/BussinesLogic/BusinessLogic/OrderLogic.cs index 78fe795..625bd49 100644 --- a/BussinesLogic/BusinessLogic/OrderLogic.cs +++ b/BussinesLogic/BusinessLogic/OrderLogic.cs @@ -7,18 +7,18 @@ using Microsoft.Extensions.Logging; namespace BusinessLogics.BusinessLogic { - public class OrderLogic : ICostLogic + public class OrderLogic : IOrderLogic { private readonly ILogger _logger; - private readonly ICostStorage _costStorage; + private readonly IOrderStorage _orderStorage; - public OrderLogic(ILogger logger, ICostStorage costStorage) + public OrderLogic(ILogger logger, IOrderStorage orderStorage) { _logger = logger; - _costStorage = costStorage; + _orderStorage = orderStorage; } - public void CheckModel(CostBindingModel model, bool checkParams = true) + public void CheckModel(OrderBindingModel model, bool checkParams = true) { if (model == null) { @@ -29,7 +29,7 @@ namespace BusinessLogics.BusinessLogic return; } - if (string.IsNullOrEmpty(model.NameOfCost)) + if (string.IsNullOrEmpty(model.NameOrder)) { throw new ArgumentNullException($"Имя затраты не должно быть пустым"); } @@ -40,12 +40,12 @@ namespace BusinessLogics.BusinessLogic } } - public bool Create(CostBindingModel model) + public bool Create(OrderBindingModel model) { try { CheckModel(model); - var result = _costStorage.Insert(model); + var result = _orderStorage.Insert(model); if (result == null) { throw new ArgumentNullException($"Затрата не создана"); @@ -60,12 +60,12 @@ namespace BusinessLogics.BusinessLogic } } - public bool Delete(CostBindingModel model) + public bool Delete(OrderBindingModel model) { try { CheckModel(model, false); - var result = _costStorage.Delete(model); + var result = _orderStorage.Delete(model); if (result == null) { throw new ArgumentNullException($"Удалить затрату не удалось"); @@ -80,11 +80,11 @@ namespace BusinessLogics.BusinessLogic } } - public CostViewModel ReadElement(CostSearchModel model) + public OrderViewModel ReadElement(OrderSearchModel model) { try { - var result = _costStorage.GetElement(model); + var result = _orderStorage.GetElement(model); if (result == null) { throw new ArgumentNullException($"Не получилось получить id {model.Id}"); @@ -99,11 +99,11 @@ namespace BusinessLogics.BusinessLogic } } - public List ReadList(CostSearchModel? model = null) + public List ReadList(OrderSearchModel? model = null) { try { - var results = model != null ? _costStorage.GetFilteredList(model) : _costStorage.GetFullList(); + var results = model != null ? _orderStorage.GetFilteredList(model) : _orderStorage.GetFullList(); _logger.LogDebug("Список полученных статей затрат {@costs}", results); _logger.LogInformation("Извлечение списка c затрат по {@CostSearchModel} модели", model); return results; @@ -115,12 +115,12 @@ namespace BusinessLogics.BusinessLogic } } - public bool Update(CostBindingModel model) + public bool Update(OrderBindingModel model) { try { //CheckModel(model); - var result = _costStorage.Update(model); + var result = _orderStorage.Update(model); if (result == null) { throw new ArgumentNullException($"Не получилось обновить затраты"); diff --git a/BussinesLogic/BussinesLogic.csproj b/BussinesLogic/BussinesLogic.csproj index 0c1d671..0a1b166 100644 --- a/BussinesLogic/BussinesLogic.csproj +++ b/BussinesLogic/BussinesLogic.csproj @@ -8,6 +8,7 @@ + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/BussinesLogic/OfficePackage/AbstractSaveToPdf.cs b/BussinesLogic/OfficePackage/AbstractSaveToPdf.cs index 02327bb..a717cdd 100644 --- a/BussinesLogic/OfficePackage/AbstractSaveToPdf.cs +++ b/BussinesLogic/OfficePackage/AbstractSaveToPdf.cs @@ -85,11 +85,11 @@ namespace BusinessLogics.OfficePackage $"ожидается Purchase; Получен объект типа: {pc.GetType()}", nameof(info)); } - if (purchase.CostViewModels == null) + if (purchase.OrderViewModels == null) { throw new ArgumentNullException($"Получена модель статьи затрат c нулевыми полями"); } - foreach (var cost in purchase.CostViewModels) + foreach (var order in purchase.OrderViewModels) { CreateRow(new PdfRowParameters { @@ -97,8 +97,8 @@ namespace BusinessLogics.OfficePackage { purchase.DatePurchase.ToShortDateString(), purchase.Id.ToString(), - cost.NameOfCost, - (cost.Price* cost.PurchaseModels[purchase.Id].Count).ToString(), + order.NameOrder, + (order.Price* order.PurchaseModels[purchase.Id].Count).ToString(), }, Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Left diff --git a/Contracts/BindingModel/PurchaseBindingModel.cs b/Contracts/BindingModel/PurchaseBindingModel.cs index def51a1..3a69a34 100644 --- a/Contracts/BindingModel/PurchaseBindingModel.cs +++ b/Contracts/BindingModel/PurchaseBindingModel.cs @@ -8,7 +8,7 @@ namespace Contracts.BindingModel public int ClientId { get; set; } public DateOnly DatePurchase { get; set; } public Dictionary OperationsModel { get; set; } = new(); - public List CostsModel { get; set; } = new(); + public List OrdersModel { get; set; } = new(); public int Id { get; set; } } diff --git a/Contracts/Contracts.csproj b/Contracts/Contracts.csproj index e78682b..ada9687 100644 --- a/Contracts/Contracts.csproj +++ b/Contracts/Contracts.csproj @@ -8,6 +8,7 @@ + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Contracts/StoragesContracts/IOrderStorage.cs b/Contracts/StoragesContracts/IOrderStorage.cs index c5071cc..58d0731 100644 --- a/Contracts/StoragesContracts/IOrderStorage.cs +++ b/Contracts/StoragesContracts/IOrderStorage.cs @@ -6,11 +6,11 @@ namespace Contracts.StoragesContracts { public interface IOrderStorage { - List GetFullList(); - List GetFilteredList(OrderSearchModel model); - CostViewModel? GetElement(OrderSearchModel model); - CostViewModel? Insert(CostBindingModel model); - CostViewModel? Update(CostBindingModel model); - CostViewModel? Delete(CostBindingModel model); + List GetFullList(); + List GetFilteredList(OrderSearchModel model); + OrderViewModel? GetElement(OrderSearchModel model); + OrderViewModel? Insert(OrderBindingModel model); + OrderViewModel? Update(OrderBindingModel model); + OrderViewModel? Delete(OrderBindingModel model); } } diff --git a/Contracts/ViewModels/OrderViewModel.cs b/Contracts/ViewModels/OrderViewModel.cs index 984cd74..775cfa6 100644 --- a/Contracts/ViewModels/OrderViewModel.cs +++ b/Contracts/ViewModels/OrderViewModel.cs @@ -15,6 +15,6 @@ namespace Contracts.ViewModels [DisplayName("Стоимость")] public double Price { get; set; } - public Dictionary PurchaseModels { get; set; } = new(); + public Dictionary PurchaseModels { get; set; } = new(); } } diff --git a/DataModel1/DataModel.csproj b/DataModel1/DataModel.csproj index 67eaa0c..111d0b7 100644 --- a/DataModel1/DataModel.csproj +++ b/DataModel1/DataModel.csproj @@ -8,6 +8,7 @@ + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/DataModel1/ProxyModels/CostByPurchaseModel.cs b/DataModel1/ProxyModels/CostByPurchaseModel.cs index 3392de8..b6bd8e9 100644 --- a/DataModel1/ProxyModels/CostByPurchaseModel.cs +++ b/DataModel1/ProxyModels/CostByPurchaseModel.cs @@ -2,10 +2,10 @@ namespace DataModels.ProxyModels { - public class CostByPurchaseModel : IId + public class OrderByPurchaseModel : IId { public virtual int Id { get; set; } - public virtual int CostId { get; set; } + public virtual int OrderId { get; set; } public virtual int PurchaseId { get; set; } public virtual int Count { get; set; } } diff --git a/DatabaseImplement/AutoShopDB.cs b/DatabaseImplement/AutoShopDB.cs index fdeed78..8ad0616 100644 --- a/DatabaseImplement/AutoShopDB.cs +++ b/DatabaseImplement/AutoShopDB.cs @@ -1,4 +1,5 @@ -using DatabaseImplement.Models; +using BankDatabaseImplement.Models; +using DatabaseImplement.Models; using Microsoft.EntityFrameworkCore; namespace DatabaseImplement @@ -20,7 +21,7 @@ namespace DatabaseImplement } public virtual DbSet Clients { set; get; } - public virtual DbSet Costs { set; get; } + public virtual DbSet Order { set; get; } public virtual DbSet OrderByPurchases { set; get; } public virtual DbSet Employees { set; get; } public virtual DbSet Operations { set; get; } diff --git a/DatabaseImplement/DatabaseImplement.csproj b/DatabaseImplement/DatabaseImplement.csproj index 0c1d671..0a1b166 100644 --- a/DatabaseImplement/DatabaseImplement.csproj +++ b/DatabaseImplement/DatabaseImplement.csproj @@ -8,6 +8,7 @@ + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/DatabaseImplement/Implements/CostStorage.cs b/DatabaseImplement/Implements/OrderStorage.cs similarity index 53% rename from DatabaseImplement/Implements/CostStorage.cs rename to DatabaseImplement/Implements/OrderStorage.cs index 778b9c4..0dea82f 100644 --- a/DatabaseImplement/Implements/CostStorage.cs +++ b/DatabaseImplement/Implements/OrderStorage.cs @@ -1,13 +1,13 @@ -using Contracts.BindingModels; +using Contracts.BindingModel; using Contracts.SearchModels; using Contracts.StoragesContracts; using Contracts.ViewModels; using DatabaseImplement.Models; using Microsoft.EntityFrameworkCore; -namespace kDatabaseImplement.Implements +namespace DatabaseImplement.Implements { - public class CostStorage : IOrderStorage + public class OrderStorage : IOrderStorage { private void CheckSearchModel(OrderSearchModel model) { @@ -16,20 +16,20 @@ namespace kDatabaseImplement.Implements if (!model.Id.HasValue && !model.EmployeeId.HasValue) throw new ArgumentException("Все передаваемые поля поисковой модели оказались пусты или равны null"); } - public CostViewModel? Delete(CostBindingModel model) + public OrderViewModel? Delete(OrderBindingModel model) { using var context = new AutoShopDB(); - var element = context.Costs.FirstOrDefault(x => x.Id == model.Id); + var element = context.Order.FirstOrDefault(x => x.Id == model.Id); if (element != null) { - context.Costs.Remove(element); + context.Order.Remove(element); context.SaveChanges(); return element.GetViewModel; } return null; } - public CostViewModel? GetElement(OrderSearchModel model) + public OrderViewModel? GetElement(OrderSearchModel model) { CheckSearchModel(model); using var context = new AutoShopDB(); @@ -37,60 +37,60 @@ namespace kDatabaseImplement.Implements { return null; } - return context.Costs - .Include(cost => cost.Employee) - .Include(cost => cost.Purchases).ThenInclude(costByPurchase => costByPurchase.Purchase) + return context.Order + .Include(Order => Order.OrderId) + .Include(Order => Order.Purchases).ThenInclude(OrderByPurchase => OrderByPurchase.Purchase) .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel; } - public List GetFilteredList(OrderSearchModel model) + public List GetFilteredList(OrderSearchModel model) { CheckSearchModel(model); using var context = new AutoShopDB(); - return context.Costs - .Include(cost => cost.Employee) - .Include(cost => cost.Purchases).ThenInclude(costByPurchase => costByPurchase.Purchase) - .Where(x => x.EmployeeId == model.EmployeeId || x.Id == model.Id) + return context.Order + .Include(order => order.OrderId) + .Include(order => order.Purchases).ThenInclude(orderByPurchase => orderByPurchase.Purchase) + .Where(x => x.OrderId == model.Id || x.Id == model.Id) .Select(x => x.GetViewModel) .ToList(); } - public List GetFullList() + public List GetFullList() { using var context = new AutoShopDB(); - return context.Costs - .Include(cost => cost.Employee) - .Include(cost => cost.Purchases).ThenInclude(costByPurchase => costByPurchase.Purchase) + return context.Order + .Include(order => order.OrderId) + .Include(order => order.Purchases).ThenInclude(orderByPurchase => orderByPurchase.Purchase) .Select(x => x.GetViewModel) .ToList(); } - public CostViewModel? Insert(CostBindingModel model) + public OrderViewModel? Insert(OrderBindingModel model) { - var newCost = Cost.Create(model); - if (newCost == null) + var newOrder = Order.Create(model); + if (newOrder == null) { return null; } using var context = new AutoShopDB(); - context.Costs.Add(newCost); + context.Order.Add(newOrder); context.SaveChanges(); - return newCost.GetViewModel; + return newOrder.GetViewModel; } - public CostViewModel? Update(CostBindingModel model) + public OrderViewModel? Update(OrderBindingModel model) { using var context = new AutoShopDB(); - var cost = context.Costs.FirstOrDefault(x => x.Id == model.Id); - if (cost == null) + var order = context.OrderByPurchases.FirstOrDefault(x => x.Id == model.Id); + if (order == null) { return null; } - cost.Update(model); + order.Update(model); context.SaveChanges(); - cost.UpdatePurchases(context, model); + order.UpdatePurchases(context, model); context.SaveChanges(); - return cost.GetViewModel; + return order.GetViewModel; } } } diff --git a/DatabaseImplement/Models/CostByPurchase.cs b/DatabaseImplement/Models/CostByPurchase.cs deleted file mode 100644 index 85386d2..0000000 --- a/DatabaseImplement/Models/CostByPurchase.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using BankDataModels.ProxyModels; - -namespace BankDatabaseImplement.Models -{ - public class CostByPurchase : CostByPurchaseModel - { - [Required] - public Order? Cost { get; private set; } - [Required] - public Purchase? Purchase { get; private set; } - } -} diff --git a/DatabaseImplement/Models/Employee.cs b/DatabaseImplement/Models/Employee.cs index 39c9eb1..9be6f30 100644 --- a/DatabaseImplement/Models/Employee.cs +++ b/DatabaseImplement/Models/Employee.cs @@ -1,6 +1,6 @@ -using BankContracts.BindingModels; -using BankContracts.ViewModels; -using BankDataModels; +using Contracts.BindingModel; +using Contracts.ViewModels; +using DataModels; using System.ComponentModel.DataAnnotations; namespace BankDatabaseImplement.Models @@ -24,7 +24,7 @@ namespace BankDatabaseImplement.Models [Required] public List? Operations { get; private set; } [Required] - public List? Costs { get; private set; } + public List? Orders { get; private set; } public static Employee Create(EmployeeBindingModel model) { diff --git a/DatabaseImplement/Models/Order.cs b/DatabaseImplement/Models/Order.cs index 7cf8d73..c08c513 100644 --- a/DatabaseImplement/Models/Order.cs +++ b/DatabaseImplement/Models/Order.cs @@ -15,10 +15,10 @@ namespace DatabaseImplement.Models public int Id { get; private set; } [Required] public double Price { get; private set; } - private Dictionary? _cachedPurchases; - public Dictionary PurchasesModels => _cachedPurchases ??= Purchases.Select(x => (CostByPurchaseModel)x).ToDictionary(x => x.PurchaseId, x => x); + private Dictionary? _cachedPurchases; + public Dictionary PurchasesModels => _cachedPurchases ??= Purchases.Select(x => (OrderByPurchaseModel)x).ToDictionary(x => x.PurchaseId, x => x); [Required] - public Order? Order{ get; private set; } + public Order? Orders{ get; private set; } [Required] public List Purchases { get; private set; } = new(); @@ -40,10 +40,10 @@ namespace DatabaseImplement.Models public OrderViewModel GetViewModel => new() { - PhoneNumber = Employee?.PhoneNumber??string.Empty, + PhoneNumber = IEmployee?.PhoneNumber??string.Empty, PurchaseModels = PurchasesModels, - EmployeeId = EmployeeId, - NameOfCost = NameOfCost, + OrderId = OrderId, + NameOrder = NameOrder, Price = Price, Id = Id }; @@ -59,12 +59,12 @@ namespace DatabaseImplement.Models /// public void UpdatePurchases(AutoShopDB context, OrderBindingModel model) { - var oldPurchases = context.CostByPurchases.Where(x => x.CostId == model.Id).ToDictionary(x => x.PurchaseId, x => x); + var oldPurchases = context.OrderByPurchases.Where(x => x.OrderId == model.Id).ToDictionary(x => x.PurchaseId, x => x); var newPurchases = model.PurchasesModels.ToDictionary( x => x.Key, x => new OrderByPurchase() { - CostId = model.Id, + OrderId = model.Id, PurchaseId = x.Key, Count = x.Value.Count, } diff --git a/DatabaseImplement/Models/OrderByPurchase.cs b/DatabaseImplement/Models/OrderByPurchase.cs new file mode 100644 index 0000000..cd42026 --- /dev/null +++ b/DatabaseImplement/Models/OrderByPurchase.cs @@ -0,0 +1,19 @@ +using System.ComponentModel.DataAnnotations; +using Contracts.BindingModel; +using DataModels.ProxyModels; + +namespace DatabaseImplement.Models +{ + public class OrderByPurchase : OrderByPurchaseModel + { + [Required] + public Order? Order { get; private set; } + [Required] + public Purchase? Purchase { get; private set; } + + internal void Update(OrderBindingModel model) + { + throw new NotImplementedException(); + } + } +} diff --git a/DatabaseImplement/Models/Purchase.cs b/DatabaseImplement/Models/Purchase.cs index 5d7aab1..7881097 100644 --- a/DatabaseImplement/Models/Purchase.cs +++ b/DatabaseImplement/Models/Purchase.cs @@ -48,7 +48,7 @@ namespace DatabaseImplement.Models ClientId = ClientId, ClientPhoneNumber = Client?.PhoneNumber ?? string.Empty, - CostViewModels = Costs? + OrderViewModels = Order? .Select(x => x.Cost.GetViewModel) .ToList() ?? new(), OperationViewModels = Operations? @@ -64,7 +64,7 @@ namespace DatabaseImplement.Models ClientId = ClientId, ClientPhoneNumber = Client?.PhoneNumber ?? string.Empty, - CostViewModels = Costs? + OrderViewModels = Order? .Select(x => x.Cost.GetViewModel) .ToList() ?? new() }; diff --git a/WebApplication2/AutoRepairShop.csproj b/WebApplication2/AutoRepairShop.csproj index 867990d..f121837 100644 --- a/WebApplication2/AutoRepairShop.csproj +++ b/WebApplication2/AutoRepairShop.csproj @@ -9,6 +9,7 @@ + all runtime; build; native; contentfiles; analyzers; buildtransitive