Bondarenko M.S. Lab Work 3 hard #13

Closed
maxnes3 wants to merge 8 commits from LabWork_03_hard into LabWork_02_hard
3 changed files with 28 additions and 17 deletions
Showing only changes of commit f8e9e27f73 - Show all commits

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,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<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);
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)