diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs index 17fc279..4940643 100644 --- a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -52,7 +52,7 @@ namespace ComputersShopBusinessLogic.BusinessLogics return false; } model.Status = newStatus; - if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.Now; + if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc); else { model.DateImplement = viewModel.DateImplement; diff --git a/ComputersShop/ComputersShopContracts/BindingModels/OrderBindingModel.cs b/ComputersShop/ComputersShopContracts/BindingModels/OrderBindingModel.cs index b07eaa5..f6f11c6 100644 --- a/ComputersShop/ComputersShopContracts/BindingModels/OrderBindingModel.cs +++ b/ComputersShop/ComputersShopContracts/BindingModels/OrderBindingModel.cs @@ -15,7 +15,7 @@ namespace ComputersShopContracts.BindingModels public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - public DateTime DateCreate { get; set; } = DateTime.Now; + public DateTime DateCreate { get; set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc); public DateTime? DateImplement { get; set; } } } diff --git a/ComputersShop/ComputersShopDataBaseImplement/Implements/OrderStorage.cs b/ComputersShop/ComputersShopDataBaseImplement/Implements/OrderStorage.cs index 158598f..db6ffc2 100644 --- a/ComputersShop/ComputersShopDataBaseImplement/Implements/OrderStorage.cs +++ b/ComputersShop/ComputersShopDataBaseImplement/Implements/OrderStorage.cs @@ -3,6 +3,7 @@ using ComputersShopContracts.SearchModels; using ComputersShopContracts.StoragesContracts; using ComputersShopContracts.ViewModels; using ComputersShopDataBaseImplement.Models; +using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; @@ -24,7 +25,7 @@ namespace ComputersShopDataBaseImplement.Implements context.Orders.Remove(element); context.SaveChanges(); - return element.GetViewModel; + return GetViewModel(element); } return null; @@ -39,7 +40,7 @@ namespace ComputersShopDataBaseImplement.Implements using var context = new ComputersShopDataBase(); - return context.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + return GetViewModel(context.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))); } public List GetFilteredList(OrderSearchModel model) @@ -51,31 +52,41 @@ namespace ComputersShopDataBaseImplement.Implements using var context = new ComputersShopDataBase(); - return context.Orders.Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList(); + return context.Orders.Where(x => x.Id == model.Id).Select(x => GetViewModel(x)).ToList(); } public List GetFullList() { using var context = new ComputersShopDataBase(); - return context.Orders.Select(x => x.GetViewModel).ToList(); + return context.Orders.Select(x => GetViewModel(x)).ToList(); } public OrderViewModel? Insert(OrderBindingModel model) { var newOrder = Order.Create(model); - - if (newOrder == null) + try { - return null; + if (newOrder == null) + { + return null; + } + + using var context = new ComputersShopDataBase(); + + context.Orders.Add(newOrder); + context.SaveChanges(); } - - using var context = new ComputersShopDataBase(); - - context.Orders.Add(newOrder); - context.SaveChanges(); - - return newOrder.GetViewModel; + catch (DbUpdateException ex) + { + var innerException = ex.InnerException; + while (innerException != null) + { + Console.WriteLine(innerException.Message); + innerException = innerException.InnerException; + } + } + return GetViewModel(newOrder); } public OrderViewModel? Update(OrderBindingModel model) @@ -92,7 +103,7 @@ namespace ComputersShopDataBaseImplement.Implements order.Update(model); context.SaveChanges(); - return order.GetViewModel; + return GetViewModel(order); } private static OrderViewModel GetViewModel(Order order)