public ActionResult Order(productSearchViewModel data) //Post Action for data obtained from category dropdown form in view { var category = data.cate.categoryId; var productViewModel = new productSearchViewModel(); var sortCondition = data.sortTypeView.sortType; var userID = data.userId; if (!(Convert.ToDouble(category) == double.NaN && sortCondition == null)) //block of code when category and sorting both are selected { productViewModel.productView = context.products.Where(c => c.cateID == category).OrderBy(c => c.Price).ToList(); productViewModel.categoryView = context.categories.ToList(); productViewModel.sortView = context.sorts.ToList(); ViewBag.userID = userID; // productViewModel.userId = userID; return(View(productViewModel)); } else if ((Convert.ToDouble(category) != double.NaN && sortCondition == null) == true) //block of code when only category is selected { productViewModel.productView = context.products.Where(c => c.cateID == category).ToList(); productViewModel.categoryView = context.categories.ToList(); productViewModel.sortView = context.sorts.ToList(); ViewBag.userID = userID; productViewModel.userId = userID; return(View(productViewModel)); } else if ((sortCondition != null && Convert.ToDouble(category) == double.NaN) == true) //block of code when only sorting is selected { productViewModel.productView = context.products.OrderBy(c => c.Price).ToList(); productViewModel.categoryView = context.categories.ToList(); productViewModel.sortView = context.sorts.ToList(); ViewBag.userID = userID; productViewModel.userId = userID; return(View(productViewModel)); } RedirectToAction("Order", "shopping", new { userId = userID }); return(View()); }
public ActionResult Order(int userId) //Action to show all the available products in the database { ViewBag.userID = userId; //Viewbag to transfer userid to view var productviewmodel = new productSearchViewModel(); //object of productSearch Viewmodel productviewmodel.userId = userId; productviewmodel.productView = context.products.ToList(); //List of all the products in the database productviewmodel.categoryView = context.categories.ToList(); //List of all the categories in the database for dropdownlist productviewmodel.sortView = context.sorts.ToList(); //List of all the type of sorting available return(View(productviewmodel)); }
public ActionResult cartAdd(productSearchViewModel data) //Action to add item from order cshtml to cart { ViewBag.cartItemCount = ""; ViewBag.UserID = data.userId; ViewBag.grandTotal = 0.0; var cartItems = new Cart(); var cartTablePre = context.carts.ToList(); var productData = context.products.Find(data.productID); cartItems.productId = productData.productId; cartItems.productName = productData.productName; cartItems.price = productData.Price; cartItems.Quantity = data.quantity; cartItems.totalPrice = cartItems.price * cartItems.Quantity; context.carts.Add(cartItems); context.SaveChanges(); var cartTablePost = context.carts.ToList(); foreach (var item in cartTablePost) { ViewBag.grandTotal += item.totalPrice; } return(View(cartTablePost)); }