РАБОТАЕТ!!!!!!!!
This commit is contained in:
parent
d1325fb0bc
commit
f8e9e27f73
@ -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;
|
||||||
|
@ -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; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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,31 +52,41 @@ 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)
|
|
||||||
{
|
{
|
||||||
return null;
|
if (newOrder == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
using var context = new ComputersShopDataBase();
|
||||||
|
|
||||||
|
context.Orders.Add(newOrder);
|
||||||
|
context.SaveChanges();
|
||||||
}
|
}
|
||||||
|
catch (DbUpdateException ex)
|
||||||
using var context = new ComputersShopDataBase();
|
{
|
||||||
|
var innerException = ex.InnerException;
|
||||||
context.Orders.Add(newOrder);
|
while (innerException != null)
|
||||||
context.SaveChanges();
|
{
|
||||||
|
Console.WriteLine(innerException.Message);
|
||||||
return newOrder.GetViewModel;
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user