Esempio n. 1
0
        public bool UpdateGoodinCart([FromBody] IOSUpdateVM updateInfo)
        {
            AccountGood good = _context.AccountGoods.Where(ag => ag.Account_ID == _context.Users.Where(name => name.Email == updateInfo.Email).Select(i => i.Id).FirstOrDefault() && ag.Type == "cart" && ag.Goods_ID == updateInfo.GoodId).FirstOrDefault();

            switch (updateInfo.UpdateType)
            {
            case "add":
                good.Quantity++;
                _context.SaveChanges();
                return(true);

            case "minus":
                good.Quantity--;
                _context.SaveChanges();
                return(true);

            case "delete":
                _context.AccountGoods.Remove(good);
                _context.SaveChanges();
                return(true);

            default:
                return(false);
            }
        }
Esempio n. 2
0
 public bool IOSAddToCart([FromBody] IOSUpdateVM addInfo)
 {
     //List<AccountGood> accountGoods = _context.AccountGoods.Where(ag => ag.Account_ID == _context.Users.Where(name => name.Email == addInfo.Email).Select(i => i.Id).FirstOrDefault() && ag.Type == "cart").ToList();
     _context.AccountGoods.Add(new AccountGood()
     {
         Account_ID = _context.Users.Where(name => name.Email == addInfo.Email).Select(i => i.Id).FirstOrDefault(),
         Goods_ID   = addInfo.GoodId,
         Order_ID   = ag.GenerateOrderId(),
         Quantity   = 1,
         Type       = "cart",
         Viewed     = true
     });
     _context.SaveChanges();
     return(true);
 }