public void Create(Operation operation) { db.Operations.Add(operation); db.Entry(operation).State = EntityState.Added; if (operation.Action == "transfer") { var billFrom = db.Bills.Find(operation.BillFromId); billFrom.Amount = billFrom.Amount - operation.Amount; db.Entry(billFrom).State = EntityState.Modified; var billTo = db.Bills.Find(operation.BillToId); billTo.Amount = billTo.Amount + operation.Amount; db.Entry(billTo).State = EntityState.Modified; } db.SaveChanges(); }
public void Save() { db.SaveChanges(); }