Fix new barcode not saved when adding existing item to transaction
This commit is contained in:
parent
60c48ce952
commit
cd77aaf313
@ -10,6 +10,7 @@ public class AppDbContext : DbContext
|
||||
}
|
||||
|
||||
public DbSet<Item> Items => Set<Item>();
|
||||
public DbSet<ItemBarcode> ItemBarcodes => Set<ItemBarcode>();
|
||||
public DbSet<ItemPurchase> ItemPurchases => Set<ItemPurchase>();
|
||||
public DbSet<ItemTagQuantity> ItemTagQuantities => Set<ItemTagQuantity>();
|
||||
public DbSet<List> Lists => Set<List>();
|
||||
@ -28,7 +29,6 @@ public class AppDbContext : DbContext
|
||||
|
||||
modelBuilder.Entity<ItemBarcode>(entity =>
|
||||
{
|
||||
entity.ToTable("item_barcodes");
|
||||
entity.HasKey(e => new { e.ItemId, e.BarcodeData });
|
||||
|
||||
entity.Property(e => e.Format)
|
||||
|
@ -142,7 +142,13 @@ public class TransactionsController : Controller
|
||||
var item = new Item(itemId, brand, name);
|
||||
if (barcodeData != null && barcodeFormat != null)
|
||||
{
|
||||
item.Barcodes.Add(new ItemBarcode(itemId, barcodeData.Value, barcodeFormat));
|
||||
var barcode = new ItemBarcode(itemId, barcodeData.Value, barcodeFormat);
|
||||
item.Barcodes.Add(barcode);
|
||||
|
||||
if (!await dbContext.ItemBarcodes.ContainsAsync(barcode))
|
||||
{
|
||||
dbContext.ItemBarcodes.Add(barcode);
|
||||
}
|
||||
}
|
||||
|
||||
dbContext.Items.Attach(item);
|
||||
|
Loading…
x
Reference in New Issue
Block a user