public IActionResult ShoppingCart() { try { IEnumerable <Tuple <ShoppingCart, IEnumerable <ShopProduct> > > bag = _serviceFacade.GetUserBag(new Guid(HttpContext.Session.Id)); CheckoutModel model = new CheckoutModel(bag); IList <double> discountPrices = new List <double>(); foreach (Tuple <ShoppingCart, IEnumerable <ShopProduct> > tup in bag) { var disc = _serviceFacade.GetCartPrice(new Guid(HttpContext.Session.Id), tup.Item1.ShopGuid); discountPrices.Add(disc); } model.AfterDiscount = discountPrices; return(View(model)); } catch (ShopStateException) { var redirect = this.Url.Action("Index", "Buyer"); var message = new UserMessage(redirect, "Can't purchase a cart of an inactive shop"); return(View("UserMessage", message)); } catch (GeneralServerError) { var redirect = this.Url.Action("Index", "Buyer"); var message = new UserMessage(redirect, "An error has occured. Please refresh and try again."); return(View("UserMessage", message)); } catch (DatabaseConnectionTimeoutException) { var redirect = this.Url.Action("Index", "Buyer"); var message = new UserMessage(redirect, "An error has occured. Please refresh and try again. (Database connection lost)."); return(View("UserMessage", message)); } }
public double GetCartPrice(Guid userGuid, Guid shopGuid) { return(_serviceFacade.GetCartPrice(userGuid, shopGuid)); }