示例#1
0
        public List <buy> getUnapprovedBuys()
        {
            List <buy> Buys = new List <buy>();

            using (var ctx = new unapprovedBuysContext())
            {
                Buys = ctx.Buys.ToList();
            }
            return(Buys);
        }
示例#2
0
        public buy getUnapprovedBuy(long productID, DateTime date, string storeName)
        {
            buy buy;

            using (var ctx = new unapprovedBuysContext())
            {
                buy = ctx.Buys.FirstOrDefault(b => b.productID == productID && b.date == date && b.storeName == storeName);
            }
            return(buy);
        }
示例#3
0
        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();
            }
        }
示例#4
0
        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();
            }
        }
示例#5
0
 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);
     }
 }