public IActionResult ViewCart() { CookieHelper cookieHelper = new CookieHelper(_httpContextAccessor, Request, Response); if (!_signInManager.IsSignedIn(User)) { cookieHelper.Remove("UserID"); return(Redirect("/Identity/Account/Login")); } SignInUser(); var query = new CartRepo(db).GetAllProductsFromCart(userID); return(View("AddToCart", query)); }
public static List <CartInformation> getCartCustomView(int UserID) { var cart_List = CartRepo.getCartCustomView(UserID); var cartInformation_List = new List <CartInformation>(); for (int i = 0; i < cart_List.Count; i++) { CartInformation CInfo = new CartInformation(); CInfo.ID = cart_List[i].ProductID; CInfo.Name = ProductHandler.getName(cart_List[i].ProductID); CInfo.Price = ProductHandler.getPrice(cart_List[i].ProductID); CInfo.Quantity = getQuantity(UserID, cart_List[i].ProductID); CInfo.SubTotal = (ProductHandler.getPrice(cart_List[i].ProductID) * cart_List[i].Quantity); cartInformation_List.Add(CInfo); } return(cartInformation_List); }
protected void Page_Load(object sender, EventArgs e) { if (Session["user"] == null) { HttpCookie cookies = Request.Cookies.Get("user"); if (cookies != null) { int cookie_id = int.Parse(cookies.Value); User users = UserRepo.GetUserByID(cookie_id); Session["user"] = users; } else { Response.Redirect("Login.aspx"); } } else { List <Model.Cart> cartList = CartRepo.getListCart(); int countCart = cartList.Count; if (countCart == 0) { TitleKosong.Visible = true; BelanjaBtn.Visible = true; LblGrandTotal.Visible = false; } else { TitleKosong.Visible = false; BelanjaBtn.Visible = false; ListCartTable.Visible = true; LblGrandTotal.Visible = true; ListCart.Visible = true; CheckOutBtn.Visible = true; Load_Cart(); } } }
public IActionResult Bought() { //The code below is the old method that I use cookie to judge which data I should get in //the database. //CookieHelper cookieHelper = new CookieHelper(_httpContextAccessor, Request, // Response); //if (cookieHelper.Get("KarlShop") == null) //{ // return RedirectToAction("Login", "Account"); //} ViewBag.menuActive = "Bought"; List <AccountGood> NewaccountGoods = _context.AccountGoods. Where(ag => ag.Account_ID == _context.Users.Where(name => name.UserName == User.Identity.Name).Select(i => i.Id).FirstOrDefault() && ag.Type == "bought").ToList(); CartRepo cart = new CartRepo(_context); return(View(cart.GetBoughtAll(_context.Users.Where(name => name.UserName == User.Identity.Name).Select(i => i.Id).FirstOrDefault()))); }
public void GetRoomTest() { var cartRepo = new CartRepo(bookcontextmock.Object); CartViewModel temp = new CartViewModel() { Name = "Harry Potter and the Order of Phoenix", Price = 531, Description = "5th book of Harry Potter series" }; CartModel temp1 = new CartModel() { Name = temp.Name, Price = temp.Price, Description = temp.Description }; var roomAdded = cartRepo.AddRoom(temp); books.Add(temp1); Assert.AreNotEqual(4, books.Count()); Assert.AreEqual(5, books.Count()); }
private void GetPurchasesInCart(string userId) { var cartRepo = new CartRepo(); double subTotal = 0; //Get all purchases for current user and display in table List <CartModel> purchaseList = cartRepo.GetOrdersInCart(userId); CreateShopTable(purchaseList, out subTotal); //Add totals to webpage double vat = subTotal * 0.21; double totalAmount = subTotal + 15 + vat; litTotal.Text = "£ " + subTotal; litVat.Text = "£ " + vat; litTotalAmount.Text = "£ " + totalAmount; //Add paypal button to checkout //string paypal = GeneratePaypalButton(subTotal); //litPaypal.Text = paypal; }
protected void UpdateBtn_Click(object sender, EventArgs e) { int id = getProductId(); int userId = getUserId(); int qty = Convert.ToInt32(TxtQty.Text); Product products = ProductRepo.GetProductByID(id); if (qty >= products.Stock) { LblError.Text = "Sorry, This Product Stock is just " + products.Stock; } else if (qty == 0) { CartRepo.deleteProductCart(id, userId); Response.Redirect("./Cart.aspx"); } else { CartRepo.updateQtyCart(qty, id, userId); Response.Redirect("./Cart.aspx"); } }
public Result CreateNewCart(UserDto userDto) { try { if (userDto?.Email == null) { throw new Exception("Validation exception: User doesn't exist"); } CartRepo.CreateNewCart(userDto.Email); return(new Result() { ResultCode = EnumResultCode.OK }); } catch (Exception ex) { return(new Result() { ResultCode = EnumResultCode.Error, Details = ex.Message }); } }
public Result AddItemToCart(ItemDto itemDto, UserDto userDto) { try { if (itemDto?.ItemCode == null) { throw new Exception("Validation exception: Item doesn't exist"); } if (itemDto?.Quantity == null) { throw new Exception("Validation exception: Item quantity is not specified"); } if (userDto?.Email == null) { throw new Exception("Validation exception: User doesn't exist"); } var cart = CartRepo.GetUserCart(userDto.Email); cart.AddItem(itemDto.ItemCode, itemDto.Quantity.Value); return(new Result() { ResultCode = EnumResultCode.OK }); } catch (Exception ex) { return(new Result() { ResultCode = EnumResultCode.Error, Details = ex.Message }); } }
public static void deleteProductCart(int productId, int userId) { CartRepo.deleteProductCart(productId, userId); }
public static void deleteCartbyUserId(int userId) { CartRepo.deleteCartuser(userId); }
public static void updateCart(int productId, int userId, int qty) { CartRepo.updateQtyCart(qty, productId, userId); }
public static void createCart(int productId, int userId, int qty) { CartRepo.doInsertProductToCart(productId, userId, qty); }
public static List <Cart> getAllCurrentUserCart(int UserID) { return(CartRepo.getCartCustomView(UserID)); }
public CartService() { _cartRepo = new CartRepo(); }
public OrderController(UserManager <ApplicationUser> userManager) { _cartRepo = new CartRepo(); _orderRepo = new OrderRepo(); _userManager = userManager; }
public static bool isExist(int productId, int userId) { bool exist = CartRepo.existCartbyProductIdAndUserId(productId, userId); return(exist); }
public static void updateNewQuantity(int UserID, int ProductID, int Quantity) { CartRepo.updateNewQuantity(UserID, ProductID, Quantity); }
public static int getQuantity(int UserID, int ProductID) { Cart cart = CartRepo.get(UserID, ProductID); return(cart.Quantity); }
public static Cart get(int UserID, int ProductID) { return(CartRepo.get(UserID, ProductID)); }
public static void remove(int UserID, int ProductID) { CartRepo.remove(CartRepo.get(UserID, ProductID)); }
public static void add(int UserID, int ProductID, int Quantity) { CartRepo.add(CartFactory.createCart(UserID, ProductID, Quantity)); }
public static void decreaseQtyCartProduct(int productId, int userId) { CartRepo.deleteQtyProductCart(productId, userId); }
public static List <Cart> getAllCartUser(int userId) { return(CartRepo.getCartUser(userId)); }
public CartService() { _cartRepo = new CartRepo(); _bookService = new BookService(); }
public static Cart getCartByProductIdAndUserId(int productId, int userId) { return(CartRepo.getCartbyProductIdAndUserId(productId, userId)); }
//[Authorize] public IEnumerable <WishlistVM> Wishlist() { CartRepo cart = new CartRepo(_context); return(cart.GetWishAll(User.getUserId())); }
public static void addQtyCartProduct(int productId, int userId, int qty) { CartRepo.addQtyProduct(productId, userId, qty); }
public CartController(UserManager <ApplicationUser> userManager) { _cartRepo = new CartRepo(); _userManager = userManager; }
public static List <Cart> getAll() { return(CartRepo.getAll()); }