public ActionResult RemoveOneItem(string productId) { ViewShoppingCart viewShoppingCart; ShoppingCart shoppingCart = GetShoppingCart(); if (!shoppingCart.Items.ContainsKey(productId)) { viewShoppingCart = new ViewShoppingCart() { shoppingCart = GetShoppingCart() }; return(View("ShowCart", viewShoppingCart)); } if (shoppingCart.Items[productId].Quantity > 1) { shoppingCart.Items[productId].Quantity--; } else if (shoppingCart.Items[productId].Quantity == 1) { RemoveCartItem(productId); } SetShoppingCart(shoppingCart); viewShoppingCart = new ViewShoppingCart() { shoppingCart = GetShoppingCart() }; return(View("ShowCart", viewShoppingCart)); }
public static void Add(int custId, int bookId, ModelStore modelStore) { Book bookToAdd = modelStore.GetBook(bookId); if (bookToAdd == null) { ViewInvalidRequest.Render(); return; } ShoppingCart cart = modelStore.GetCustomer(custId).ShoppingCart; ShoppingCartItem item = cart.GetItem(bookId); if (item == null) { cart.Items.Add(new ShoppingCartItem { BookId = bookId, Count = 1 }); } else { item.Count += 1; } ViewShoppingCart.Render(custId, modelStore); }
public void Dispatch(string request) { try { string[] tokens = request.Split(' '); int custId = Int32.Parse(tokens[1]); string action = tokens[2]; if (tokens[0] != "GET" || !customerExists(custId) || tokens.Length != 3 || !action.StartsWith(WEBSITE_NAME)) { throw new InvalidRequestException(); } // strip http://www.nezarka.net/ from request action = action.Substring(WEBSITE_NAME.Length, action.Length - WEBSITE_NAME.Length); string[] act_list = action.Split('/'); if (act_list.Length == 1 && act_list[0] == "Books") { // http://www.nezarka.net/Books ViewBooks.Render(custId, modelStore); } else if (act_list.Length == 3 && act_list[0] == "Books" && act_list[1] == "Detail") { // http://www.nezarka.net/Books/Detail/_Book_Id_ ViewBookDetail.Render(custId, Int32.Parse(act_list[2]), modelStore); } else if (act_list.Length == 1 && act_list[0] == "ShoppingCart") { // http://www.nezarka.net/ShoppingCart ViewShoppingCart.Render(custId, modelStore); } else if (act_list.Length == 3 && act_list[0] == "ShoppingCart" && act_list[1] == "Add") { // http://www.nezarka.net/ShoppingCart/Add/_BookId_ CartController.Add(custId, Int32.Parse(act_list[2]), modelStore); } else if (act_list.Length == 3 && act_list[0] == "ShoppingCart" && act_list[1] == "Remove") { // http://www.nezarka.net/ShoppingCart/Remove/_BookId_ CartController.Remove(custId, Int32.Parse(act_list[2]), modelStore); } else { ViewInvalidRequest.Render(); } } catch (Exception ex) { if (ex is InvalidRequestException || ex is FormatException || ex is IndexOutOfRangeException) { ViewInvalidRequest.Render(); } else { throw; } } }
public void ViewShoppingCartTest() { ExtentTest viewShoppingCartTest = extent.CreateTest("ViewShoppingCartTest").Info("View shopping cart Test started"); ViewShoppingCart view = new ViewShoppingCart(driver); view.ViewShoppingCartPage(); ((ITakesScreenshot)driver).GetScreenshot().SaveAsFile(Path + "ViewShoppingCartPage.png", ScreenshotImageFormat.Png); log.Info("View Shopping Cart Test Executed Successfully"); }
public ActionResult ActiveOrders() { try { List <List <ShoppingCartModel> > shoppingCarts = new List <List <ShoppingCartModel> >(); var currentUser = context.Users.Where(b => b.UserName == User.Identity.Name).First(); var activeOrders = context.OrderRequest.Include("User").Where(a => a.Deliverer.Id == currentUser.Id && a.ActiveOrder == true).First(); var myCartId = context.ShoppingcartJoin.Where(a => a.User.Id == activeOrders.User.Id).ToList(); var customer = activeOrders.User; var orderPurchased = context.OrderRequest.Where(a => a.Deliverer.Id == currentUser.Id).First(); var userAddress = context.AddressJoin.Include("Address").Include("Address.Zip").Include("Address.City").Where(a => a.User.Id == customer.Id).First(); foreach (var item in myCartId) { shoppingCarts.Add(context.ShopingCarts.Where(a => a.Id == item.Id).ToList()); } ViewShoppingCart model = new ViewShoppingCart(); model.shoppingCart = shoppingCarts; model.UserName = activeOrders.User.UserName; model.userId = activeOrders.User.Id; model.lat = userAddress.Address.Lattitude; model.lng = userAddress.Address.Longitude; model.address = userAddress.Address.addressLine; double roundedPrice = 0; foreach (var item in model.shoppingCart) { foreach (var thing in item) { if (thing.amount > 1) { roundedPrice += thing.salePrices * thing.amount; model.TotalPrice = Math.Round(roundedPrice, 2); } else { roundedPrice += thing.salePrices; model.TotalPrice = Math.Round(roundedPrice, 2); } } } if (orderPurchased.ShowOnDeliverer != true) { return(View("NoOrder")); } else if (orderPurchased.OrderPurchased == true) { return(View("ToDelivery", model)); } else { return(View("ActiveOrders", model)); } } catch { return(View("NoOrder")); } }
public ActionResult ClearShoppingCart() { ViewShoppingCart viewShoppingCart = new ViewShoppingCart() { shoppingCart = GetShoppingCart() }; Session[ShoppingCartName] = null; return(View("ShowCart", viewShoppingCart)); }
public ActionResult RemoveCartItem(string productId) { ShoppingCart shoppingCart = GetShoppingCart(); shoppingCart.Delete(productId); SetShoppingCart(shoppingCart); ViewShoppingCart viewShoppingCart = new ViewShoppingCart() { shoppingCart = GetShoppingCart() }; return(View("ShowCart", viewShoppingCart)); }
//========================================================== //========================================================== public ActionResult Index() { ShoppingCart cart = ShoppingCartCreateOrLoad(); ViewShoppingCart modelCart = new ViewShoppingCart(); if (cart != null) { modelCart.Id = cart.Id; modelCart.UserId = cart.UserId; modelCart.CookieKey = cart.CookieKey; modelCart.CountProducts = 0; if (cart.ShoppingCartsProducts.Count > 0) { modelCart.Products = new List <ViewShoppingCartsProducts>(); foreach (ShoppingCartsProduct cartProduct in cart.ShoppingCartsProducts) { ViewShoppingCartsProducts modelProduct = new ViewShoppingCartsProducts { Id = cartProduct.Id, Alias = cartProduct.ShopProduct.Alias, Name = cartProduct.ShopProduct.Name, PhotoName = cartProduct.ShopProduct.PhotoName, Quantity = cartProduct.Quantity, DateAdded = cartProduct.DateAdded }; modelCart.CountProducts = modelCart.CountProducts + cartProduct.Quantity; ShopProductsPrice price = db.ShopProductsPrices.Where(p => p.ShopProduct.Id == cartProduct.ShopProduct.Id && p.CurrentPrice).SingleOrDefault(); if (price != null) { modelProduct.PriceOne = price.Price; modelProduct.PriceTotal = Decimal.Multiply(modelProduct.Quantity, modelProduct.PriceOne); } modelCart.Products.Add(modelProduct); } modelCart.Products = modelCart.Products.OrderByDescending(m => m.DateAdded).ToList(); } } return(View(modelCart)); }
// GET: ShoppingCart public ActionResult ShowCart() { List <Category> CategoriesMenu = new List <Category>(); List <Category> CategoriesProduct = new List <Category>(); List <Product> Products = new List <Product>(); List <Product> NewProducts = new List <Product>(); List <Product> FeatureProducts = new List <Product>(); List <Product> LatestProducts = new List <Product>(); CategoriesMenu = HttpContext.GetOwinContext().Get <ApplicationDbContext>().Categories.Where(c => c.Active == 1).ToList(); CategoriesProduct = HttpContext.GetOwinContext().Get <ApplicationDbContext>().Categories.Where(c => c.Parent == 0 && c.Active == 1).Take(4).ToList(); foreach (var cate in CategoriesProduct) { var count = 0; foreach (var cate2 in CategoriesMenu) { if (cate2.Parent == cate.Id) { if (count < 8) { Products.AddRange(HttpContext.GetOwinContext().Get <ApplicationDbContext>().Products.Where(p => p.CategoryID == cate2.Id && p.isActive == 1).Take(2).ToList()); count += 2; } } } } ViewHomeClient viewHomeClient = new ViewHomeClient() { CategoriesProduct = CategoriesProduct, Products = Products, NewProducts = HttpContext.GetOwinContext().Get <ApplicationDbContext>().Products.Where(p => p.isNew == 1 && p.isActive == 1).Take(8).ToList(), FeatureProducts = HttpContext.GetOwinContext().Get <ApplicationDbContext>().Products.Where(p => p.isFeature == 1 && p.isActive == 1).Take(8).ToList(), shoppingCart = GetShoppingCart(), LatestProducts = getLastestProduct() }; ViewBag.Message = viewHomeClient; ViewShoppingCart viewShoppingCart = new ViewShoppingCart() { shoppingCart = GetShoppingCart() }; return(View(viewShoppingCart)); }
public static void Remove(int custId, int bookId, ModelStore modelStore) { ShoppingCart cart = modelStore.GetCustomer(custId).ShoppingCart; ShoppingCartItem item = cart.GetItem(bookId); if (item == null) { ViewInvalidRequest.Render(); return; } item.Count -= 1; if (item.Count == 0) { cart.RemoveItem(item); } ViewShoppingCart.Render(custId, modelStore); }
public ActionResult DisplayShoppingCart() { var currentUser = context.Users.Where(b => b.UserName == User.Identity.Name).First(); var orderAccepted = context.OrderRequest.Where(a => a.User.Id == currentUser.Id).First(); List <List <ShoppingCartModel> > shoppingCarts = new List <List <ShoppingCartModel> >(); var myCartId = context.ShoppingcartJoin.Where(a => a.User.Id == currentUser.Id).ToList(); foreach (var item in myCartId) { shoppingCarts.Add(context.ShopingCarts.Where(a => a.Id == item.Id).ToList()); } ViewShoppingCart model = new ViewShoppingCart(); model.shoppingCart = shoppingCarts; double roundedPrice = 0; double deliveryPrice = 0; double finalPrice = 0; foreach (var item in model.shoppingCart) { foreach (var thing in item) { if (thing.amount > 1) { roundedPrice += thing.salePrices * thing.amount; model.TotalPrice = Math.Round(roundedPrice, 2); } else { roundedPrice += thing.salePrices; model.TotalPrice = Math.Round(roundedPrice, 2); } } } try { var address = context.AddressJoin.Include("Address").Include("Address.Zip").Include("Address.City").Where(a => a.User.Id == currentUser.Id).First(); var location = StaticClasses.StaticClasses.WalmartLocatorApi(address.Address.City.City, address.Address.Zip.zip.ToString()); string userLat = StaticClasses.StaticClasses.GoogleGeoLocationApi(address.Address.addressLine, address.Address.Zip.zip)[0]; string userLng = StaticClasses.StaticClasses.GoogleGeoLocationApi(address.Address.addressLine, address.Address.Zip.zip)[1]; string distanceObject = StaticClasses.StaticClasses.GoogleDistanceApi(userLat, userLng, location.Coordinates[1].ToString(), location.Coordinates[0].ToString()); var hold = distanceObject.Split(' '); var distance = double.Parse(hold[0]); deliveryPrice += distance * 2; finalPrice = deliveryPrice + roundedPrice; model.deliveryPrice = Math.Round(deliveryPrice, 2); model.finalPrice = Math.Round(finalPrice, 2); if (orderAccepted.FinishOrder == true) { FinisedOrderModel finishmodel = new FinisedOrderModel(); finishmodel.userId = currentUser.Id; return(View("FinishedOrder", finishmodel)); } else if (orderAccepted.ActiveOrder == true && orderAccepted.OrderAccepted == true) { var orderRequest = context.OrderRequest.Include("Deliverer").Where(a => a.User.Id == currentUser.Id).First(); var mapData = context.DelivererGeoLocation.Where(a => a.User.Id == orderRequest.Deliverer.Id).First(); var rating = context.Rating.Where(a => a.User.Id == orderRequest.Deliverer.Id).First(); if (rating.raitingCount > 1) { model.rating = rating.raiting / rating.raitingCount; } else { model.rating = 4; } model.lat = mapData.lat; model.lng = mapData.lng; var orderStatus = context.OrderStatus.Where(a => a.User.Id == currentUser.Id).First(); model.OrderStatus = orderStatus.status; model.message = orderRequest.message; return(View("OrderInProgress", model)); } else if (orderAccepted.ActiveOrder == true && orderAccepted.OrderAccepted == false) { return(View("SubmittedOrder", model)); } else { return(View("ShoppingCart", model)); } } catch { return(View("NoAddress")); } }