Exemplo n.º 1
0
 public HttpResponseMessage Create(HttpRequestMessage request, ApplicationRoleViewModel applicationRoleViewModel)
 {
     if (ModelState.IsValid)
     {
         var newAppRole = new AppRole();
         var identity = (ClaimsIdentity)User.Identity;
         IEnumerable<Claim> claims = identity.Claims;
         newAppRole.UpdateApplicationRole(applicationRoleViewModel);
         try
         {
             AppRoleManager.Create(newAppRole);
             Log log = new Log()
             {
                 AppUserId = claims.FirstOrDefault().Value,
                 Content = Notification.CREATE_ROLE,
                 Created = DateTime.Now
             };
             _logService.Create(log);
             _logService.Save();
             return request.CreateResponse(HttpStatusCode.OK, applicationRoleViewModel);
         }
         catch (NameDuplicatedException dex)
         {
             return request.CreateErrorResponse(HttpStatusCode.BadRequest, dex.Message);
         }
     }
     else
     {
         return request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
     }
 }
Exemplo n.º 2
0
        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;
            }));
        }
Exemplo n.º 3
0
        public HttpResponseMessage Create(HttpRequestMessage request, ApplicationRoleViewModel applicationRoleViewModel)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (ModelState.IsValid)
                {
                    AppRole newRoleDb = new AppRole();
                    newRoleDb.UpdateApplicationRole(applicationRoleViewModel, "add");
                    AppRoleManager.Create(newRoleDb);
                    response = request.CreateResponse(HttpStatusCode.Created, newRoleDb);
                }

                return response;
            }));
        }
Exemplo n.º 4
0
 public HttpResponseMessage Create(HttpRequestMessage request, ApplicationRoleViewModel applicationRoleViewModel)
 {
     return(CreateHttpResponse(request, () =>
     {
         HttpResponseMessage response = null;
         if (!ModelState.IsValid)
         {
             response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
         }
         else
         {
             var newAppRole = new AppRole();
             newAppRole.UpdateApplicationRole(applicationRoleViewModel);
             AppRoleManager.Create(newAppRole);
             response = request.CreateResponse(HttpStatusCode.OK, applicationRoleViewModel);
         }
         return response;
     }));
 }
Exemplo n.º 5
0
 public HttpResponseMessage Create(HttpRequestMessage request, ApplicationRoleViewModel applicationRoleViewModel)
 {
     if (ModelState.IsValid)
     {
         var newAppRole = new AppRole();
         newAppRole.UpdateApplicationRole(applicationRoleViewModel);
         try
         {
             AppRoleManager.Create(newAppRole);
             return(request.CreateResponse(HttpStatusCode.OK, applicationRoleViewModel));
         }
         catch (NameDuplicatedException dex)
         {
             return(request.CreateErrorResponse(HttpStatusCode.BadRequest, dex.Message));
         }
     }
     else
     {
         return(request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
     }
 }