public HttpResponseMessage Update(HttpRequestMessage request, ApplicationRoleViewModel appRoleVm) { return(CreateHttpResponse(request, () => { if (ModelState.IsValid) { try { var newRole = _appRoleService.GetDetail(appRoleVm.Id); newRole.UpdateRole(appRoleVm); _appRoleService.Update(newRole); _appRoleService.Save(); var modelVm = Mapper.Map <AppRole, ApplicationRoleViewModel>(newRole); return request.CreateResponse(HttpStatusCode.OK, modelVm); } catch (Exception dex) { return request.CreateErrorResponse(HttpStatusCode.BadRequest, dex.Message); } } else { return request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } })); }
public HttpResponseMessage Update(HttpRequestMessage request, AppRoleViewModel appRoleViewModel) { if (ModelState.IsValid) { var appRole = _appRoleService.GetDetail(appRoleViewModel.Id); try { appRole.UpdateAppRole(appRoleViewModel, "update"); _appRoleService.Update(appRole); _appRoleService.Save(); return(request.CreateResponse(HttpStatusCode.OK, appRole)); } catch (NameDuplicatedException dex) { return(request.CreateErrorResponse(HttpStatusCode.BadRequest, dex.Message)); } } else { return(request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } }