public async Task <IActionResult> Index() { try { var cocktailDTOs = await this.cocktailService.GetAllCocktailssAsync(); var cocktailVMs = cocktailDTOs.Select(cocktailDTO => cocktailDTOMapper.MapToVMFromDTO(cocktailDTO)).ToList(); foreach (var cocktail in cocktailVMs) { cocktail.Ingredients = (await this.ingredientService.GetAllIngredientsAsync()) .Where(ingredient => ingredient.CocktailDTOs.Any(c => c.Name == cocktail.Name)) .Select(idto => ingredientDTOMapper.MapToVMFromDTO(idto)).ToList(); cocktail.Bars = (await this.barService.GetAllBarsAsync()) .Where(bar => bar.Cocktails.Any(c => c.Name == cocktail.Name)) .Select(bdto => barDTOMApper.MapToVMFromDTO(bdto)).ToList(); } return(View(cocktailVMs)); } catch (Exception) { this.toaster.AddWarningToastMessage(ToastrConsts.GenericError); return(RedirectToAction("Index", "Home", new { area = "" })); } }
public async Task <IActionResult> Create(int id) { try { var barDTO = await this.barService.GetBarAsync(id); var barVM = barMapper.MapToVMFromDTO(barDTO); var currentUserId = int.Parse(userManager.GetUserId(HttpContext.User)); var reviewVM = new BarReviewViewModel { BarName = barVM.Name, BarId = barDTO.Id, AuthorId = currentUserId }; //ViewData["BarId"] = new SelectList(_context.Bars, "Id", "Address"); //ViewData["UserId"] = new SelectList(_context.Users, "Id", "Id"); return(View(reviewVM)); } catch (Exception) { this.toaster.AddWarningToastMessage(ToastrConsts.GenericError); return(RedirectToAction("Index", "Bars", new { id })); } }
public async Task <IActionResult> Index() { try { var barDTOs = await this.barService.GetAllBarsAsync(); var bars = barDTOs .Select(b => barMapper.MapToVMFromDTO(b)) .ToList(); return(View(bars)); } catch (Exception) { this.toaster.AddWarningToastMessage(ToastrConsts.GenericError); return(RedirectToAction("Index", "Home", new { area = "" })); } }
public async Task <IActionResult> ListAllCities() { try { var draw = Request.Form["draw"].FirstOrDefault(); var start = Request.Form["start"].FirstOrDefault(); var length = Request.Form["length"].FirstOrDefault(); var searchValue = Request.Form["search[value]"].FirstOrDefault(); var sortColumn = Request.Form["columns[" + Request.Form["order[0][column]"].FirstOrDefault() + "][name]"].FirstOrDefault(); var sortColumnDirection = Request.Form["order[0][dir]"].FirstOrDefault(); int pageSize = length != null?Convert.ToInt32(length) : 0; int skip = start != null?Convert.ToInt32(start) : 0; int totalCities = this.cityService.GetAllCitiesCount(); int filteredCities = this.cityService.GetAllFilteredCitiesCount(searchValue); var cities = await this.cityService.ListAllCitiesAsync(skip, pageSize, searchValue, sortColumn, sortColumnDirection); var cityVMs = cities.Select(city => this.cityMapper.MapToVMFromDTO(city)).ToList(); foreach (var city in cityVMs) { city.Bars = (await this.barService.GetAllBarsAsync()) .Where(b => b.CityName.Contains(city.Name)) .Select(b => barMapper.MapToVMFromDTO(b)).ToList(); //city.BarNames = string.Join(", ", city.Bars.Select(b => b.Name)); } return(Json(new { draw = draw, recordsFiltered = filteredCities, recordsTotal = totalCities, data = cityVMs })); //data = model } catch (Exception) { this.toaster.AddWarningToastMessage(ToastrConsts.GenericError); return(RedirectToAction(nameof(Index))); } }