public HttpResponseMessage Update(HttpRequestMessage request, ApplicationRoleViewModel applicationRoleViewModel)
 {
     if (ModelState.IsValid)
     {
         var identity = (ClaimsIdentity)User.Identity;
         IEnumerable<Claim> claims = identity.Claims;
         var appRole = AppRoleManager.FindById(applicationRoleViewModel.Id);
         try
         {
             appRole.UpdateApplicationRole(applicationRoleViewModel, "update");
             AppRoleManager.Update(appRole);
             Log log = new Log()
             {
                 AppUserId = claims.FirstOrDefault().Value,
                 Content = Notification.UPDATE_ROLE,
                 Created = DateTime.Now
             };
             _logService.Create(log);
             _logService.Save();
             return request.CreateResponse(HttpStatusCode.OK, appRole);
         }
         catch (NameDuplicatedException dex)
         {
             return request.CreateErrorResponse(HttpStatusCode.BadRequest, dex.Message);
         }
     }
     else
     {
         return request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
     }
 }
        public HttpResponseMessage Update(HttpRequestMessage request, ApplicationRoleViewModel applicationRoleViewModel)
        {
            HttpResponseMessage response = null;

            return(CreateHttpResponse(request, () =>
            {
                if (ModelState.IsValid)
                {
                    AppRole roleDb = AppRoleManager.FindById(applicationRoleViewModel.Id);
                    roleDb.UpdateApplicationRole(applicationRoleViewModel, "update");
                    AppRoleManager.Update(roleDb);
                    response = request.CreateResponse(HttpStatusCode.Created, roleDb);
                }
                return response;
            }));
        }
Exemple #3
0
 public HttpResponseMessage Update(HttpRequestMessage request, ApplicationRoleViewModel applicationRoleViewModel)
 {
     return(CreateHttpResponse(request, () =>
     {
         HttpResponseMessage response = null;
         if (!ModelState.IsValid)
         {
             response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
         }
         else
         {
             var AppRole = AppRoleManager.FindById(applicationRoleViewModel.Id);
             AppRole.UpdateApplicationRole(applicationRoleViewModel, "update");
             AppRoleManager.Update(AppRole);
             response = request.CreateResponse(HttpStatusCode.OK, applicationRoleViewModel);
         }
         return response;
     }));
 }
 public HttpResponseMessage Update(HttpRequestMessage request, ApplicationRoleViewModel applicationRoleViewModel)
 {
     if (ModelState.IsValid)
     {
         var appRole = AppRoleManager.FindById(applicationRoleViewModel.Id);
         try
         {
             appRole.UpdateApplicationRole(applicationRoleViewModel, "update");
             AppRoleManager.Update(appRole);
             return(request.CreateResponse(HttpStatusCode.OK, appRole));
         }
         catch (NameDuplicatedException dex)
         {
             return(request.CreateErrorResponse(HttpStatusCode.BadRequest, dex.Message));
         }
     }
     else
     {
         return(request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
     }
 }
 public IHttpActionResult Update(ApplicationRoleViewModel applicationRoleViewModel)
 {
     if (ModelState.IsValid)
     {
         var appRole = AppRoleManager.FindById(applicationRoleViewModel.Id);
         try
         {
             appRole.UpdateApplicationRole(applicationRoleViewModel, "update");
             AppRoleManager.Update(appRole);
             return(Ok(appRole));
         }
         catch (NameDuplicatedException)
         {
             return(BadRequest());
         }
     }
     else
     {
         return(BadRequest());
     }
 }