public buy getApprovedBuy(long productID, DateTime date, string storeName) { buy buy; using (var ctx = new approvedBuysContext()) { buy = ctx.Buys.FirstOrDefault(b => b.productID == productID && b.date == date && b.storeName == storeName); } return(buy); }
public List <buy> getApprovedBuys() { List <buy> Buys = new List <buy>(); using (var ctx = new approvedBuysContext()) { Buys = ctx.Buys.ToList(); } return(Buys); }
public void updateAppruvedBuy(buy newBuy) { buy buy; using (var ctx = new approvedBuysContext()) { buy = ctx.Buys.FirstOrDefault(b => b.productID == newBuy.productID && b.date == newBuy.date && b.storeName == newBuy.storeName); buy.DeepCopy(newBuy); ctx.SaveChanges(); } }
public void addApprovedBuy(buy newBuy) { try { using (var ctx = new approvedBuysContext()) { ctx.Buys.Add(newBuy); ctx.SaveChanges(); } } catch (Exception e) { buy buy = getApprovedBuy(newBuy.productID, newBuy.date, newBuy.storeName); float pricePerOne = buy.price / buy.amount; buy.amount += newBuy.amount; buy.price += pricePerOne; updateAppruvedBuy(buy); } }