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,6 +16,7 @@ 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,6 +71,7 @@ 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;
} }
} }

View File

@ -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,

View File

@ -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,6 +48,7 @@ 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)
.Include(x => x.Client)
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }
@ -51,6 +56,7 @@ namespace ConfectioneryDatabaseImplement.Implements
{ {
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;