示例#1
0
 public bool saveCarts(Combo combo)
 {
     try
     {
         foreach (var cartlist in combo.cartlist)
         {
             var dbcart = db.Carts.Where(c => c.ItemsId == cartlist.ItemsId && c.CustomerName == combo.stripe.UserName).SingleOrDefault();
             if (dbcart == null)
             {
                 db.saveNewCart(cartlist.ItemsQunatity, DateTime.Now.Date, cartlist.ItemsId, combo.stripe.UserName);
                 db.SaveChanges();
             }
             else
             {
                 decimal quantity = dbcart.ItemsQunatity;
                 quantity = quantity + Convert.ToDecimal(cartlist.ItemsQunatity);
                 db.updateCart(dbcart.CartId, Convert.ToInt32(quantity));
                 db.SaveChanges();
             }
         }
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
示例#2
0
        public IHttpActionResult save(Cart cart)
        {
            var dbcart = db.Carts.Where(c => c.ItemsId == cart.ItemsId && c.CustomerName == cart.CustomerName).SingleOrDefault();

            if (dbcart == null)
            {
                var dbuser = db.AspNetUsers.Single(usr => usr.UserName == cart.CustomerName);
                if (dbuser != null)
                {
                    cart.DateCreated = DateTime.Now.Date;
                    //System.Diagnostics.Debug.WriteLine(cart.DateCreated);
                    db.saveNewCart(cart.ItemsQunatity, cart.DateCreated, cart.ItemsId, cart.CustomerName);
                    db.SaveChanges();
                    return(Ok());
                }
                return(BadRequest("You Donot Have Permisions"));
            }
            int quantity = dbcart.ItemsQunatity;

            quantity = quantity + cart.ItemsQunatity;
            db.updateCart(dbcart.CartId, quantity);
            db.SaveChanges();
            return(Ok());
        }