Попытка исправить ошибку миграции.

This commit is contained in:
Programmist73 2023-03-24 10:52:44 +04:00
parent a2760750d5
commit 6870753d1a
4 changed files with 17 additions and 14 deletions

View File

@ -18,6 +18,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
{
using var context = new BlacksmithWorkshopDatabase();
var element = context.Orders
.Include(x => x.Manufacture)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
@ -41,6 +42,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
using var context = new BlacksmithWorkshopDatabase();
return context.Orders
.Include(x => x.Manufacture)
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
?.GetViewModel;
}
@ -84,14 +86,16 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
context.Orders.Add(newOrder);
context.SaveChanges();
return context.Orders.Include(x => x.Manufacture)
.FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel;
return context.Orders
.Include(x => x.Manufacture)
.FirstOrDefault(x => x.Id == newOrder.Id)
?.GetViewModel;
}
public OrderViewModel? Update(OrderBindingModel model)
{
using var context = new BlacksmithWorkshopDatabase();
var order = context.Orders.FirstOrDefault(x => x.Id == model.Id);
var order = context.Orders.Include(x => x.Manufacture).FirstOrDefault(x => x.Id == model.Id);
if (order == null)
{

View File

@ -79,8 +79,6 @@ namespace BlacksmithWorkshopDatabaseImplement.Models
ManufactureWorkPieces = ManufactureWorkPieces
};
Dictionary<int, (IWorkPieceModel, int)> IManufactureModel.ManufactureWorkPieces => throw new NotImplementedException();
public void UpdateWorkPieces(BlacksmithWorkshopDatabase context, ManufactureBindingModel model)
{
var manufactureWorkPieces = context.ManufactureWorkPieces.Where(rec => rec.ManufactureId == model.Id).ToList();
@ -103,13 +101,13 @@ namespace BlacksmithWorkshopDatabaseImplement.Models
var manufacture = context.Manufactures.First(x => x.Id == Id);
foreach (var pc in model.ManufactureWorkPieces)
foreach (var mwp in model.ManufactureWorkPieces)
{
context.ManufactureWorkPieces.Add(new ManufactureWorkPiece
{
Manufacture = manufacture,
WorkPiece = context.WorkPieces.First(x => x.Id == pc.Key),
Count = pc.Value.Item2
WorkPiece = context.WorkPieces.First(x => x.Id == mwp.Key),
Count = mwp.Value.Item2
});
context.SaveChanges();

View File

@ -26,10 +26,10 @@ namespace BlacksmithWorkshopDatabaseImplement.Models
public double Sum { get; private set; }
[Required]
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
public OrderStatus Status { get; private set; }
[Required]
public DateTime DateCreate { get; private set; } = DateTime.Now;
public DateTime DateCreate { get; private set; }
public DateTime? DateImplement { get; private set; }

View File

@ -21,7 +21,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Models
[Required]
public string Address { get; private set; } = string.Empty;
public DateTime DateOpen { get; private set; } = DateTime.Now;
[Required]
public DateTime DateOpen { get; private set; }
[Required]
public int MaxCountManufactures { get; private set; }
@ -110,13 +111,13 @@ namespace BlacksmithWorkshopDatabaseImplement.Models
var shop = context.Shops.First(x => x.Id == Id);
foreach (var si in model.ShopManufactures)
foreach (var sm in model.ShopManufactures)
{
context.ShopManufactures.Add(new ShopManufacture
{
Shop = shop,
Manufacture = context.Manufactures.First(x => x.Id == si.Key),
Count = si.Value.Item2
Manufacture = context.Manufactures.First(x => x.Id == sm.Key),
Count = sm.Value.Item2
});
context.SaveChanges();