public async Task <IActionResult> Create(TownInputViewModel model) { 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)); } bool townExists = await this.townService.CheckIfExistsAsync(model.Name); if (townExists) { var error = new TownError { ErrorMessage = GlobalConstants.TownExistErrorMessage }; return(this.RedirectToAction("Error", "Town", error)); } await this.townService.CreateTownByNameAsync(model.Name); return(this.Redirect("/Town/All")); }
public async Task <IActionResult> Create(TownInputViewModel model) { if (!this.ModelState.IsValid) { return(this.Redirect("/Town/Create")); } else { bool townExists = this.townService.CheckIfExists(model.Name); if (townExists) { return(this.Redirect("/Town/Create")); } else { await this.townService.CreateTownByNameAsync(model.Name); return(this.Redirect("/Town/All")); } } }