РАБОТАЕТ!!!!!!!!

This commit is contained in:
maxnes3 2023-02-28 01:00:56 +04:00
parent d1325fb0bc
commit f8e9e27f73
3 changed files with 28 additions and 17 deletions

View File

@ -52,7 +52,7 @@ namespace ComputersShopBusinessLogic.BusinessLogics
return false; return false;
} }
model.Status = newStatus; model.Status = newStatus;
if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.Now; if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
else else
{ {
model.DateImplement = viewModel.DateImplement; model.DateImplement = viewModel.DateImplement;

View File

@ -15,7 +15,7 @@ namespace ComputersShopContracts.BindingModels
public int Count { get; set; } public int Count { get; set; }
public double Sum { get; set; } public double Sum { get; set; }
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; 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; } public DateTime? DateImplement { get; set; }
} }
} }

View File

@ -3,6 +3,7 @@ using ComputersShopContracts.SearchModels;
using ComputersShopContracts.StoragesContracts; using ComputersShopContracts.StoragesContracts;
using ComputersShopContracts.ViewModels; using ComputersShopContracts.ViewModels;
using ComputersShopDataBaseImplement.Models; using ComputersShopDataBaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -24,7 +25,7 @@ namespace ComputersShopDataBaseImplement.Implements
context.Orders.Remove(element); context.Orders.Remove(element);
context.SaveChanges(); context.SaveChanges();
return element.GetViewModel; return GetViewModel(element);
} }
return null; return null;
@ -39,7 +40,7 @@ namespace ComputersShopDataBaseImplement.Implements
using var context = new ComputersShopDataBase(); 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<OrderViewModel> GetFilteredList(OrderSearchModel model) public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
@ -51,20 +52,21 @@ namespace ComputersShopDataBaseImplement.Implements
using var context = new ComputersShopDataBase(); 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<OrderViewModel> GetFullList() public List<OrderViewModel> GetFullList()
{ {
using var context = new ComputersShopDataBase(); 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) public OrderViewModel? Insert(OrderBindingModel model)
{ {
var newOrder = Order.Create(model); var newOrder = Order.Create(model);
try
{
if (newOrder == null) if (newOrder == null)
{ {
return null; return null;
@ -74,8 +76,17 @@ namespace ComputersShopDataBaseImplement.Implements
context.Orders.Add(newOrder); context.Orders.Add(newOrder);
context.SaveChanges(); 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) public OrderViewModel? Update(OrderBindingModel model)
@ -92,7 +103,7 @@ namespace ComputersShopDataBaseImplement.Implements
order.Update(model); order.Update(model);
context.SaveChanges(); context.SaveChanges();
return order.GetViewModel; return GetViewModel(order);
} }
private static OrderViewModel GetViewModel(Order order) private static OrderViewModel GetViewModel(Order order)