public bool UpdateInventoryCost(hooDbContext db, WarehouseCostModel model) { using (var trx = db.Database.BeginTransaction()) { try { var dbWarehouseCost = db.WarehouseCost.Where(w => w.ProductId == model.ProductId).SingleOrDefault(); if (dbWarehouseCost == null) { //Add var warehouseCost = new WarehouseCost(); warehouseCost.Cost = model.Cost; warehouseCost.ProductId = model.ProductId; db.WarehouseCost.Add(warehouseCost); } else { //update dbWarehouseCost.Cost = model.Cost; } db.SaveChanges(); trx.Commit(); } catch (Exception ex) { trx.Rollback(); return(false); } finally { trx.Dispose(); } } return(true); }
public bool UpdateInventoryCost([FromBody] WarehouseCostModel model) { TransactionRepository repo = new TransactionRepository(); return(repo.UpdateInventoryCost(_context, model)); }