Пример #1
0
        public async Task <IActionResult> Delete(TownDeleteViewModel townDelete)
        {
            if (!this.User.IsInRole(GlobalConstants.AdministratorRoleName))
            {
                return(this.Redirect("/Identity/Account/AccessDenied"));
            }

            if (!this.ModelState.IsValid)
            {
                var error = new TownError
                {
                    ErrorMessage = GlobalConstants.TownModelValidationMessаge
                };
                return(this.RedirectToAction("Error", "Town", error));
            }

            var dtoModel  = TownDeleteHandMapper.Map(townDelete);
            var isDeleted = await this.townService.DeleteTownAsync(dtoModel);

            if (!isDeleted)
            {
                var error = new TownError
                {
                    ErrorMessage = GlobalConstants.TownDeleteErrorMessage
                };
                return(this.RedirectToAction("Error", "Town", error));
            }

            return(this.Redirect("/Town/Index"));
        }
Пример #2
0
        public static TownDeleteDtoModel Map(TownDeleteViewModel viewModel)
        {
            var dtoModel = new TownDeleteDtoModel
            {
                TownId = viewModel.TownId
            };

            return(dtoModel);
        }