From c3150957582744a1330a487d236330a6f27e715a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Tue, 28 Mar 2023 00:27:02 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=9D=D0=9E=D0=9E=D0=9E=D0=9E=D0=9E?= =?UTF-8?q?=D0=9E=D0=9E=20=D0=A0=D0=90=D0=91=D0=9E=D0=A2=D0=90=D0=95=D0=95?= =?UTF-8?q?=D0=95=D0=95=D0=95=D0=95=D0=95=D0=95=D0=95=D0=95=D0=A2!!!!!!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormCreateOrder.Designer.cs | 1 + .../PrecastConcretePlant/FormCreateOrder.cs | 11 ++- .../PrecastConcretePlant/FormMain.cs | 21 +----- .../BusinessLogic/OrderLogic.cs | 55 ++++++++------- .../Controllers/HomeController.cs | 29 +++----- .../BindingModels/OrderBindingModel.cs | 1 - .../ViewModels/OrderViewModel.cs | 19 +++-- .../Models/IOrderModel.cs | 2 +- .../Implements/OrderStorage.cs | 69 +++++++++---------- ....cs => 20230327202214_Restart.Designer.cs} | 16 ++--- ...8_Restart.cs => 20230327202214_Restart.cs} | 8 +-- ...ecastConcretePlantDataBaseModelSnapshot.cs | 14 ++-- .../Models/Order.cs | 58 ++++++++-------- .../Models/Order.cs | 6 -- .../Models/Order.cs | 4 -- .../Properties/launchSettings.json | 28 ++++---- 16 files changed, 158 insertions(+), 184 deletions(-) rename PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/{20230326191118_Restart.Designer.cs => 20230327202214_Restart.Designer.cs} (95%) rename PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/{20230326191118_Restart.cs => 20230327202214_Restart.cs} (97%) diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormCreateOrder.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormCreateOrder.Designer.cs index 626b41b..c280144 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormCreateOrder.Designer.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormCreateOrder.Designer.cs @@ -151,6 +151,7 @@ this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.Name = "FormCreateOrder"; this.Text = "Заказ"; + this.Load += new System.EventHandler(this.FormCreateOrder_Load); this.ResumeLayout(false); this.PerformLayout(); diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormCreateOrder.cs b/PrecastConcretePlant/PrecastConcretePlant/FormCreateOrder.cs index 12ef448..598068f 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormCreateOrder.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormCreateOrder.cs @@ -63,11 +63,6 @@ namespace PrecastConcretePlantView } } - private void FormCreateOrder_Load(object sender, EventArgs e) - { - LoadData(); - } - private void CalcSum() { if (ReinforcedComboBox.SelectedValue != null && !string.IsNullOrEmpty(CountTextBox.Text)) @@ -125,7 +120,6 @@ namespace PrecastConcretePlantView { ClientId = Convert.ToInt32(ClientСomboBox.SelectedValue), ReinforcedId = Convert.ToInt32(ReinforcedComboBox.SelectedValue), - ReinforcedName = ReinforcedComboBox.Text, Count = Convert.ToInt32(CountTextBox.Text), Sum = Convert.ToDouble(SumTextBox.Text) }); @@ -156,5 +150,10 @@ namespace PrecastConcretePlantView { CalcSum(); } + + private void FormCreateOrder_Load(object sender, EventArgs e) + { + LoadData(); + } } } diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs b/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs index 105adaa..516f77d 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs @@ -47,6 +47,7 @@ namespace PrecastConcretePlantView { DataGridView.DataSource = list; DataGridView.Columns["ReinforcedId"].Visible = false; + DataGridView.Columns["ClientId"].Visible = false; } _logger.LogInformation("Загрузка заказов"); @@ -101,12 +102,7 @@ namespace PrecastConcretePlantView var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id, - ReinforcedId = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["ReinforcedId"].Value), - ReinforcedName = DataGridView.SelectedRows[0].Cells["ReinforcedName"].Value.ToString(), - Status = Enum.Parse(DataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(DataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(DataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + }); if (!operationResult) @@ -136,12 +132,6 @@ namespace PrecastConcretePlantView var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id, - ReinforcedId = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["ReinforcedId"].Value), - ReinforcedName = DataGridView.SelectedRows[0].Cells["ReinforcedName"].Value.ToString(), - Status = Enum.Parse(DataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(DataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(DataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }); if (!operationResult) @@ -171,12 +161,7 @@ namespace PrecastConcretePlantView var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id, - ReinforcedId = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["ReinforcedId"].Value), - ReinforcedName = DataGridView.SelectedRows[0].Cells["ReinforcedName"].Value.ToString(), - Status = Enum.Parse(DataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(DataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(DataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + }); if (!operationResult) diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs index d308c19..233bc68 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs @@ -27,53 +27,67 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic public bool CreateOrder(OrderBindingModel model) { CheckModel(model); - if (model.Status != OrderStatus.Неизвестен) { _logger.LogWarning("Insert operation failed. Order status incorrect."); return false; } - model.Status = OrderStatus.Принят; - if (_orderStorage.Insert(model) == null) { model.Status = OrderStatus.Неизвестен; _logger.LogWarning("Insert operation failed"); return false; } - return true; } - public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) + public bool StatusUpdate(OrderBindingModel rawModel, OrderStatus newStatus) { - CheckModel(model); + var viewModel = _orderStorage.GetElement(new OrderSearchModel + { + Id = rawModel.Id + }); + if (viewModel == null) + { + _logger.LogWarning("Order model not found"); + return false; + } + + OrderBindingModel model = new OrderBindingModel + { + Id = viewModel.Id, + ReinforcedId = viewModel.ReinforcedId, + Status = viewModel.Status, + DateCreate = viewModel.DateCreate, + DateImplement = viewModel.DateImplement, + Count = viewModel.Count, + Sum = viewModel.Sum + }; + + CheckModel(model, false); if (model.Status + 1 != newStatus) { _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect."); return false; } - model.Status = newStatus; - - if (model.Status == OrderStatus.Выдан) - model.DateImplement = DateTime.Now; - + if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; if (_orderStorage.Update(model) == null) { model.Status--; _logger.LogWarning("Update operation failed"); return false; } - return true; } + public bool TakeOrderInWork(OrderBindingModel model) { return StatusUpdate(model, OrderStatus.Выполняется); } + public bool DeliveryOrder(OrderBindingModel model) { return StatusUpdate(model, OrderStatus.Готов); @@ -83,18 +97,16 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic { return StatusUpdate(model, OrderStatus.Выдан); } + public List? ReadList(OrderSearchModel? model) { - _logger.LogInformation("Order. OrderId:{Id}", model?.Id); - + _logger.LogInformation("Order. OrderID:{Id}", model?.Id); var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); - if (list == null) { _logger.LogWarning("ReadList return null list"); return null; } - _logger.LogInformation("ReadList. Count:{Count}", list.Count); return list; } @@ -104,28 +116,23 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic { throw new ArgumentNullException(nameof(model)); } - if (!withParams) { return; } - if (model.ReinforcedId < 0) { - throw new ArgumentNullException("Некорректный идентификатор изделия", nameof(model.ReinforcedId)); + throw new ArgumentNullException("Некорректный идентификатор документа", nameof(model.ReinforcedId)); } - if (model.Count <= 0) { - throw new ArgumentNullException("Количество изделий в заказе должно быть больше 0", nameof(model.Count)); + throw new ArgumentNullException("Количество документов в заказе должно быть больше 0", nameof(model.Count)); } - if (model.Sum <= 0) { throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); } - - _logger.LogInformation("Order. OrderId:{Id}.Sum:{ Sum}. ReinforcedId: { ReinforcedId}", model.Id, model.Sum, model.ReinforcedId); + _logger.LogInformation("Order. OrderID:{Id}.Sum:{ Sum}. ReinforcedId: { ReinforcedId}", model.Id, model.Sum, model.ReinforcedId); } } } diff --git a/PrecastConcretePlant/PrecastConcretePlantClientApp/Controllers/HomeController.cs b/PrecastConcretePlant/PrecastConcretePlantClientApp/Controllers/HomeController.cs index 51cf194..96767ab 100644 --- a/PrecastConcretePlant/PrecastConcretePlantClientApp/Controllers/HomeController.cs +++ b/PrecastConcretePlant/PrecastConcretePlantClientApp/Controllers/HomeController.cs @@ -9,12 +9,10 @@ namespace PrecastConcretePlantClientApp.Controllers public class HomeController : Controller { private readonly ILogger _logger; - public HomeController(ILogger logger) { _logger = logger; } - public IActionResult Index() { if (APIClient.Client == null) @@ -23,7 +21,6 @@ namespace PrecastConcretePlantClientApp.Controllers } return View(APIClient.GetRequest>($"api/main/getorders?clientId={APIClient.Client.Id}")); } - [HttpGet] public IActionResult Privacy() { @@ -33,7 +30,6 @@ namespace PrecastConcretePlantClientApp.Controllers } return View(APIClient.Client); } - [HttpPost] public void Privacy(string login, string password, string fio) { @@ -45,37 +41,37 @@ namespace PrecastConcretePlantClientApp.Controllers { throw new Exception("Введите логин, пароль и ФИО"); } - APIClient.PostRequest("api/client/updatedata", new ClientBindingModel + APIClient.PostRequest("api/client/updatedata", new + ClientBindingModel { Id = APIClient.Client.Id, ClientFIO = fio, Email = login, Password = password }); - APIClient.Client.ClientFIO = fio; APIClient.Client.Email = login; APIClient.Client.Password = password; Response.Redirect("Index"); } - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { - return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); + return View(new ErrorViewModel + { + RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier + }); } - [HttpGet] public IActionResult Enter() { return View(); } - [HttpPost] public void Enter(string login, string password) { if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)) - { + { throw new Exception("Введите логин и пароль"); } APIClient.Client = APIClient.GetRequest($"api/client/login?login={login}&password={password}"); @@ -85,18 +81,16 @@ namespace PrecastConcretePlantClientApp.Controllers } Response.Redirect("Index"); } - [HttpGet] public IActionResult Register() { return View(); } - [HttpPost] public void Register(string login, string password, string fio) { if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) - { + { throw new Exception("Введите логин, пароль и ФИО"); } APIClient.PostRequest("api/client/register", new ClientBindingModel @@ -108,14 +102,12 @@ namespace PrecastConcretePlantClientApp.Controllers Response.Redirect("Enter"); return; } - [HttpGet] public IActionResult Create() { ViewBag.Reinforcedies = APIClient.GetRequest>("api/main/getreinforcedlist"); return View(); } - [HttpPost] public void Create(int reinforced, int count) { @@ -136,12 +128,11 @@ namespace PrecastConcretePlantClientApp.Controllers }); Response.Redirect("Index"); } - [HttpPost] public double Calc(int count, int reinforced) { - var prod = APIClient.GetRequest($"api/main/getreinforced?reinforcedId={reinforced}"); - return count * (prod?.Price ?? 1); + var doc = APIClient.GetRequest($"api/main/getreinforced?reinforcedId={reinforced}"); + return count * (doc?.Price ?? 1); } } } \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/OrderBindingModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/OrderBindingModel.cs index 7314c8c..f7d54e5 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/OrderBindingModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/OrderBindingModel.cs @@ -13,7 +13,6 @@ namespace PrecastConcretePlantContracts.BindingModels public int Id { get; set; } public int ReinforcedId { get; set; } public int ClientId { get; set; } - public string ReinforcedName { get; set; } = string.Empty; public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/OrderViewModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/OrderViewModel.cs index 9176733..b26d563 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/OrderViewModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/OrderViewModel.cs @@ -11,25 +11,32 @@ namespace PrecastConcretePlantContracts.ViewModels { public class OrderViewModel : IOrderModel { - public int ClientId { get; set; } - public int ReinforcedId { get; set; } [DisplayName("Номер")] public int Id { get; set; } - [DisplayName("Фамилия клиента")] - public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Изделие")] + public int ReinforcedId { get; set; } + + [DisplayName("Документ")] public string ReinforcedName { get; set; } = string.Empty; + public int ClientId { get; set; } + + [DisplayName("ФИО клиента")] + public string ClientFIO { get; set; } = string.Empty; + [DisplayName("Количество")] public int Count { get; set; } + [DisplayName("Сумма")] public double Sum { get; set; } + [DisplayName("Статус")] public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + [DisplayName("Дата создания")] public DateTime DateCreate { get; set; } = DateTime.Now; + [DisplayName("Дата выполнения")] public DateTime? DateImplement { get; set; } - + } } diff --git a/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IOrderModel.cs b/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IOrderModel.cs index ca84013..67f1b72 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IOrderModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IOrderModel.cs @@ -10,7 +10,7 @@ namespace PrecastConcretePlantDataModels.Enums public interface IOrderModel : IId { int ReinforcedId { get; } - string ReinforcedName { get; } + int ClientId { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/OrderStorage.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/OrderStorage.cs index 9bd0500..42050e0 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/OrderStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/OrderStorage.cs @@ -1,4 +1,5 @@ -using PrecastConcretePlantContracts.BindingModels; +using Microsoft.EntityFrameworkCore; +using PrecastConcretePlantContracts.BindingModels; using PrecastConcretePlantContracts.SearchModels; using PrecastConcretePlantContracts.StoragesContracts; using PrecastConcretePlantContracts.ViewModels; @@ -13,86 +14,80 @@ namespace PrecastConcretePlantDatabaseImplement.Implements { public class OrderStorage : IOrderStorage { - public OrderViewModel? Delete(OrderBindingModel model) - { - using var context = new PrecastConcretePlantDataBase(); - - var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id); - - if (element != null) - { - context.Orders.Remove(element); - context.SaveChanges(); - - return element.GetViewModel; - } - - return null; - } - public OrderViewModel? GetElement(OrderSearchModel model) { if (!model.Id.HasValue) { return null; } - using var context = new PrecastConcretePlantDataBase(); - - return context.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + return context.Orders.Include(x => x.Reinforced).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } public List GetFilteredList(OrderSearchModel model) { - if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue) + if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue) { return new(); } - using var context = new PrecastConcretePlantDataBase(); - - return context.Orders.Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo).Select(x => x.GetViewModel).ToList(); + if (model.ClientId.HasValue) + { + return context.Orders + .Include(x => x.Client) + .Where(x => x.ClientId == model.ClientId) + .Select(x => x.GetViewModel) + .ToList(); + } + return context.Orders + .Include(x => x.Reinforced) + .Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo) + .Select(x => x.GetViewModel) + .ToList(); } public List GetFullList() { using var context = new PrecastConcretePlantDataBase(); - - return context.Orders.Select(x => x.GetViewModel).ToList(); + return context.Orders.Include(x => x.Reinforced).Select(x => x.GetViewModel).ToList(); } public OrderViewModel? Insert(OrderBindingModel model) { var newOrder = Order.Create(model); - if (newOrder == null) { return null; } - using var context = new PrecastConcretePlantDataBase(); - context.Orders.Add(newOrder); context.SaveChanges(); - - return newOrder.GetViewModel; + return context.Orders.Include(x => x.Reinforced).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel; } public OrderViewModel? Update(OrderBindingModel model) { using var context = new PrecastConcretePlantDataBase(); - var order = context.Orders.FirstOrDefault(x => x.Id == model.Id); - if (order == null) { return null; } - order.Update(model); context.SaveChanges(); - - return order.GetViewModel; + return context.Orders.Include(x => x.Reinforced).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + } + public OrderViewModel? Delete(OrderBindingModel model) + { + using var context = new PrecastConcretePlantDataBase(); + var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Orders.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; } } } diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230326191118_Restart.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230327202214_Restart.Designer.cs similarity index 95% rename from PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230326191118_Restart.Designer.cs rename to PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230327202214_Restart.Designer.cs index 7ab0208..f42e9d3 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230326191118_Restart.Designer.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230327202214_Restart.Designer.cs @@ -12,7 +12,7 @@ using PrecastConcretePlantDatabaseImplement; namespace PrecastConcretePlantDatabaseImplement.Migrations { [DbContext(typeof(PrecastConcretePlantDataBase))] - [Migration("20230326191118_Restart")] + [Migration("20230327202214_Restart")] partial class Restart { /// @@ -78,7 +78,7 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property("ClientId") + b.Property("ClientId") .HasColumnType("int"); b.Property("Count") @@ -93,10 +93,6 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations b.Property("ReinforcedId") .HasColumnType("int"); - b.Property("ReinforcedName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - b.Property("Status") .HasColumnType("int"); @@ -160,9 +156,11 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b => { - b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Client", null) + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Client", "Client") .WithMany("Orders") - .HasForeignKey("ClientId"); + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced") .WithMany("Orders") @@ -170,6 +168,8 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.Navigation("Client"); + b.Navigation("Reinforced"); }); diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230326191118_Restart.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230327202214_Restart.cs similarity index 97% rename from PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230326191118_Restart.cs rename to PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230327202214_Restart.cs index 567482c..df8cbd5 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230326191118_Restart.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230327202214_Restart.cs @@ -61,13 +61,12 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), ReinforcedId = table.Column(type: "int", nullable: false), - ReinforcedName = table.Column(type: "nvarchar(max)", nullable: false), + ClientId = table.Column(type: "int", nullable: false), Count = table.Column(type: "int", nullable: false), Sum = table.Column(type: "float", nullable: false), Status = table.Column(type: "int", nullable: false), DateCreate = table.Column(type: "datetime2", nullable: false), - DateImplement = table.Column(type: "datetime2", nullable: true), - ClientId = table.Column(type: "int", nullable: true) + DateImplement = table.Column(type: "datetime2", nullable: true) }, constraints: table => { @@ -76,7 +75,8 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations name: "FK_Orders_Clients_ClientId", column: x => x.ClientId, principalTable: "Clients", - principalColumn: "Id"); + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Orders_Reinforcedies_ReinforcedId", column: x => x.ReinforcedId, diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/PrecastConcretePlantDataBaseModelSnapshot.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/PrecastConcretePlantDataBaseModelSnapshot.cs index 4ac8cd3..884e47b 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/PrecastConcretePlantDataBaseModelSnapshot.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/PrecastConcretePlantDataBaseModelSnapshot.cs @@ -75,7 +75,7 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property("ClientId") + b.Property("ClientId") .HasColumnType("int"); b.Property("Count") @@ -90,10 +90,6 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations b.Property("ReinforcedId") .HasColumnType("int"); - b.Property("ReinforcedName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - b.Property("Status") .HasColumnType("int"); @@ -157,9 +153,11 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b => { - b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Client", null) + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Client", "Client") .WithMany("Orders") - .HasForeignKey("ClientId"); + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced") .WithMany("Orders") @@ -167,6 +165,8 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.Navigation("Client"); + b.Navigation("Reinforced"); }); diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Order.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Order.cs index 947b899..c46cc95 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Order.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Order.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; +using System.Reflection.Metadata; using System.Text; using System.Threading.Tasks; @@ -13,26 +14,22 @@ namespace PrecastConcretePlantDatabaseImplement.Models public class Order : IOrderModel { public int Id { get; private set; } - + [Required] public int ReinforcedId { get; private set; } - - public string ReinforcedName { get; private set; } = string.Empty; - + [Required] + public int ClientId { get; private set; } [Required] public int Count { get; private set; } - [Required] public double Sum { get; private set; } - [Required] public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; - [Required] public DateTime DateCreate { get; private set; } = DateTime.Now; public DateTime? DateImplement { get; private set; } - public virtual Reinforced Reinforced { get; set; } + public virtual Client Client { get; set; } public static Order? Create(OrderBindingModel? model) { @@ -40,17 +37,16 @@ namespace PrecastConcretePlantDatabaseImplement.Models { return null; } - - return new Order() + return new Order { - Id = model.Id, ReinforcedId = model.ReinforcedId, - ReinforcedName = model.ReinforcedName, + ClientId = model.ClientId, Count = model.Count, Sum = model.Sum, Status = model.Status, DateCreate = model.DateCreate, - DateImplement = model.DateImplement + DateImplement = model.DateImplement, + Id = model.Id, }; } @@ -60,26 +56,30 @@ namespace PrecastConcretePlantDatabaseImplement.Models { return; } - - ReinforcedId = model.ReinforcedId; - ReinforcedName = model.ReinforcedName; - Count = model.Count; - Sum = model.Sum; Status = model.Status; - DateCreate = model.DateCreate; DateImplement = model.DateImplement; } - public OrderViewModel GetViewModel => new() + public OrderViewModel GetViewModel { - Id = Id, - ReinforcedId = ReinforcedId, - ReinforcedName = ReinforcedName, - Count = Count, - Sum = Sum, - Status = Status, - DateCreate = DateCreate, - DateImplement = DateImplement - }; + get + { + var context = new PrecastConcretePlantDataBase(); + return new() + { + + ReinforcedId = ReinforcedId, + ClientId = ClientId, + Count = Count, + Sum = Sum, + DateCreate = DateCreate, + DateImplement = DateImplement, + Id = Id, + Status = Status, + ReinforcedName = context.Reinforcedies.FirstOrDefault(x => x.Id == ReinforcedId)?.ReinforcedName ?? string.Empty, + ClientFIO = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty + }; + } + } } } diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Order.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Order.cs index a557d3e..e8bd5b8 100644 --- a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Order.cs +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Order.cs @@ -15,8 +15,6 @@ namespace PrecastConcretePlantFileImplement.Models public int ReinforcedId { get; private set; } public int ClientId { get; set; } - public string ReinforcedName { get; private set; } = string.Empty; - public int Count { get; private set; } public double Sum { get; private set; } @@ -39,7 +37,6 @@ namespace PrecastConcretePlantFileImplement.Models { Id = model.Id, ReinforcedId = model.ReinforcedId, - ReinforcedName = model.ReinforcedName, ClientId = model.ClientId, Count = model.Count, Sum = model.Sum, @@ -61,7 +58,6 @@ namespace PrecastConcretePlantFileImplement.Models Id = Convert.ToInt32(element.Attribute("Id")!.Value), ReinforcedId = Convert.ToInt32(element.Element("ReinforcedId")!.Value), ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), - ReinforcedName = element.Element("ReinforcedName")!.Value, Count = Convert.ToInt32(element.Element("Count")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value), Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), @@ -81,7 +77,6 @@ namespace PrecastConcretePlantFileImplement.Models return; } ReinforcedId = model.ReinforcedId; - ReinforcedName = model.ReinforcedName; Count = model.Count; Sum = model.Sum; Status = model.Status; @@ -105,7 +100,6 @@ namespace PrecastConcretePlantFileImplement.Models public XElement GetXElement => new("Order", new XAttribute("Id", Id), - new XElement("ReinforcedName", ReinforcedName), new XElement("ReinforcedId", ReinforcedId.ToString()), new XElement("ClientId", ClientId), new XElement("Count", Count.ToString()), diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Order.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Order.cs index 443737b..ed5376d 100644 --- a/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Order.cs +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Order.cs @@ -15,7 +15,6 @@ namespace PrecastConcretePlantListImplement.Models { public int ReinforcedId { get; private set; } public int ClientId { get; private set; } - public string ReinforcedName { get; private set; } public int Count { get; private set; } @@ -40,7 +39,6 @@ namespace PrecastConcretePlantListImplement.Models Id = model.Id, ReinforcedId = model.ReinforcedId, ClientId = model.ClientId, - ReinforcedName = model.ReinforcedName, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -56,7 +54,6 @@ namespace PrecastConcretePlantListImplement.Models return; } ReinforcedId = model.ReinforcedId; - ReinforcedName = model.ReinforcedName; Count = model.Count; Sum = model.Sum; Status = model.Status; @@ -69,7 +66,6 @@ namespace PrecastConcretePlantListImplement.Models Id = Id, ReinforcedId = ReinforcedId, ClientId = ClientId, - ReinforcedName = ReinforcedName, Count = Count, Sum = Sum, Status = Status, diff --git a/PrecastConcretePlant/PrecastConcretePlantRestApi/Properties/launchSettings.json b/PrecastConcretePlant/PrecastConcretePlantRestApi/Properties/launchSettings.json index d9ddb8b..ef1a34b 100644 --- a/PrecastConcretePlant/PrecastConcretePlantRestApi/Properties/launchSettings.json +++ b/PrecastConcretePlant/PrecastConcretePlantRestApi/Properties/launchSettings.json @@ -1,23 +1,14 @@ -{ - "$schema": "https://json.schemastore.org/launchsettings.json", - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:43427", - "sslPort": 44365 - } - }, +{ "profiles": { "PrecastConcretePlantRestApi": { "commandName": "Project", - "dotnetRunMessages": true, "launchBrowser": true, "launchUrl": "swagger", - "applicationUrl": "https://localhost:7197;http://localhost:5197", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" - } + }, + "dotnetRunMessages": true, + "applicationUrl": "https://localhost:7197;http://localhost:5197" }, "IIS Express": { "commandName": "IISExpress", @@ -27,5 +18,14 @@ "ASPNETCORE_ENVIRONMENT": "Development" } } + }, + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:64248/", + "sslPort": 44372 + } } -} +} \ No newline at end of file