public async Task CreateRecord(InputModels.CreateRoleInput input) { var now = DateTime.Now; var record = new DataModels.ApplicationRole { Name = input.Name, Description = input.Description, CreatedDate = now, CreatedById = UserContext.ApplicationUser.Id, ModifiedDate = now, ModifiedById = UserContext.ApplicationUser.Id }; await RoleManager.CreateAsync(record); }
public async Task <ServiceModels.ServiceResponse> Create(InputModels.CreateRoleInput input) { var serviceResponse = new ServiceModels.ServiceResponse(); if (input.Name != null) { input.Name = input.Name.Trim(); } if (string.IsNullOrEmpty(input.Name)) { serviceResponse.Error(nameof(InputModels.CreateRoleInput.Name), "Name is required"); } if (input.Description != null) { input.Description = input.Description.Trim(); } if (string.IsNullOrEmpty(input.Description)) { serviceResponse.Error(nameof(InputModels.CreateRoleInput.Description), "Description is required"); } if (!serviceResponse.Success) { return(serviceResponse); } if (await RoleManager.FindByNameAsync(input.Name) != null) { serviceResponse.Error(nameof(InputModels.CreateRoleInput.Name), "A role with this name already exists"); } if (!serviceResponse.Success) { return(serviceResponse); } await CreateRecord(input); serviceResponse.RedirectPath = UrlHelper.Action(nameof(Roles.Index), nameof(Roles)); return(serviceResponse); }
public async Task <IActionResult> Create(InputModels.CreateRoleInput input) { if (ModelState.IsValid) { var serviceResponse = await RoleRepository.Create(input); return(await ForumViewResult.RedirectFromService(this, serviceResponse, FailureCallback)); } return(await FailureCallback()); async Task <IActionResult> FailureCallback() { var viewModel = new ViewModels.Roles.CreatePage() { Name = input.Name, Description = input.Description }; return(await ForumViewResult.ViewResult(this, viewModel)); } }