This commit is contained in:
Данияр Аглиуллов 2023-03-04 20:45:41 +04:00
parent 08cd7160fd
commit c1e1972d3a
3 changed files with 21 additions and 8 deletions

View File

@ -16,7 +16,8 @@ namespace ConfectioneryDatabaseImplement.Implements
if (res != null)
{
context.Clients.Remove(res);
}
context.SaveChanges();
}
return res?.GetViewModel;
}
@ -70,7 +71,8 @@ namespace ConfectioneryDatabaseImplement.Implements
if (res != null)
{
context.Clients.Add(res);
}
context.SaveChanges();
}
return res?.GetViewModel;
}
@ -79,6 +81,7 @@ namespace ConfectioneryDatabaseImplement.Implements
using var context = new ConfectioneryDatabase();
var res = context.Clients.FirstOrDefault(x => x.Id == model.Id);
res?.Update(model);
context.SaveChanges();
return res?.GetViewModel;
}
}

View File

@ -84,7 +84,8 @@ namespace ConfectioneryDatabaseImplement.Models
return new()
{
PastryName = context.Pastries.FirstOrDefault(x => x.Id == PastryId)?.PastryName ?? string.Empty,
ClientFIO = Client.ClientFIO,
// ??????
ClientFIO = Client?.ClientFIO ?? context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty,
PastryId = PastryId,
Count = Count,
Sum = Sum,

View File

@ -3,6 +3,7 @@ using ConfectioneryContracts.SearchModels;
using ConfectioneryContracts.StoragesContract;
using ConfectioneryContracts.ViewModels;
using ConfectioneryDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using System.Security.Cryptography.X509Certificates;
namespace ConfectioneryDatabaseImplement.Implements
@ -12,7 +13,7 @@ namespace ConfectioneryDatabaseImplement.Implements
public OrderViewModel? Delete(OrderBindingModel model)
{
using var context = new ConfectioneryDatabase();
var element = context.Orders.FirstOrDefault(x => x.Id == model.Id);
var element = context.Orders.Include(x => x.Client).FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
context.Orders.Remove(element);
@ -29,7 +30,10 @@ namespace ConfectioneryDatabaseImplement.Implements
{
return null;
}
return context.Orders.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
return context.Orders
.Include(x => x.Client)
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
?.GetViewModel;
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
@ -44,13 +48,15 @@ namespace ConfectioneryDatabaseImplement.Implements
{
return context.Orders
.Where(x => model.DateFrom <= x.DateCreate.Date && x.DateCreate <= model.DateTo)
.Select(x => x.GetViewModel)
.Include(x => x.Client)
.Select(x => x.GetViewModel)
.ToList();
}
if (model.ClientId.HasValue)
{
return context.Orders
.Where(x => x.Client.Id == model.ClientId)
.Where(x => x.Client.Id == model.ClientId)
.Include(x => x.Client)
.Select(x => x.GetViewModel)
.ToList();
}
@ -61,6 +67,7 @@ namespace ConfectioneryDatabaseImplement.Implements
{
using var context = new ConfectioneryDatabase();
return context.Orders
.Include(x => x.Client)
.Select(x => x.GetViewModel)
.ToList();
}
@ -81,7 +88,9 @@ namespace ConfectioneryDatabaseImplement.Implements
public OrderViewModel? Update(OrderBindingModel model)
{
using var context = new ConfectioneryDatabase();
var order = context.Orders.FirstOrDefault(x => x.Id == model.Id);
var order = context.Orders
.Include(x => x.Client)
.FirstOrDefault(x => x.Id == model.Id);
if (order == null)
{
return null;