Exemplo n.º 1
0
        public async Task <IActionResult> Edit(string id)
        {
            try
            {
                var bar = await _barManager.GetBarForEditAsync(id);

                var createBarViewModel = new CreateBarViewModel();
                createBarViewModel.Bar = bar.ToVMforEdit();
                var allCocktails = await _cocktailManager.GetAllCocktailsAsync();

                var allCocktailsVM = allCocktails.ToCatalogVM();
                foreach (var cocktail in allCocktailsVM)
                {
                    if (!createBarViewModel.Bar.BarCocktailViewModels.Any(bc => bc.CocktailId == cocktail.CocktailId))
                    {
                        createBarViewModel.CocktailsThatCanOffer.Add(cocktail);
                    }
                }

                return(View(createBarViewModel));
            }
            catch (Exception ex)
            {
                return(RedirectToAction("ErrorAction", "Error", new { errorCode = "404", errorMessage = ex.Message }));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// This method receives a keyword to search by in all Cocktail's name. Returns a sorted list by names.
        /// </summary>
        /// <param name="criteria">the search keyword</param>
        /// <returns>List<CocktailDTO</returns>
        public async Task <ICollection <CocktailDTO> > SearchCocktails(string criteria)
        {
            var listOfCocktails = await _cocktailManager.GetAllCocktailsAsync();

            if (string.IsNullOrEmpty(criteria) || string.IsNullOrWhiteSpace(criteria))
            {
                return(listOfCocktails);
            }
            return(listOfCocktails.Where(cocktail => cocktail.Name.Contains(criteria, StringComparison.CurrentCultureIgnoreCase)).OrderBy(r => r.Name).ToList());
        }
Exemplo n.º 3
0
        public async Task <IActionResult> CocktailCatalog()
        {
            var listOfCocktails = await _cocktailManager.GetAllCocktailsAsync();

            return(View(listOfCocktails.ToCatalogVM()));
        }