public void updateUnappruvedBuy(buy newBuy) { buy buy; using (var ctx = new unapprovedBuysContext()) { buy = ctx.Buys.FirstOrDefault(b => b.productID == newBuy.productID && b.date == newBuy.date && b.storeName == newBuy.storeName); buy.DeepCopy(newBuy); ctx.SaveChanges(); } }
public void deleteUnapprovedBuy(buy buy) { buy buyToDelete; using (var ctx = new unapprovedBuysContext()) { buyToDelete = ctx.Buys.FirstOrDefault(b => b.productID == buy.productID && b.date == buy.date && b.storeName == buy.storeName); ctx.Buys.Remove(buyToDelete); ctx.SaveChanges(); } }
public void addUnapprovedBuy(buy newBuy) { try { using (var ctx = new unapprovedBuysContext()) { ctx.Buys.Add(newBuy); ctx.SaveChanges(); } } catch (Exception e) { buy buy = getUnapprovedBuy(newBuy.productID, newBuy.date, newBuy.storeName); float pricePerOne = buy.price / buy.amount; buy.amount += 1; buy.price += pricePerOne; updateUnappruvedBuy(buy); } }