From 40faac2b71e66101f780117961ddbe12b52260bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BA=20=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Wed, 5 Apr 2023 22:15:31 +0400 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D1=81=D1=82=D0=B0=D1=82=D0=B5=D0=B9=20=D0=B7=D0=B0?= =?UTF-8?q?=D1=82=D1=80=D0=B0=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ItemForRepairLogic.cs | 16 +-- .../BusinessLogics/ItemLogic.cs | 35 +++-- .../BusinessLogics/RepairRequestLogic.cs | 16 +-- .../BusinessLogics/VehicleLogic.cs | 16 +-- .../BusinessLogics/WorkInRequestLogic.cs | 16 +-- .../BusinessLogics/WorkLogic.cs | 4 +- .../BusinessLogics/WorkPaymentLogic.cs | 16 +-- .../SearchModels/ItemSearchModel.cs | 1 + .../ViewModels/ItemViewModel.cs | 2 + .../Implements/ItemStorage.cs | 87 ++++++++++++ CarService/CarServiceDatabase/Models/Item.cs | 15 ++- .../FormAddItemTest.Designer.cs | 127 ++++++++++++++++++ CarService/CarServiceView/FormAddItemTest.cs | 25 ++++ .../CarServiceView/FormAddItemTest.resx | 60 +++++++++ .../CarServiceView/FormItemTest.Designer.cs | 107 +++++++++++++++ CarService/CarServiceView/FormItemTest.cs | 33 +++++ CarService/CarServiceView/FormItemTest.resx | 63 +++++++++ .../CarServiceView/FormWorkTest.Designer.cs | 2 +- CarService/CarServiceView/Program.cs | 9 +- 19 files changed, 587 insertions(+), 63 deletions(-) create mode 100644 CarService/CarServiceDatabase/Implements/ItemStorage.cs create mode 100644 CarService/CarServiceView/FormAddItemTest.Designer.cs create mode 100644 CarService/CarServiceView/FormAddItemTest.cs create mode 100644 CarService/CarServiceView/FormAddItemTest.resx create mode 100644 CarService/CarServiceView/FormItemTest.Designer.cs create mode 100644 CarService/CarServiceView/FormItemTest.cs create mode 100644 CarService/CarServiceView/FormItemTest.resx diff --git a/CarService/CarServiceBusinessLogic/BusinessLogics/ItemForRepairLogic.cs b/CarService/CarServiceBusinessLogic/BusinessLogics/ItemForRepairLogic.cs index 228b959..007859e 100644 --- a/CarService/CarServiceBusinessLogic/BusinessLogics/ItemForRepairLogic.cs +++ b/CarService/CarServiceBusinessLogic/BusinessLogics/ItemForRepairLogic.cs @@ -10,16 +10,16 @@ namespace CarServiceBusinessLogic.BusinessLogics public class ItemForRepairLogic : IItemForRepairLogic { private readonly ILogger _logger; - private readonly IItemForRepairStorage _customerStorage; - public ItemForRepairLogic(ILogger logger, IItemForRepairStorage customerStorage) + private readonly IItemForRepairStorage _itemForRepairStorage; + public ItemForRepairLogic(ILogger logger, IItemForRepairStorage itemForRepairStorage) { _logger = logger; - _customerStorage = customerStorage; + _itemForRepairStorage = itemForRepairStorage; } public List? ReadList(ItemForRepairSearchModel? model) { _logger.LogInformation("ReadList. Id: {Id}", model?.Id); - var list = model == null ? _customerStorage.GetFullList() : _customerStorage.GetFilteredList(model); + var list = model == null ? _itemForRepairStorage.GetFullList() : _itemForRepairStorage.GetFilteredList(model); if (list == null) { _logger.LogWarning("ReadList return null list"); @@ -35,7 +35,7 @@ namespace CarServiceBusinessLogic.BusinessLogics throw new ArgumentNullException(nameof(model)); } _logger.LogInformation("ReadElement. Id: {Id}", model.Id); - var element = _customerStorage.GetElement(model); + var element = _itemForRepairStorage.GetElement(model); if (element == null) { _logger.LogWarning("ReadElement element not found"); @@ -47,7 +47,7 @@ namespace CarServiceBusinessLogic.BusinessLogics public bool Create(ItemForRepairBindingModel model) { CheckModel(model); - if (_customerStorage.Insert(model) == null) + if (_itemForRepairStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); return false; @@ -57,7 +57,7 @@ namespace CarServiceBusinessLogic.BusinessLogics public bool Update(ItemForRepairBindingModel model) { CheckModel(model); - if (_customerStorage.Update(model) == null) + if (_itemForRepairStorage.Update(model) == null) { _logger.LogWarning("Update operation failed"); return false; @@ -68,7 +68,7 @@ namespace CarServiceBusinessLogic.BusinessLogics { CheckModel(model, false); _logger.LogInformation("Delete. Id:{Id}", model.Id); - if (_customerStorage.Delete(model) == null) + if (_itemForRepairStorage.Delete(model) == null) { _logger.LogWarning("Delete operation failed"); return false; diff --git a/CarService/CarServiceBusinessLogic/BusinessLogics/ItemLogic.cs b/CarService/CarServiceBusinessLogic/BusinessLogics/ItemLogic.cs index e8db443..8d8fe54 100644 --- a/CarService/CarServiceBusinessLogic/BusinessLogics/ItemLogic.cs +++ b/CarService/CarServiceBusinessLogic/BusinessLogics/ItemLogic.cs @@ -10,16 +10,16 @@ namespace CarServiceBusinessLogic.BusinessLogics public class ItemLogic : IItemLogic { private readonly ILogger _logger; - private readonly IItemStorage _customerStorage; - public ItemLogic(ILogger logger, IItemStorage customerStorage) + private readonly IItemStorage _itemStorage; + public ItemLogic(ILogger logger, IItemStorage itemStorage) { _logger = logger; - _customerStorage = customerStorage; + _itemStorage = itemStorage; } public List? ReadList(ItemSearchModel? model) { _logger.LogInformation("ReadList. Id: {Id}", model?.Id); - var list = model == null ? _customerStorage.GetFullList() : _customerStorage.GetFilteredList(model); + var list = model == null ? _itemStorage.GetFullList() : _itemStorage.GetFilteredList(model); if (list == null) { _logger.LogWarning("ReadList return null list"); @@ -35,7 +35,7 @@ namespace CarServiceBusinessLogic.BusinessLogics throw new ArgumentNullException(nameof(model)); } _logger.LogInformation("ReadElement. Id: {Id}", model.Id); - var element = _customerStorage.GetElement(model); + var element = _itemStorage.GetElement(model); if (element == null) { _logger.LogWarning("ReadElement element not found"); @@ -47,7 +47,7 @@ namespace CarServiceBusinessLogic.BusinessLogics public bool Create(ItemBindingModel model) { CheckModel(model); - if (_customerStorage.Insert(model) == null) + if (_itemStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); return false; @@ -57,7 +57,7 @@ namespace CarServiceBusinessLogic.BusinessLogics public bool Update(ItemBindingModel model) { CheckModel(model); - if (_customerStorage.Update(model) == null) + if (_itemStorage.Update(model) == null) { _logger.LogWarning("Update operation failed"); return false; @@ -68,7 +68,7 @@ namespace CarServiceBusinessLogic.BusinessLogics { CheckModel(model, false); _logger.LogInformation("Delete. Id:{Id}", model.Id); - if (_customerStorage.Delete(model) == null) + if (_itemStorage.Delete(model) == null) { _logger.LogWarning("Delete operation failed"); return false; @@ -85,6 +85,25 @@ namespace CarServiceBusinessLogic.BusinessLogics { return; } + //Заполнено ли название? + if (string.IsNullOrEmpty(model.Name)) + { + _logger.LogWarning("Item name is empty"); + throw new ArgumentException("Не введено название"); + } + //Название уникально? + var existingItem = _itemStorage.GetElement(new() { Name = model.Name }); + if (existingItem != null) + { + _logger.LogWarning("Item name is not unique"); + throw new ArgumentException("Работа с таким названием уже есть"); + } + //Цена больше 0? + if (model.Price <= 0) + { + _logger.LogWarning("Work Price is <= 0"); + throw new ArgumentException("Цена должна быть больше 0"); + } _logger.LogInformation("Item. Id: {Id}", model.Id); } } diff --git a/CarService/CarServiceBusinessLogic/BusinessLogics/RepairRequestLogic.cs b/CarService/CarServiceBusinessLogic/BusinessLogics/RepairRequestLogic.cs index 759e619..9079235 100644 --- a/CarService/CarServiceBusinessLogic/BusinessLogics/RepairRequestLogic.cs +++ b/CarService/CarServiceBusinessLogic/BusinessLogics/RepairRequestLogic.cs @@ -10,16 +10,16 @@ namespace CarServiceBusinessLogic.BusinessLogics public class RepairRequestLogic : IRepairRequestLogic { private readonly ILogger _logger; - private readonly IRepairRequestStorage _customerStorage; - public RepairRequestLogic(ILogger logger, IRepairRequestStorage customerStorage) + private readonly IRepairRequestStorage _repairRequestStorage; + public RepairRequestLogic(ILogger logger, IRepairRequestStorage repairRequestStorage) { _logger = logger; - _customerStorage = customerStorage; + _repairRequestStorage = repairRequestStorage; } public List? ReadList(RepairRequestSearchModel? model) { _logger.LogInformation("ReadList. Id: {Id}", model?.Id); - var list = model == null ? _customerStorage.GetFullList() : _customerStorage.GetFilteredList(model); + var list = model == null ? _repairRequestStorage.GetFullList() : _repairRequestStorage.GetFilteredList(model); if (list == null) { _logger.LogWarning("ReadList return null list"); @@ -35,7 +35,7 @@ namespace CarServiceBusinessLogic.BusinessLogics throw new ArgumentNullException(nameof(model)); } _logger.LogInformation("ReadElement. Id: {Id}", model.Id); - var element = _customerStorage.GetElement(model); + var element = _repairRequestStorage.GetElement(model); if (element == null) { _logger.LogWarning("ReadElement element not found"); @@ -47,7 +47,7 @@ namespace CarServiceBusinessLogic.BusinessLogics public bool Create(RepairRequestBindingModel model) { CheckModel(model); - if (_customerStorage.Insert(model) == null) + if (_repairRequestStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); return false; @@ -57,7 +57,7 @@ namespace CarServiceBusinessLogic.BusinessLogics public bool Update(RepairRequestBindingModel model) { CheckModel(model); - if (_customerStorage.Update(model) == null) + if (_repairRequestStorage.Update(model) == null) { _logger.LogWarning("Update operation failed"); return false; @@ -68,7 +68,7 @@ namespace CarServiceBusinessLogic.BusinessLogics { CheckModel(model, false); _logger.LogInformation("Delete. Id:{Id}", model.Id); - if (_customerStorage.Delete(model) == null) + if (_repairRequestStorage.Delete(model) == null) { _logger.LogWarning("Delete operation failed"); return false; diff --git a/CarService/CarServiceBusinessLogic/BusinessLogics/VehicleLogic.cs b/CarService/CarServiceBusinessLogic/BusinessLogics/VehicleLogic.cs index 2c30a8e..0b45279 100644 --- a/CarService/CarServiceBusinessLogic/BusinessLogics/VehicleLogic.cs +++ b/CarService/CarServiceBusinessLogic/BusinessLogics/VehicleLogic.cs @@ -10,16 +10,16 @@ namespace CarServiceBusinessLogic.BusinessLogics public class VehicleLogic : IVehicleLogic { private readonly ILogger _logger; - private readonly IVehicleStorage _customerStorage; - public VehicleLogic(ILogger logger, IVehicleStorage customerStorage) + private readonly IVehicleStorage _vehicleStorage; + public VehicleLogic(ILogger logger, IVehicleStorage vehicleStorage) { _logger = logger; - _customerStorage = customerStorage; + _vehicleStorage = vehicleStorage; } public List? ReadList(VehicleSearchModel? model) { _logger.LogInformation("ReadList. Id: {Id}", model?.Id); - var list = model == null ? _customerStorage.GetFullList() : _customerStorage.GetFilteredList(model); + var list = model == null ? _vehicleStorage.GetFullList() : _vehicleStorage.GetFilteredList(model); if (list == null) { _logger.LogWarning("ReadList return null list"); @@ -35,7 +35,7 @@ namespace CarServiceBusinessLogic.BusinessLogics throw new ArgumentNullException(nameof(model)); } _logger.LogInformation("ReadElement. Id: {Id}", model.Id); - var element = _customerStorage.GetElement(model); + var element = _vehicleStorage.GetElement(model); if (element == null) { _logger.LogWarning("ReadElement element not found"); @@ -47,7 +47,7 @@ namespace CarServiceBusinessLogic.BusinessLogics public bool Create(VehicleBindingModel model) { CheckModel(model); - if (_customerStorage.Insert(model) == null) + if (_vehicleStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); return false; @@ -57,7 +57,7 @@ namespace CarServiceBusinessLogic.BusinessLogics public bool Update(VehicleBindingModel model) { CheckModel(model); - if (_customerStorage.Update(model) == null) + if (_vehicleStorage.Update(model) == null) { _logger.LogWarning("Update operation failed"); return false; @@ -68,7 +68,7 @@ namespace CarServiceBusinessLogic.BusinessLogics { CheckModel(model, false); _logger.LogInformation("Delete. Id:{Id}", model.Id); - if (_customerStorage.Delete(model) == null) + if (_vehicleStorage.Delete(model) == null) { _logger.LogWarning("Delete operation failed"); return false; diff --git a/CarService/CarServiceBusinessLogic/BusinessLogics/WorkInRequestLogic.cs b/CarService/CarServiceBusinessLogic/BusinessLogics/WorkInRequestLogic.cs index 7404ee0..51a9f99 100644 --- a/CarService/CarServiceBusinessLogic/BusinessLogics/WorkInRequestLogic.cs +++ b/CarService/CarServiceBusinessLogic/BusinessLogics/WorkInRequestLogic.cs @@ -10,16 +10,16 @@ namespace CarServiceBusinessLogic.BusinessLogics public class WorkInRequestLogic : IWorkInRequestLogic { private readonly ILogger _logger; - private readonly IWorkInRequestStorage _customerStorage; - public WorkInRequestLogic(ILogger logger, IWorkInRequestStorage customerStorage) + private readonly IWorkInRequestStorage _workInRequestStorage; + public WorkInRequestLogic(ILogger logger, IWorkInRequestStorage workInRequestStorage) { _logger = logger; - _customerStorage = customerStorage; + _workInRequestStorage = workInRequestStorage; } public List? ReadList(WorkInRequestSearchModel? model) { _logger.LogInformation("ReadList. Id: {Id}", model?.Id); - var list = model == null ? _customerStorage.GetFullList() : _customerStorage.GetFilteredList(model); + var list = model == null ? _workInRequestStorage.GetFullList() : _workInRequestStorage.GetFilteredList(model); if (list == null) { _logger.LogWarning("ReadList return null list"); @@ -35,7 +35,7 @@ namespace CarServiceBusinessLogic.BusinessLogics throw new ArgumentNullException(nameof(model)); } _logger.LogInformation("ReadElement. Id: {Id}", model.Id); - var element = _customerStorage.GetElement(model); + var element = _workInRequestStorage.GetElement(model); if (element == null) { _logger.LogWarning("ReadElement element not found"); @@ -47,7 +47,7 @@ namespace CarServiceBusinessLogic.BusinessLogics public bool Create(WorkInRequestBindingModel model) { CheckModel(model); - if (_customerStorage.Insert(model) == null) + if (_workInRequestStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); return false; @@ -57,7 +57,7 @@ namespace CarServiceBusinessLogic.BusinessLogics public bool Update(WorkInRequestBindingModel model) { CheckModel(model); - if (_customerStorage.Update(model) == null) + if (_workInRequestStorage.Update(model) == null) { _logger.LogWarning("Update operation failed"); return false; @@ -68,7 +68,7 @@ namespace CarServiceBusinessLogic.BusinessLogics { CheckModel(model, false); _logger.LogInformation("Delete. Id:{Id}", model.Id); - if (_customerStorage.Delete(model) == null) + if (_workInRequestStorage.Delete(model) == null) { _logger.LogWarning("Delete operation failed"); return false; diff --git a/CarService/CarServiceBusinessLogic/BusinessLogics/WorkLogic.cs b/CarService/CarServiceBusinessLogic/BusinessLogics/WorkLogic.cs index 11d9c59..dba68ac 100644 --- a/CarService/CarServiceBusinessLogic/BusinessLogics/WorkLogic.cs +++ b/CarService/CarServiceBusinessLogic/BusinessLogics/WorkLogic.cs @@ -11,10 +11,10 @@ namespace CarServiceBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IWorkStorage _workStorage; - public WorkLogic(ILogger logger, IWorkStorage customerStorage) + public WorkLogic(ILogger logger, IWorkStorage workStorage) { _logger = logger; - _workStorage = customerStorage; + _workStorage = workStorage; } public List? ReadList(WorkSearchModel? model) { diff --git a/CarService/CarServiceBusinessLogic/BusinessLogics/WorkPaymentLogic.cs b/CarService/CarServiceBusinessLogic/BusinessLogics/WorkPaymentLogic.cs index fbf4cb1..fabd7cf 100644 --- a/CarService/CarServiceBusinessLogic/BusinessLogics/WorkPaymentLogic.cs +++ b/CarService/CarServiceBusinessLogic/BusinessLogics/WorkPaymentLogic.cs @@ -10,16 +10,16 @@ namespace CarServiceBusinessLogic.BusinessLogics public class WorkPaymentLogic : IWorkPaymentLogic { private readonly ILogger _logger; - private readonly IWorkPaymentStorage _customerStorage; - public WorkPaymentLogic(ILogger logger, IWorkPaymentStorage customerStorage) + private readonly IWorkPaymentStorage _workPaymentStorage; + public WorkPaymentLogic(ILogger logger, IWorkPaymentStorage workPaymentStorage) { _logger = logger; - _customerStorage = customerStorage; + _workPaymentStorage = workPaymentStorage; } public List? ReadList(WorkPaymentSearchModel? model) { _logger.LogInformation("ReadList. Id: {Id}", model?.Id); - var list = model == null ? _customerStorage.GetFullList() : _customerStorage.GetFilteredList(model); + var list = model == null ? _workPaymentStorage.GetFullList() : _workPaymentStorage.GetFilteredList(model); if (list == null) { _logger.LogWarning("ReadList return null list"); @@ -35,7 +35,7 @@ namespace CarServiceBusinessLogic.BusinessLogics throw new ArgumentNullException(nameof(model)); } _logger.LogInformation("ReadElement. Id: {Id}", model.Id); - var element = _customerStorage.GetElement(model); + var element = _workPaymentStorage.GetElement(model); if (element == null) { _logger.LogWarning("ReadElement element not found"); @@ -47,7 +47,7 @@ namespace CarServiceBusinessLogic.BusinessLogics public bool Create(WorkPaymentBindingModel model) { CheckModel(model); - if (_customerStorage.Insert(model) == null) + if (_workPaymentStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); return false; @@ -57,7 +57,7 @@ namespace CarServiceBusinessLogic.BusinessLogics public bool Update(WorkPaymentBindingModel model) { CheckModel(model); - if (_customerStorage.Update(model) == null) + if (_workPaymentStorage.Update(model) == null) { _logger.LogWarning("Update operation failed"); return false; @@ -68,7 +68,7 @@ namespace CarServiceBusinessLogic.BusinessLogics { CheckModel(model, false); _logger.LogInformation("Delete. Id:{Id}", model.Id); - if (_customerStorage.Delete(model) == null) + if (_workPaymentStorage.Delete(model) == null) { _logger.LogWarning("Delete operation failed"); return false; diff --git a/CarService/CarServiceContracts/SearchModels/ItemSearchModel.cs b/CarService/CarServiceContracts/SearchModels/ItemSearchModel.cs index 8f54a26..65b2fe3 100644 --- a/CarService/CarServiceContracts/SearchModels/ItemSearchModel.cs +++ b/CarService/CarServiceContracts/SearchModels/ItemSearchModel.cs @@ -3,5 +3,6 @@ public class ItemSearchModel { public int? Id { get; set; } + public string? Name { get; set; } } } diff --git a/CarService/CarServiceContracts/ViewModels/ItemViewModel.cs b/CarService/CarServiceContracts/ViewModels/ItemViewModel.cs index 7c93229..5469082 100644 --- a/CarService/CarServiceContracts/ViewModels/ItemViewModel.cs +++ b/CarService/CarServiceContracts/ViewModels/ItemViewModel.cs @@ -13,5 +13,7 @@ namespace CarServiceContracts.ViewModels [DisplayName("Количество")] public int Count { get; set; } public int WorkerId { get; set; } + [DisplayName("Сотрудник")] + public string WorkerName { get; set; } = string.Empty; } } diff --git a/CarService/CarServiceDatabase/Implements/ItemStorage.cs b/CarService/CarServiceDatabase/Implements/ItemStorage.cs new file mode 100644 index 0000000..8852953 --- /dev/null +++ b/CarService/CarServiceDatabase/Implements/ItemStorage.cs @@ -0,0 +1,87 @@ +using CarServiceContracts.BindingModels; +using CarServiceContracts.SearchModels; +using CarServiceContracts.StorageContracts; +using CarServiceContracts.ViewModels; +using CarServiceDatabase.Models; +using Microsoft.EntityFrameworkCore; + +namespace CarServiceDatabase.Implements +{ + public class ItemStorage : IItemStorage + { + public List GetFullList() + { + using var context = new CarServiceDbContext(); + return context.Items + .Include(x => x.Worker) + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(ItemSearchModel model) + { + using var context = new CarServiceDbContext(); + return context.Items + .Where(x => x.Id == model.Id) + .Include(x => x.Worker) + .Select(x => x.GetViewModel) + .ToList(); + } + public ItemViewModel? GetElement(ItemSearchModel model) + { + if (model == null) + { + return null; + } + using var context = new CarServiceDbContext(); + if (model.Id.HasValue)//сначала ищем по Id + { + return context.Items + .Include(x => x.Worker) + .FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + } + if (!string.IsNullOrEmpty(model.Name))//затем по названию + { + return context.Items + .Include(x => x.Worker) + .FirstOrDefault(x => x.Name == model.Name)?.GetViewModel; + } + return null; + } + public ItemViewModel? Insert(ItemBindingModel model) + { + using var context = new CarServiceDbContext(); + var newItem = Item.Create(context, model); + if (newItem != null) + { + context.Items.Add(newItem); + context.SaveChanges(); + return newItem.GetViewModel; + } + return null; + } + public ItemViewModel? Update(ItemBindingModel model) + { + using var context = new CarServiceDbContext(); + var item = context.Items.FirstOrDefault(x => x.Id == model.Id); + if (item == null) + { + return null; + } + item.Update(context, model); + context.SaveChanges(); + return item.GetViewModel; + } + public ItemViewModel? Delete(ItemBindingModel model) + { + using var context = new CarServiceDbContext(); + var item = context.Items.FirstOrDefault(x => x.Id == model.Id); + if (item == null) + { + return null; + } + context.Items.Remove(item); + context.SaveChanges(); + return item.GetViewModel; + } + } +} diff --git a/CarService/CarServiceDatabase/Models/Item.cs b/CarService/CarServiceDatabase/Models/Item.cs index 51956bb..ab47d4a 100644 --- a/CarService/CarServiceDatabase/Models/Item.cs +++ b/CarService/CarServiceDatabase/Models/Item.cs @@ -23,7 +23,7 @@ namespace CarServiceDatabase.Models [ForeignKey("ItemId")] public virtual List ItemsForRepair { get; set; } = new(); public virtual Worker Worker { get; set; } = new(); - public static Item? Create(ItemBindingModel? model) + public static Item? Create(CarServiceDbContext context, ItemBindingModel? model) { if (model == null) { @@ -35,10 +35,10 @@ namespace CarServiceDatabase.Models Name = model.Name, Price = model.Price, Count = model.Count, - WorkerId = model.WorkerId + Worker = context.Workers.First(x => x.Id == model.WorkerId) }; } - public static Item Create(ItemViewModel model) + public static Item Create(CarServiceDbContext context, ItemViewModel model) { return new() { @@ -46,10 +46,10 @@ namespace CarServiceDatabase.Models Name = model.Name, Price = model.Price, Count = model.Count, - WorkerId = model.WorkerId + Worker = context.Workers.First(x => x.Id == model.WorkerId) }; } - public void Update(ItemBindingModel? model) + public void Update(CarServiceDbContext context, ItemBindingModel? model) { if (model == null) { @@ -59,7 +59,7 @@ namespace CarServiceDatabase.Models Name = model.Name; Price = model.Price; Count = model.Count; - WorkerId = model.WorkerId; + Worker = context.Workers.First(x => x.Id == model.WorkerId); } public ItemViewModel GetViewModel => new() { @@ -67,7 +67,8 @@ namespace CarServiceDatabase.Models Name = Name, Price = Price, Count = Count, - WorkerId = WorkerId + WorkerId = WorkerId, + WorkerName = Worker.Name + " " + Worker.Surname }; } } diff --git a/CarService/CarServiceView/FormAddItemTest.Designer.cs b/CarService/CarServiceView/FormAddItemTest.Designer.cs new file mode 100644 index 0000000..5bd2f14 --- /dev/null +++ b/CarService/CarServiceView/FormAddItemTest.Designer.cs @@ -0,0 +1,127 @@ +namespace CarServiceView +{ + partial class FormAddItemTest + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.buttonAdd = new System.Windows.Forms.Button(); + this.label3 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.textBoxPrice = new System.Windows.Forms.TextBox(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(36, 125); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(75, 23); + this.buttonAdd.TabIndex = 9; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(12, 67); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(72, 15); + this.label3.TabIndex = 6; + this.label3.Text = "Количество"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(12, 38); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(35, 15); + this.label2.TabIndex = 7; + this.label2.Text = "Цена"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 9); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(90, 15); + this.label1.TabIndex = 8; + this.label1.Text = "Наименование"; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(108, 64); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(100, 23); + this.textBoxCount.TabIndex = 3; + // + // textBoxPrice + // + this.textBoxPrice.Location = new System.Drawing.Point(108, 35); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.Size = new System.Drawing.Size(100, 23); + this.textBoxPrice.TabIndex = 4; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(108, 6); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(100, 23); + this.textBoxName.TabIndex = 5; + // + // FormAddItemTest + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.textBoxPrice); + this.Controls.Add(this.textBoxName); + this.Name = "FormAddItemTest"; + this.Text = "FormAddItemTest"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonAdd; + private Label label3; + private Label label2; + private Label label1; + private TextBox textBoxCount; + private TextBox textBoxPrice; + private TextBox textBoxName; + } +} \ No newline at end of file diff --git a/CarService/CarServiceView/FormAddItemTest.cs b/CarService/CarServiceView/FormAddItemTest.cs new file mode 100644 index 0000000..10655c3 --- /dev/null +++ b/CarService/CarServiceView/FormAddItemTest.cs @@ -0,0 +1,25 @@ +using CarServiceContracts.BusinessLogicsContracts; + +namespace CarServiceView +{ + public partial class FormAddItemTest : Form + { + IItemLogic _itemLogic; + public FormAddItemTest(IItemLogic itemLogic) + { + _itemLogic = itemLogic; + InitializeComponent(); + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + _itemLogic.Create(new() + { + Name = textBoxName.Text, + Price = Convert.ToDecimal(textBoxPrice.Text), + Count = Convert.ToInt32(textBoxCount.Text), + WorkerId = 1 + }); + } + } +} diff --git a/CarService/CarServiceView/FormAddItemTest.resx b/CarService/CarServiceView/FormAddItemTest.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/CarService/CarServiceView/FormAddItemTest.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/CarService/CarServiceView/FormItemTest.Designer.cs b/CarService/CarServiceView/FormItemTest.Designer.cs new file mode 100644 index 0000000..f134255 --- /dev/null +++ b/CarService/CarServiceView/FormItemTest.Designer.cs @@ -0,0 +1,107 @@ +namespace CarServiceView +{ + partial class FormItemTest + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.menuStrip = new System.Windows.Forms.MenuStrip(); + this.addToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.updateToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.deleteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.menuStrip.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // menuStrip + // + this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.addToolStripMenuItem, + this.updateToolStripMenuItem, + this.deleteToolStripMenuItem}); + this.menuStrip.Location = new System.Drawing.Point(0, 0); + this.menuStrip.Name = "menuStrip"; + this.menuStrip.Size = new System.Drawing.Size(800, 24); + this.menuStrip.TabIndex = 5; + this.menuStrip.Text = "menuStrip1"; + // + // addToolStripMenuItem + // + this.addToolStripMenuItem.Name = "addToolStripMenuItem"; + this.addToolStripMenuItem.Size = new System.Drawing.Size(71, 20); + this.addToolStripMenuItem.Text = "Добавить"; + this.addToolStripMenuItem.Click += new System.EventHandler(this.addToolStripMenuItem_Click); + // + // updateToolStripMenuItem + // + this.updateToolStripMenuItem.Name = "updateToolStripMenuItem"; + this.updateToolStripMenuItem.Size = new System.Drawing.Size(73, 20); + this.updateToolStripMenuItem.Text = "Изменить"; + // + // deleteToolStripMenuItem + // + this.deleteToolStripMenuItem.Name = "deleteToolStripMenuItem"; + this.deleteToolStripMenuItem.Size = new System.Drawing.Size(63, 20); + this.deleteToolStripMenuItem.Text = "Удалить"; + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(0, 27); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(798, 421); + this.dataGridView.TabIndex = 6; + // + // FormItemTest + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.menuStrip); + this.Name = "FormItemTest"; + this.Text = "FormItemTest"; + this.Load += new System.EventHandler(this.FormItemTest_Load); + this.menuStrip.ResumeLayout(false); + this.menuStrip.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private MenuStrip menuStrip; + private ToolStripMenuItem addToolStripMenuItem; + private ToolStripMenuItem updateToolStripMenuItem; + private ToolStripMenuItem deleteToolStripMenuItem; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/CarService/CarServiceView/FormItemTest.cs b/CarService/CarServiceView/FormItemTest.cs new file mode 100644 index 0000000..cf401e8 --- /dev/null +++ b/CarService/CarServiceView/FormItemTest.cs @@ -0,0 +1,33 @@ +using CarServiceBusinessLogic.BusinessLogics; +using CarServiceContracts.BusinessLogicsContracts; + +namespace CarServiceView +{ + public partial class FormItemTest : Form + { + IItemLogic _itemLogic; + public FormItemTest(IItemLogic itemLogic) + { + _itemLogic = itemLogic; + InitializeComponent(); + } + private void addToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormAddItemTest)); + if (service is FormAddItemTest form) + { + form.ShowDialog(); + LoadData(); + } + } + private void LoadData() + { + var list = _itemLogic.ReadList(null); + dataGridView.DataSource = list; + } + private void FormItemTest_Load(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/CarService/CarServiceView/FormItemTest.resx b/CarService/CarServiceView/FormItemTest.resx new file mode 100644 index 0000000..81a9e3d --- /dev/null +++ b/CarService/CarServiceView/FormItemTest.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/CarService/CarServiceView/FormWorkTest.Designer.cs b/CarService/CarServiceView/FormWorkTest.Designer.cs index 4dbec64..c9e1ffb 100644 --- a/CarService/CarServiceView/FormWorkTest.Designer.cs +++ b/CarService/CarServiceView/FormWorkTest.Designer.cs @@ -87,7 +87,7 @@ this.Controls.Add(this.menuStrip); this.Controls.Add(this.dataGridView); this.Name = "FormWorkTest"; - this.Text = "FormGridViewTest"; + this.Text = "FormWorkTest"; this.Load += new System.EventHandler(this.FormWorkTest_Load); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); this.menuStrip.ResumeLayout(false); diff --git a/CarService/CarServiceView/Program.cs b/CarService/CarServiceView/Program.cs index fc8cc77..57127c3 100644 --- a/CarService/CarServiceView/Program.cs +++ b/CarService/CarServiceView/Program.cs @@ -19,7 +19,7 @@ namespace CarServiceView var services = new ServiceCollection(); ConfigureServices(services); _serviceProvider = services.BuildServiceProvider(); - Application.Run(_serviceProvider.GetRequiredService()); + Application.Run(_serviceProvider.GetRequiredService()); } private static void ConfigureServices(ServiceCollection services) { @@ -28,10 +28,6 @@ namespace CarServiceView option.SetMinimumLevel(LogLevel.Information); option.AddNLog("nlog.config"); }); - //services.AddTransient(); - //services.AddTransient(); - //services.AddTransient(); - //services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -44,10 +40,13 @@ namespace CarServiceView services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file