Example #1
0
        public async Task <IActionResult> Create([Bind("Name,Phone,Website,Description,Address,CityId")] BarViewModel barVM)
        {
            if (ModelState.IsValid)
            {
                var barDTO             = barVM.BarVMtoDTO();
                var barDTOWithLocation = await barService.ParseApiLocationResult(barDTO);

                try
                {
                    var newBarDTO = await barService.CreateBarAsync(barDTOWithLocation);

                    var newBarVM = newBarDTO.BarDTOtoVM();
                    _toastNotification.AddSuccessToastMessage($"Bar {newBarVM.Name} created successfully!");
                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception)
                {
                    _toastNotification.AddErrorToastMessage("Bar cannot be created!");
                    return(RedirectToAction(nameof(Index)));
                }
            }
            return(View(barVM));
        }