public async Task <IActionResult> CocktailDetails(Guid id)
        {
            var ingredients = await ingredientServices.GetAllIngredients(null);

            if (id == null)
            {
                return(NotFound());
            }

            try
            {
                var cocktail = await cocktailServices.GetCocktail(id);

                var cocktailVM = cocktail.GetViewModel();
                cocktailVM.IngredientsToChoose = ingredients.Select(c => new SelectListItem(c.Name, c.Id.ToString())).ToList();
                cocktailVM.Ingredients         = await ingredientServices.GetCocktailIngredients(id);

                cocktailVM.Bars = await cocktailServices.GetBarsOfCocktail(id);

                var comments = await cocktailCommentServices.GetAllCommentsForCocktail(id);

                cocktailVM.Comments = comments.GetViewModels();
                return(View(cocktailVM));
            }
            catch (Exception)
            {
                this.toast.AddErrorToastMessage("Something went wrong");
                return(RedirectToAction("ListBars"));
            }
        }
        public async Task <IActionResult> RemoveCocktailFromBar(Guid barId, Guid cocktailId)
        {
            try
            {
                var cocktail = await cocktailServices.GetCocktail(cocktailId);

                await barServices.RemoveCocktailFromBar(barId, cocktailId);

                return(RedirectToAction("ListBars", "Bar"));
            }
            catch (Exception)
            {
                this.toastNotification.AddErrorToastMessage(Exceptions.SomethingWentWrong);
                return(RedirectToAction("ListBars"));
            }
        }
        public async Task <IActionResult> RemoveIngredient(Guid cocktailId, Guid ingredientId)
        {
            try
            {
                var ingredient = await ingredientServices.GetIngredient(ingredientId);

                var cocktail = await cocktailServices.GetCocktail(cocktailId);

                await cocktailServices.RemoveIngredientFromCocktail(cocktail.Name, ingredient.Name);

                this.toast.AddSuccessToastMessage(Exceptions.SuccessfullyDeleted);
                return(RedirectToAction("ListCocktails", "Cocktail"));
            }
            catch (Exception)
            {
                this.toast.AddErrorToastMessage(Exceptions.SomethingWentWrong);
                return(RedirectToAction("ListCocktails", new { Area = "" }));
            }
        }
Example #4
0
        public async Task <IActionResult> Details(Guid id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            try
            {
                var cocktail = await cocktailServices.GetCocktail(id);

                var cocktailVM = cocktail.GetViewModel();
                return(View(cocktailVM));
            }
            catch (Exception)
            {
                this.toast.AddErrorToastMessage("Something went wrong");
                return(RedirectToAction("ListCocktails", "Cocktail", new { Area = "" }));
            }
        }