public async Task <ActionResult> DeleteConfirmed(string id, string deleteUser) { if (ModelState.IsValid) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var role = await _roleManager.FindByIdAsync(id); if (role == null) { return(HttpNotFound()); } IdentityResult result; if (deleteUser != null) { result = await _roleManager.DeleteAsync(role); } else { result = await _roleManager.DeleteAsync(role); } if (!result.Succeeded) { ModelState.AddModelError("", result.Errors.First()); return(View()); } return(RedirectToAction("Index")); } return(View()); }
// DELETE: Roles/Delete/5 public async Task <IHttpActionResult> Delete(Guid id) { var role = _roleManager.Roles.SingleOrDefault(r => r.Id == id.ToString()); await _roleManager.DeleteAsync(role); return(Ok(role)); }
public async Task <string> DeleteRoleAsync(string roleName) { string message = string.Empty; try { ApplicationRole role = await roleManager.FindByNameAsync(roleName); if (role != null) { // check whether the role is assigned to any existing users if (role.Users.Count == 0) { await roleManager.DeleteAsync(role); message = string.Format("Success : {0} role deleted successfuly", roleName); } else { message = string.Format("Warning : Role {0} cannot be deleted, as the role is assigned to {1} users", roleName, role.Users.Count); } } else { message = string.Format("Error : Role with such name - {0} does not exist", roleName); } } catch (Exception ex) { message = string.Format("Error : Exception occured at deleting role {0}", ex.Message); } return(message); }
public async Task <string> Get(string roleName, string action) { var context = ApplicationDbContext.Create(); var roleManager = new ApplicationRoleManager(new RoleStore <ApplicationRole>(context)); switch (action) { case createAction: if (roleManager.RoleExists(roleName)) { return("新增角色失败,该角色名称已存在"); } await roleManager.CreateAsync(new ApplicationRole(roleName)); return("新增角色成功"); case deleteAction: if (!roleManager.RoleExists(roleName)) { return("删除角色失败,该角色名称不存在"); } var role = roleManager.FindByName(roleName); await roleManager.DeleteAsync(role); return("删除角色成功"); default: return("无效的操作指令"); } }
public async Task <ActionResult> DeleteConfirm(string id) { var role = await RoleManager.FindByIdAsync(id); await _roleMangager.DeleteAsync(role); return(RedirectToAction("Index")); }
public async Task <IdentityResult> DeleteRole(Guid id) { var identityRole = await _applicationRoleManager.FindByIdAsync(id.ToString()); if (identityRole.Users.Count > 0) { return(new IdentityResult($"The {identityRole.Name} is in using.")); } return(await _applicationRoleManager.DeleteAsync(identityRole)); }
public async Task <ActionResult> Delete(string id) { var role = await _roleManager.FindByIdAsync(id); if (role != null) { IdentityResult result = await _roleManager.DeleteAsync(role); } return(RedirectToAction("Index")); }
public RemoveResultStatus Remove(int id) { var role = _applicationRoleManager.FindByIdAsync(id).Result; var result = _applicationRoleManager.DeleteAsync(role); if (result.Result.Succeeded) { return(RemoveResultStatus.Success); } return(RemoveResultStatus.Failed); }
public override async Task RemoveAsync(object id) { if (!await ExistsAsync(id)) { CustomException.ThrowNotFoundException($"There is no role with id = {id}."); } var role = await _roleManager.FindByIdAsync((string)id); await _roleManager.DeleteAsync(role); }
public async Task <JsonResult> DeleteRole(string role) { IdentityRole irole = await _roleManager.FindByNameAsync(role); if (irole != null) { await _roleManager.DeleteAsync(irole); } var model = _roleManager.Roles; return(Json(model)); }
public async Task DeleteRoleAsync(RoleDTO role) { var existingRole = await _roleManager.FindByNameAsync(role.Name); if (existingRole != null) { await _roleManager.DeleteAsync(mapper.Map <IdentityRole>(existingRole)); } else { throw new RoleException($"The role with name: {existingRole.Name} does not exist!"); } }
public async Task <IHttpActionResult> DeleteRoleAsync(string id) { var role = await ApplicationRoleManager.FindByIdAsync(id); if (role == null) { return(NotFound()); } var result = await ApplicationRoleManager.DeleteAsync(role); return(result.Succeeded ? Ok() : GetErrorResult(result)); }
public async Task <IdentityResult> RemoveRoleAsync(string roleId) { var roleEntity = await _roleManager.FindByIdAsync(roleId); if (roleEntity == null) { throw new NotFoundException($"Could not locate entity with Id {roleId}"); } var identityResult = await _roleManager.DeleteAsync(roleEntity); return(identityResult); }
public async Task <ActionResult> DeleteRoleConfirmed(string id, string deleteUser) { if (ModelState.IsValid) { if (id == null) { return(View("Response", new ResponseViewModel() { Msg = "Record not found!" })); } var role = await RoleManager.FindByIdAsync(id); if (role == null) { return(View("Response", new ResponseViewModel() { Msg = "Record not found!" })); } IdentityResult result; if (deleteUser != null) { result = await RoleManager.DeleteAsync(role); } else { result = await RoleManager.DeleteAsync(role); } if (!result.Succeeded) { ModelState.AddModelError("", result.Errors.First()); return(View()); } return(RedirectToAction("Index")); } return(View()); }
public async Task <bool> DeleteRole(object roleId) { string id = roleId.ToString(); var role = await roleManager.FindByIdAsync(id); if (role != null) { var result = await roleManager.DeleteAsync(role); return(result.Succeeded); } return(false); }
public async Task <string> Get(string roleName) { var context = ApplicationDbContext.Create(); var roleManager = new ApplicationRoleManager(new RoleStore <ApplicationRole>(context)); if (!roleManager.RoleExists(roleName)) { return("删除角色失败,该角色名称不存在"); } var role = roleManager.FindByName(roleName); await roleManager.DeleteAsync(role); return("删除角色成功"); }
public async Task <ActionResult> DeleteConfirmed(string id) { ApplicationRole applicationRole = await RoleManager.FindByIdAsync(id); if (applicationRole.Name == "Admin") { ModelState.AddModelError("", "You cannot delete the Admin role."); return(View(applicationRole)); } await RoleManager.DeleteAsync(applicationRole); return(RedirectToAction("Index")); }
public async Task <bool> RemoveRole(ClaimsPrincipal claim, ApplicationRoleViewModel data) { ApplicationRole roleData = _roleManager.Roles.FirstOrDefault(x => x.Id == data.Id); ExtBusinessLogic.CheckRecord(roleData); // ReSharper disable once PossibleNullReferenceException roleData.ModifiedBy = ExtBusinessLogic.UserValue(claim); var result = await _roleManager.DeleteAsync(roleData); if (!result.Succeeded) { throw new WebApiApplicationException(StatusCodes.Status400BadRequest, ErrorMessages.CommonErrorMessage, result.Errors.ToList()); } return(true); }
public async Task <IHttpActionResult> DeleteRole(string id) { var role = await roleManager.FindByIdAsync(id); if (role != null) { IdentityResult result = await roleManager.DeleteAsync(role); if (!result.Succeeded) { return(NotFound()); } return(Ok()); } return(NotFound()); }
public async Task <IHttpActionResult> DeleteRole(string id) { IdentityRole identityRole = await ApplicationRoleManager.FindByIdAsync(id); if (identityRole == null) { NotFound(); } IdentityResult identityResult = await ApplicationRoleManager.DeleteAsync(identityRole); if (!identityResult.Succeeded) { return(GetErrorResult(identityResult)); } return(Ok()); }
public async Task<IdentityResult> DeleteRole(JObject deleteRole) { string roleName = ((dynamic)deleteRole).Name.Value; string roleId = ((dynamic)deleteRole).Id.Value; IdentityResult result = null; var roleStore = new RoleStore<IdentityRole>(_contextProvider.Context); var roleManager = new ApplicationRoleManager(roleStore); var role = await roleManager.FindByNameAsync(roleName); //var role = await roleManager.FindByIdAsync(roleId); if (role != null) { result = await roleManager.DeleteAsync(role); } return result; }
public async Task <ActionResult> Delete(string id) { var role = await _roleManager.FindByIdAsync(id); if (role == null) { return(NotFound()); } var result = await _roleManager.DeleteAsync(role); if (!result.Succeeded) { throw new Exception($"Deleting role {id} failed on save."); } return(NoContent()); }
public async Task <IHttpActionResult> DeleteRole(Guid Id) { var role = await _applicationRoleManager.FindByIdAsync(Id); if (role != null) { IdentityResult result = await _applicationRoleManager.DeleteAsync(role); if (!result.Succeeded) { return(GetErrorResult(result)); } return(Ok()); } return(NotFound()); }
public async Task <ActionResult> Delete(string id) { var role = await _roleManager.FindByIdAsync(id); if (role == null) { return(NotFound()); } var result = await _roleManager.DeleteAsync(role); if (result.Succeeded) { return(NoContent()); } return(BadRequest()); }
public async Task<string> Get(string roleName, string action) { var context = ApplicationDbContext.Create(); var roleManager = new ApplicationRoleManager(new RoleStore<ApplicationRole>(context)); switch (action) { case createAction: if (roleManager.RoleExists(roleName)) return "新增角色失败,该角色名称已存在"; await roleManager.CreateAsync(new ApplicationRole(roleName)); return "新增角色成功"; case deleteAction: if (!roleManager.RoleExists(roleName)) return "删除角色失败,该角色名称不存在"; var role = roleManager.FindByName(roleName); await roleManager.DeleteAsync(role); return "删除角色成功"; default: return "无效的操作指令"; } }
public async Task <IActionResult> DeleteRole(int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } ApplicationRole role = await rolemanager.FindByIdAsync(id.ToString()); if (role == null) { return(NotFound()); } IdentityResult result = await rolemanager.DeleteAsync(role); if (result.Succeeded) { return(Ok(role)); } return(BadRequest(result.Errors)); }
public async Task <object> DeleteRole(Guid roleId) { ResponseMessageModel message; var role = await _roleManager.FindByIdAsync(roleId.ToString()); if (role == null) { message = new ResponseMessageModel { Code = MessageCode.OBJECT_NOT_FOUND }; return(message); } var result = await _roleManager.DeleteAsync(role); if (result.Succeeded) { message = new ResponseMessageModel { Code = MessageCode.SUCCESS, }; return(message); } //error occurs string errorMessage = ""; foreach (var error in result.Errors) { errorMessage += error.Description + "\r\n"; } message = new ResponseMessageModel { Code = MessageCode.SQL_ACTION_ERROR, ErrorMessage = errorMessage }; return(message); }
public async Task <ActionResult> DeleteRole_POST(DeleteRoleViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var role = await RoleManager.FindByNameAsync(model.Role); if (role == null) { ModelState.AddModelError("Role", $"The role '{model.Role}' does not exist!"); } else { await RoleManager.DeleteAsync(role); TempData["Message"] = $"Role '{model.Role}' deleted successfully!"; return(RedirectToAction("Index")); } return(View(model)); }
public async Task <IdentityResult> DeleteAsync(IdentityRole role) { return(await _appRoleManager.DeleteAsync(role)); }
public async Task <Tuple <bool, string[]> > DeleteRoleAsync(ApplicationRole role) { var result = await _appRoleManager.DeleteAsync(role); return(Tuple.Create(result.Succeeded, result.Errors.ToArray())); }
public async Task Delete(string id) { var role = await RoleManager.FindByIdAsync(id); await RoleManager.DeleteAsync(role); }
public async Task <IdentityResult> Remover(IdentityRole role) { return(await _roleManager.DeleteAsync(role)); }