fix
This commit is contained in:
parent
08cd7160fd
commit
c1e1972d3a
@ -16,7 +16,8 @@ namespace ConfectioneryDatabaseImplement.Implements
|
|||||||
if (res != null)
|
if (res != null)
|
||||||
{
|
{
|
||||||
context.Clients.Remove(res);
|
context.Clients.Remove(res);
|
||||||
}
|
context.SaveChanges();
|
||||||
|
}
|
||||||
return res?.GetViewModel;
|
return res?.GetViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +71,8 @@ namespace ConfectioneryDatabaseImplement.Implements
|
|||||||
if (res != null)
|
if (res != null)
|
||||||
{
|
{
|
||||||
context.Clients.Add(res);
|
context.Clients.Add(res);
|
||||||
}
|
context.SaveChanges();
|
||||||
|
}
|
||||||
return res?.GetViewModel;
|
return res?.GetViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,6 +81,7 @@ namespace ConfectioneryDatabaseImplement.Implements
|
|||||||
using var context = new ConfectioneryDatabase();
|
using var context = new ConfectioneryDatabase();
|
||||||
var res = context.Clients.FirstOrDefault(x => x.Id == model.Id);
|
var res = context.Clients.FirstOrDefault(x => x.Id == model.Id);
|
||||||
res?.Update(model);
|
res?.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
return res?.GetViewModel;
|
return res?.GetViewModel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,8 @@ namespace ConfectioneryDatabaseImplement.Models
|
|||||||
return new()
|
return new()
|
||||||
{
|
{
|
||||||
PastryName = context.Pastries.FirstOrDefault(x => x.Id == PastryId)?.PastryName ?? string.Empty,
|
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,
|
PastryId = PastryId,
|
||||||
Count = Count,
|
Count = Count,
|
||||||
Sum = Sum,
|
Sum = Sum,
|
||||||
|
@ -3,6 +3,7 @@ using ConfectioneryContracts.SearchModels;
|
|||||||
using ConfectioneryContracts.StoragesContract;
|
using ConfectioneryContracts.StoragesContract;
|
||||||
using ConfectioneryContracts.ViewModels;
|
using ConfectioneryContracts.ViewModels;
|
||||||
using ConfectioneryDatabaseImplement.Models;
|
using ConfectioneryDatabaseImplement.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System.Security.Cryptography.X509Certificates;
|
using System.Security.Cryptography.X509Certificates;
|
||||||
|
|
||||||
namespace ConfectioneryDatabaseImplement.Implements
|
namespace ConfectioneryDatabaseImplement.Implements
|
||||||
@ -12,7 +13,7 @@ namespace ConfectioneryDatabaseImplement.Implements
|
|||||||
public OrderViewModel? Delete(OrderBindingModel model)
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new ConfectioneryDatabase();
|
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)
|
if (element != null)
|
||||||
{
|
{
|
||||||
context.Orders.Remove(element);
|
context.Orders.Remove(element);
|
||||||
@ -29,7 +30,10 @@ namespace ConfectioneryDatabaseImplement.Implements
|
|||||||
{
|
{
|
||||||
return null;
|
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)
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
@ -44,13 +48,15 @@ namespace ConfectioneryDatabaseImplement.Implements
|
|||||||
{
|
{
|
||||||
return context.Orders
|
return context.Orders
|
||||||
.Where(x => model.DateFrom <= x.DateCreate.Date && x.DateCreate <= model.DateTo)
|
.Where(x => model.DateFrom <= x.DateCreate.Date && x.DateCreate <= model.DateTo)
|
||||||
.Select(x => x.GetViewModel)
|
.Include(x => x.Client)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
if (model.ClientId.HasValue)
|
if (model.ClientId.HasValue)
|
||||||
{
|
{
|
||||||
return context.Orders
|
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)
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
@ -61,6 +67,7 @@ namespace ConfectioneryDatabaseImplement.Implements
|
|||||||
{
|
{
|
||||||
using var context = new ConfectioneryDatabase();
|
using var context = new ConfectioneryDatabase();
|
||||||
return context.Orders
|
return context.Orders
|
||||||
|
.Include(x => x.Client)
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
@ -81,7 +88,9 @@ namespace ConfectioneryDatabaseImplement.Implements
|
|||||||
public OrderViewModel? Update(OrderBindingModel model)
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new ConfectioneryDatabase();
|
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)
|
if (order == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
Reference in New Issue
Block a user