public void UpdateOneGoodByBothID(AccountGood accountGood) { AccountGood ag = _context.AccountGoods.Where(a => a.Goods_ID == accountGood.Goods_ID && a.Account_ID == accountGood.Account_ID && a.Type == "cart").FirstOrDefault(); ag.Quantity = accountGood.Quantity; _context.SaveChanges(); }
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); } }
public void DeleteOneGoodinCartByBothID(string accountID, int goodsID) { AccountGood ag = _context.AccountGoods.Where(a => a.Goods_ID == goodsID && a.Account_ID == accountID && a.Type == "cart").FirstOrDefault(); _context.AccountGoods.Remove(ag); _context.SaveChanges(); }
public bool changeQuantityInCart(int id, int quantity) { AccountGood accountGood = _context.AccountGoods.Where(i => i.Account_ID == _userManager.GetUserId(User) && i.Goods_ID == id && i.Type == "cart").FirstOrDefault(); accountGood.Quantity = quantity; _context.SaveChanges(); return(true); }
public void WishToCart(string AccountID, int id) { AccountGood ag = _context.AccountGoods.Where(a => a.Goods_ID == id && a.Account_ID == AccountID && a.Type == "wishlist").FirstOrDefault(); if (_context.AccountGoods.Where(a => a.Goods_ID == id && a.Account_ID == AccountID && a.Type == "cart").FirstOrDefault() == null) { ag.Type = "cart"; } else { _context.AccountGoods.Where(a => a.Goods_ID == id && a.Account_ID == AccountID && a.Type == "cart").FirstOrDefault().Quantity++; } _context.SaveChanges(); }
public bool WishList(int id) { List <AccountGood> accountGoods = _context.AccountGoods.Where(ag => ag.Account_ID == User.getUserId()).ToList(); AccountGood item = accountGoods.Where(ag => ag.Goods_ID == id && ag.Type == "wishlist").FirstOrDefault(); if (item == null) { AccountGood temp = new AccountGood() { Order_ID = ag.GenerateOrderId(), Account_ID = _context.Users.Where(name => name.UserName == User.Identity.Name).Select(i => i.Id).FirstOrDefault(), Goods_ID = id, Quantity = 1, Type = "wishlist" }; _context.AccountGoods.Add(temp); _context.SaveChanges(); return(true); } return(false); }
public ActionResult EditCart(AccountGood accountGood) { ag.UpdateOneGoodByBothID(accountGood); return(RedirectToAction("ShowCart", "Home")); }
public ActionResult ShowCart(int id) { List <AccountGood> accountGoods = _context.AccountGoods.Where(ag => ag.Account_ID == _context.Users.Where(name => name.UserName == User.Identity.Name).Select(i => i.Id).FirstOrDefault()).ToList(); ViewBag.menuActive = "Cart"; if (id != 0) { AccountGood item = accountGoods.Where(ag => ag.Goods_ID == id && ag.Type == "cart").FirstOrDefault(); if (item != null) { item.Quantity++; _context.SaveChanges(); } else { //AccountGood viewed = new AccountGood() //{ // Order_ID = ag.GenerateOrderId(), // Account_ID = _context.Users.Where(name => name.UserName == User.Identity.Name).Select(i => i.Id).FirstOrDefault(), // Goods_ID = id, // Quantity = 1, // Viewed = true //}; //_context.AccountGoods.Add(viewed); //_context.SaveChanges(); AccountGood temp = new AccountGood() { Order_ID = ag.GenerateOrderId(), Account_ID = _context.Users.Where(name => name.UserName == User.Identity.Name).Select(i => i.Id).FirstOrDefault(), Goods_ID = id, Quantity = 1, Type = "cart", }; _context.AccountGoods.Add(temp); _context.SaveChanges(); } } //why I have to define this again? List <AccountGood> NewaccountGoods = _context.AccountGoods.Where(ag => ag.Account_ID == User.getUserId() && ag.Type == "cart").ToList(); var totalPieces = 0m; var totalPrice = 0m; foreach (var item in NewaccountGoods) { totalPieces += item.Quantity; // item.subCount = item.shop_price * item.quantity; totalPrice += gr.GetOneGoods(item.Goods_ID).shop_price *item.Quantity; } ViewBag.totalPieces = totalPieces; ViewBag.totalPrice = totalPrice; CookieHelper cookieHelper = new CookieHelper(_httpContextAccessor, Request, Response); cookieHelper.Set("totalPieces", totalPieces.ToString(), 1); cookieHelper.Set("totalPrice", totalPrice.ToString(), 1); // ViewBag.test = _context.AccountGoods.Where(ag => ag.Account_ID == Int32.Parse(cookieHelper.GetValue("KarlShop"))).FirstOrDefault().Account.address; // return View(ag.GetCartByAccountID(Int32.Parse(cookieHelper.GetValue("KarlShop")))); CartRepo cart = new CartRepo(_context); return(View(cart.GetCartAll(User.getUserId()))); }
public AccountGood GetOneGoodByBothID(string accountID, int goodsID) { AccountGood ag = _context.AccountGoods.Where(a => a.Goods_ID == goodsID && a.Account_ID == accountID && a.Type == "cart").FirstOrDefault(); return(ag); }