public async Task <IActionResult> Edit(CreateBarVM createBarVM) { if (ModelState.IsValid) { try { var barDTO = createBarVM.MapBarVMToDTO(); var barName = await _barServices.Update(barDTO); _toast.AddSuccessToastMessage($"You successfully edited \"{barName}\" bar!"); return(RedirectToAction(nameof(ListBars))); } catch (Exception ex) { _toast.AddErrorToastMessage(ex.Message); ViewBag.ErrorTitle = ""; return(View("Error")); } } var allCountries = await _barServices.GetAllCountries(); var allCocktails = await _cocktailServices.GetAllCocktails(); createBarVM.AllCocktails = allCocktails .Select(c => new SelectListItem(c.Name, c.Id)).ToList(); createBarVM.AllCountries = allCountries .Select(c => new SelectListItem(c.Name, c.Id)).ToList(); return(View(createBarVM)); }
public async Task <IActionResult> Create(CreateBarVM barVM) { if (ModelState.IsValid) { try { var barDTO = barVM.MapBarVMToDTO(); var barName = await _barServices.AddBarAsync(barDTO); //notification for admin string id = this.User.FindFirstValue(ClaimTypes.NameIdentifier); await _notificationServices.BarCreateNotificationToAdminAsync(id, barName); _toast.AddSuccessToastMessage($"You successfully added \"{barName}\" bar!"); return(RedirectToAction(nameof(ListBars))); } catch (Exception ex) { _toast.AddErrorToastMessage(ex.Message); ViewBag.ErrorTitle = ""; return(View("Error")); } } var allCocktails = await _cocktailServices.GetAllCocktails(); var allCountries = await _barServices.GetAllCountries(); barVM.AllCocktails = allCocktails .Select(c => new SelectListItem(c.Name, c.Id)).ToList(); barVM.AllCountries = allCountries .Select(c => new SelectListItem(c.Name, c.Id)).ToList(); return(View(barVM)); }