Ejemplo n.º 1
0
        public async Task <IActionResult> Update([FromBody] AppRoleViewModel appRoleVm)
        {
            var hasPermission = await _authorizationService.AuthorizeAsync(User, "ROLE", Operations.Update);

            if (hasPermission.Succeeded == false)
            {
                return(new BadRequestObjectResult(CommonConstants.Forbidden));
            }
            if (ModelState.IsValid)
            {
                try
                {
                    AppRole appRole = await _roleManager.FindByIdAsync(appRoleVm.Id.ToString());

                    appRole.UpdateAppRole(appRoleVm);
                    await _roleManager.UpdateAsync(appRole);

                    return(new OkObjectResult(appRoleVm));
                }
                catch (Exception ex)
                {
                    return(new BadRequestObjectResult(ex.Message));
                }
            }
            return(new BadRequestObjectResult(ModelState));
        }
        public ActionResult Create(AppRoleViewModel model)
        {
            if (ModelState.IsValid)
            {
                var role = new AppRole();
                role.UpdateAppRole(model);
                _roleService.Add(role);
                _roleService.Save();
                SetAlert("Added successfully", "success");

                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
Ejemplo n.º 3
0
 public HttpResponseMessage Create(HttpRequestMessage request, AppRoleViewModel appRoleViewModel)
 {
     if (ModelState.IsValid)
     {
         var newAppRole = new AppRole();
         newAppRole.UpdateAppRole(appRoleViewModel);
         try
         {
             _appRoleService.Add(newAppRole);
             _appRoleService.Save();
             return(request.CreateResponse(HttpStatusCode.OK, appRoleViewModel));
         }
         catch (NameDuplicatedException dex)
         {
             return(request.CreateErrorResponse(HttpStatusCode.BadRequest, dex.Message));
         }
     }
     else
     {
         return(request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
     }
 }