Exemplo n.º 1
0
 public IActionResult AddToCart(int Quantity, string ShopId, string ItemId)
 {
     try
     {
         _serviceFacade.AddProductToCart(new Guid(HttpContext.Session.Id), new Guid(ShopId), new Guid(ItemId), Quantity);
         if (User.IsInRole("Buyer"))
         {
             return(RedirectToAction("Index", "Buyer"));
         }
         return(RedirectToAction("Index", "Home"));
     }
     catch (BrokenConstraintException)
     {
         var redirect = this.Url.Action("Index", "Buyer");
         var message  = new UserMessage(redirect, "Cant buy the same product.");
         return(View("UserMessage", message));
     }
     catch (IllegalArgumentException)
     {
         var redirect = this.Url.Action("Index", "Buyer");
         var message  = new UserMessage(redirect, "Please buy more than 0 products.");
         return(View("UserMessage", message));
     }
     catch (ShopStateException)
     {
         var redirect = this.Url.Action("Index", "Buyer");
         var message  = new UserMessage(redirect, "Cant add products to cart from a closed 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));
     }
 }
Exemplo n.º 2
0
 public bool AddProductToCart(Guid userGuid, Guid shopGuid, Guid productGuid, int quantity)
 {
     return(_serviceFacade.AddProductToCart(userGuid, shopGuid, productGuid, quantity));
 }