public async Task <IHttpActionResult> deleteone([FromUri] System.String id ) { aspnetroleView result = RoleManager.Roles .Where(p => p.Id == id) .Select(itm => new aspnetroleView() { Id = itm.Id, Name = itm.Name }).FirstOrDefault(); if (result == null) { return(NotFound()); } IdentityRole entityToDelete = RoleManager.Roles .Where(p => p.Id == result.Id) .FirstOrDefault(); if (entityToDelete == null) { return(Ok(result)); } IdentityResult rslt = await RoleManager.DeleteAsync(entityToDelete); if (!rslt.Succeeded) { return(GetErrorResult(rslt)); } return(Ok(result)); }
public IHttpActionResult addone([FromBody] aspnetroleView viewToAdd) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } IdentityRole entityToAdd = new IdentityRole() { Name = viewToAdd.Name }; /* * entityToAdd.Id = viewToAdd.Id; * entityToAdd.Name = viewToAdd.Name; */ IdentityResult rslt = RoleManager.Create(entityToAdd); if (!rslt.Succeeded) { return(GetErrorResult(rslt)); } aspnetroleView result = RoleManager.Roles.Where(p => p.Name == viewToAdd.Name) .Select(itm => new aspnetroleView() { Id = itm.Id, Name = itm.Name }).FirstOrDefault(); if (result == null) { return(NotFound()); } return(Ok(result)); }
public IHttpActionResult getone([FromUri] System.String id ) { aspnetroleView result = RoleManager.Roles .Where(p => p.Id == id) .Select(itm => new aspnetroleView() { Id = itm.Id, Name = itm.Name }).FirstOrDefault(); if (result == null) { return(NotFound()); } return(Ok(result)); } // the end of public GetOne()-method
public IHttpActionResult updateone([FromBody] aspnetroleView viewToUpdate) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } IdentityRole resultEntity = RoleManager.Roles .Where(p => p.Id == viewToUpdate.Id) .FirstOrDefault(); if (resultEntity == null) { return(NotFound()); } resultEntity.Name = viewToUpdate.Name; IdentityResult rslt = RoleManager.Update(resultEntity); if (!rslt.Succeeded) { return(GetErrorResult(rslt)); } aspnetroleView result = RoleManager.Roles .Where(p => p.Id == viewToUpdate.Id) .Select(itm => new aspnetroleView() { Id = itm.Id, Name = itm.Name }).FirstOrDefault(); if (result == null) { return(NotFound()); } return(Ok(result)); }