public IActionResult Edit(GeekyRole geekyRole) { if (ModelState.IsValid) { var res = _roleManager.UpdateAsync(geekyRole).Result; if (res.Succeeded) { return(RedirectToAction("Index")); } return(RedirectToAction("Index", new { Message = RolesMessageId.ConcurrecyError })); } return(View()); }
public IActionResult PostRole([FromBody] GeekyRole geekyRole) { if (!ModelState.IsValid) { return(HttpBadRequest(ModelState)); } var res = _roleManager.CreateAsync(geekyRole); if (!res.Result.Succeeded) { } return(CreatedAtRoute("GetGeekyRole", new { id = geekyRole.Id }, geekyRole)); }
public IActionResult GetRole([FromRoute] string id) { if (!ModelState.IsValid) { return(HttpBadRequest(ModelState)); } GeekyRole geekyRole = _roleManager.Roles.Single(m => m.Id == id); if (geekyRole == null) { return(HttpNotFound()); } return(Ok(geekyRole)); }
public IActionResult Create(GeekyRole geekyRole) { if (ModelState.IsValid) { geekyRole.Id = Guid.NewGuid().ToString(); geekyRole.ConcurrencyStamp = Guid.NewGuid().ToString(); var res = _roleManager.CreateAsync(geekyRole); if (res.Result.Succeeded) { return(RedirectToAction("Index")); } return(View()); } return(View(geekyRole)); }
public IActionResult DeleteRole(string id) { if (!ModelState.IsValid) { return(HttpBadRequest(ModelState)); } GeekyRole geekyRole = _roleManager.Roles.Single(m => m.Id == id); if (geekyRole == null) { return(HttpNotFound()); } var res = _roleManager.DeleteAsync(geekyRole); if (!res.Result.Succeeded) { return(Content(res.Result.Errors.FirstOrDefault().Description)); } return(Ok(geekyRole)); }
public IActionResult PutRole(string id, [FromBody] GeekyRole geekyRole) { if (!ModelState.IsValid) { return(HttpBadRequest(ModelState)); } if (id != geekyRole.Id) { return(HttpBadRequest()); } try { var res = _roleManager.UpdateAsync(geekyRole); return(!res.Result.Succeeded ? new HttpStatusCodeResult(StatusCodes.Status500InternalServerError) : Ok()); } catch (Exception ex) { return(Content(ex.Message)); } }