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

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;
}
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;

View File

@ -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; }
}
}

View File

@ -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<OrderViewModel> GetFilteredList(OrderSearchModel model)
@ -51,20 +52,21 @@ 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<OrderViewModel> 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);
try
{
if (newOrder == null)
{
return null;
@ -74,8 +76,17 @@ namespace ComputersShopDataBaseImplement.Implements
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)