исравление изменения статусов заказа

This commit is contained in:
bekodeg 2024-04-28 11:49:26 +04:00
parent 46439ae569
commit c69a473c11
2 changed files with 16 additions and 15 deletions

View File

@ -71,9 +71,9 @@ namespace SushiBar.Forms
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id);
try
try
{
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id});
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id });
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");

View File

@ -14,19 +14,20 @@ namespace SushiBarDatabaseImplement.Implements
{
using var context = new SushiBarDatabase();
return context.Orders
.Include(x => x.Sushi)
.Select(x => x.GetViewModel)
.Include(o => o.Sushi)
.Select(o => o.GetViewModel)
.ToList();
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
var result = new List<OrderViewModel>();
var element = GetElement(model);
if (element != null)
{
result.Add(element);
}
return new();
using var context = new SushiBarDatabase();
return context.Orders
.Include(o => o.Sushi)
.Where(o =>
(model.Id.HasValue && o.Id == model.Id) ||
(model.DateFrom.HasValue && model.DateTo.HasValue && model.DateFrom < o.DateCreate && o.DateCreate < model.DateTo))
.Select(o => o.GetViewModel)
.ToList();
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
@ -36,8 +37,8 @@ namespace SushiBarDatabaseImplement.Implements
}
using var context = new SushiBarDatabase();
return context.Orders
.Include (x => x.Sushi)
.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
.Include (o => o.Sushi)
.FirstOrDefault(o => o.Id == model.Id)?.GetViewModel;
}
public OrderViewModel? Insert(OrderBindingModel model)
{
@ -57,7 +58,7 @@ namespace SushiBarDatabaseImplement.Implements
using var transaction = context.Database.BeginTransaction();
try
{
var order = context.Orders.FirstOrDefault(rec =>
var order = context.Orders.Include(o => o.Sushi).FirstOrDefault(rec =>
rec.Id == model.Id);
if (order == null)
{
@ -78,7 +79,7 @@ namespace SushiBarDatabaseImplement.Implements
{
using var context = new SushiBarDatabase();
var element = context.Orders
.FirstOrDefault(x => x.Id == model.Id);
.FirstOrDefault(o => o.Id == model.Id);
if (element != null)
{
context.Orders.Remove(element);