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));
        }
Example #3
0
        public static CreateBarVM MapBarToCreateBarVM(this BarDTO bar)
        {
            var newBarVM = new CreateBarVM();

            newBarVM.Id              = bar.Id;
            newBarVM.Name            = bar.Name;
            newBarVM.City            = bar.City;
            newBarVM.Country         = bar.CountryId;
            newBarVM.Details         = bar.Details;
            newBarVM.BarImageURL     = bar.ImageUrl;
            newBarVM.Website         = bar.Website;
            newBarVM.AllCocktailsIDs = bar.Cocktails.Select(c => c.CocktailId).ToList();
            return(newBarVM);
        }
Example #4
0
        public static BarDTO MapBarVMToDTO(this CreateBarVM bar)
        {
            var newBarDTO = new BarDTO();

            newBarDTO.Id        = bar.Id;
            newBarDTO.Name      = bar.Name;
            newBarDTO.City      = bar.City;
            newBarDTO.CountryId = bar.Country;
            newBarDTO.Details   = bar.Details;
            newBarDTO.BarImage  = bar.BarImage;
            newBarDTO.Website   = bar.Website;
            newBarDTO.Cocktails = bar.AllCocktailsIDs
                                  .Select(i => new CocktailDto()
            {
                Id = i.ToString()
            })
                                  .ToList();

            return(newBarDTO);
        }
        public async Task <IActionResult> Create()
        {
            try
            {
                var allCocktails = await _cocktailServices.GetAllCocktails();

                var allCountries = await _barServices.GetAllCountries();

                var createBarVM = new CreateBarVM();
                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));
            }
            catch (Exception ex)
            {
                _toast.AddErrorToastMessage(ex.Message);
                ViewBag.ErrorTitle = "";
                return(View("Error"));
            }
        }