Очень надеюсь, что финиш.
This commit is contained in:
parent
e2034af97d
commit
400b9350cd
@ -13,6 +13,6 @@ namespace BlacksmithWorkshopContracts.ViewModels
|
||||
public int TotalCount { get; set; }
|
||||
|
||||
//список кортежей
|
||||
public List<(string Manufacure, int Count)> WorkPieces { get; set; } = new();
|
||||
public List<(string WorkPiece, int Count)> WorkPieces { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -23,10 +23,16 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
// для отображения КОРРЕКТНОЙ ViewModel-и
|
||||
var deletedElement = context.Orders
|
||||
.Include(x => x.Manufacture)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
|
||||
context.Orders.Remove(element);
|
||||
context.SaveChanges();
|
||||
|
||||
return element.GetViewModel;
|
||||
return deletedElement;
|
||||
}
|
||||
|
||||
return null;
|
||||
@ -72,36 +78,13 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
|
||||
.ToList();
|
||||
}
|
||||
|
||||
private static OrderViewModel GetViewModel(Order order)
|
||||
{
|
||||
var viewModel = order.GetViewModel;
|
||||
|
||||
using var context = new BlacksmithWorkshopDatabase();
|
||||
|
||||
var element = context.Manufactures
|
||||
.FirstOrDefault(x => x.Id == order.ManufactureId);
|
||||
|
||||
viewModel.ManufactureName = element.ManufactureName;
|
||||
|
||||
return viewModel;
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
using var context = new BlacksmithWorkshopDatabase();
|
||||
|
||||
return context.Orders
|
||||
.Select(x => new OrderViewModel
|
||||
{
|
||||
Id = x.Id,
|
||||
ManufactureId = x.ManufactureId,
|
||||
Count = x.Count,
|
||||
Sum = x.Sum,
|
||||
Status = x.Status,
|
||||
DateCreate = x.DateCreate,
|
||||
DateImplement = x.DateImplement,
|
||||
ManufactureName = x.Manufacture.ManufactureName
|
||||
})
|
||||
.Include(x => x.Manufacture)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
@ -119,7 +102,10 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
|
||||
context.Orders.Add(newOrder);
|
||||
context.SaveChanges();
|
||||
|
||||
return newOrder.GetViewModel;
|
||||
return context.Orders
|
||||
.Include(x => x.Manufacture)
|
||||
.FirstOrDefault(x => x.Id == newOrder.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
@ -135,7 +121,10 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
|
||||
order.Update(model);
|
||||
context.SaveChanges();
|
||||
|
||||
return order.GetViewModel;
|
||||
return context.Orders
|
||||
.Include(x => x.Manufacture)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user