public RedirectToActionResult Add(int id) { var product = this.Data.Get(new QueryOptions <OfficeProduct> { Include = "Type", Where = b => b.OfficeProductId == id }); if (product == null) { TempData["message"] = "Unable to add book to cart."; } else { var dto = new OfficeProductDTO(); dto.Load(product); var item = new CartItem { Product = dto, Quantity = 1 }; var cart = this.getCart(); cart.Add(item); cart.Save(); TempData["message"] = $"{product.Name} added to cart"; } var builder = new OfficeProductsGridBuilder(HttpContext.Session); return(RedirectToAction("List", "Products", builder.CurrentRoute)); }
/// <summary> /// Gets the list of products. /// </summary> /// <param name="values">The values.</param> /// <returns>the list view</returns> public IActionResult List(OfficeProductGridDTO values) { var builder = new OfficeProductsGridBuilder(HttpContext.Session, values, nameof(OfficeProduct.Name)); var options = new OfficeProductQueryOptions { Include = "Type", OrderByDirection = builder.CurrentRoute.SortDirection, PageNumber = builder.CurrentRoute.PageNumber, PageSize = builder.CurrentRoute.PageSize }; options.SortFilter(builder); var vm = new OfficeProductListViewModel { Products = this.Data.Products.List(options), ProductTypes = this.Data.Types.List(new QueryOptions <ProductType> { OrderBy = g => g.Name }), Images = this.Data.Images.List(new QueryOptions <Image>()), CurrentRoute = builder.CurrentRoute, TotalPages = builder.GetTotalPages(this.Data.Products.Count) }; return(View(vm)); }
/// <summary> /// Gets the index page /// </summary> /// <returns>the index view</returns> public ViewResult Index() { var cart = this.getCart(); var builder = new OfficeProductsGridBuilder(HttpContext.Session); var vm = new CartViewModel { List = cart.List, Subtotal = cart.Subtotal, BookGridRoute = builder.CurrentRoute }; return(View(vm)); }
public RedirectToActionResult Filter(string[] filter, bool clear = false) { var builder = new OfficeProductsGridBuilder(HttpContext.Session); if (clear) { builder.ClearFilterSegments(); } else { builder.LoadFilterSegments(filter); } builder.SaveRouteSegments(); return(RedirectToAction("List", builder.CurrentRoute)); }