示例#1
0
        public ActionResult Put(int id, [FromBody] RoleDTO value)
        {
            try
            {
                editRoleCommand.Execute(value);
                return(NoContent());
            }
            catch (DataNotFoundException)
            {
                return(NotFound());
            }
            catch (DataAlreadyExistsException)
            {
                return(Conflict("Role with that name already exists"));
            }
            catch (DataNotAlteredException)
            {
                return(Conflict("Role not changed"));
            }

            catch (Exception)
            {
                return(StatusCode(500, "Server is busy at the moment, please try later"));
            }
        }
示例#2
0
 public ActionResult Edit(int id, RoleDto dto)
 {
     if (!ModelState.IsValid)
     {
         return(View(dto));
     }
     try
     {
         // TODO: Add update logic here
         _editRole.Execute(dto);
         return(RedirectToAction(nameof(Index)));
     }
     catch (NotFoundException)
     {
         return(RedirectToAction(nameof(Index)));
     }
     catch (EntityAlreadyExistsException)
     {
         TempData["error"] = "Role with the same name already exists.";
         return(View(dto));
     }
     catch (Exception)
     {
         TempData["error"] = "Something went wrong. Please try again.";
         return(View(dto));
     }
 }
示例#3
0
 public IActionResult Put(int id, [FromBody] AddRoleDto dto)
 {
     try
     {
         dto.Id = id;
         _editRoleCommand.Execute(dto);
         return(StatusCode(204, "Successfully updated user."));
     }
     catch
     {
         return(StatusCode(422, "Error while trying to update user."));
     }
 }
示例#4
0
 public IActionResult Put(int id, [FromBody] RoleDto dto)
 {
     try
     {
         dto.Id = id;
         _editRole.Execute(dto);
         return(StatusCode(204));
     }
     catch (NotFoundException)
     {
         return(NotFound());
     }
     catch (EntityAlreadyExistsException)
     {
         return(StatusCode(422));
     }
 }
示例#5
0
 public ActionResult PutRole(int id, [FromBody] RoleDTO value)
 {
     try
     {
         _editRoleCommand.Execute(value);
         return(NoContent());
     }catch (AlredyExistException)
     {
         return(StatusCode(422, "Role name or isDelete alredy set."));
     }catch (NotFoundException)
     {
         return(NotFound());
     }catch (Exception)
     {
         return(StatusCode(500, "Server error, try later"));
     }
 }
        public ActionResult Put(int id, [FromBody] CreateRoleDto dto)
        {
            dto.Id = id;
            try
            {
                _editRole.Execute(dto);
                return(StatusCode(204));
            }
            catch (EntityAlreadyExistsException e)
            {
                return(UnprocessableEntity(e.Message));
            }
            catch (EntityNotFoundException e) {
                return(NotFound(e.Message));
            }

            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }
示例#7
0
 public ActionResult Put(int id, [FromBody] RoleDto dto)
 {
     dto.Id = id;
     try
     {
         _editCommand.Execute(dto);
         return(NoContent());
     }
     catch (EntityNotFoundException e)
     {
         return(NotFound(e.Message));
     }
     catch (EntityAlreadyExistsException e)
     {
         return(Conflict(e.Message));
     }
     catch (Exception)
     {
         return(StatusCode(500, "Server error has occurred."));
     }
 }
示例#8
0
        public async Task <ActionResult> Edit([FromRoute] string roleId,
                                              [FromBody] RoleCreateModel changes,
                                              [FromServices] IValidatorFactory validatorFactory,
                                              [FromServices] IEditRoleCommand editRoleCommand)
        {
            try
            {
                if (roleId == null || changes == null)
                {
                    return(BadRequest());
                }

                IValidator validator = validatorFactory.Create();
                await editRoleCommand.Execute(roleId, changes, validator);

                if (validator.HasErrors)
                {
                    return(BadRequest(validator.Errors));
                }
                else
                {
                    return(Created("", roleId));
                }
            }
            catch (Exception ex)
            {
                //Log error
                _logger.LogError("RoleController.Edit", "Exception was thrown", new
                {
                    RoleId    = roleId,
                    Changes   = changes,
                    Exception = ex
                });

                return(BadRequest(new Message("Something bad happened. Try again")));
            }
        }
示例#9
0
 public IActionResult Put(int id, [FromBody] RoleDto dto)
 {
     try
     {
         dto.Id = id;
         editRole.Execute(dto);
         return(StatusCode(204));
     }
     catch (EntityNotFoundException e)
     {
         return(NotFound(new
         {
             Errors = new List <string> {
                 e.Message
             }
         }));
     }
     catch (EntityAlreadyExistsException e)
     {
         return(StatusCode(409, new
         {
             Errors = new List <string> {
                 e.Message
             }
         }));
     }
     catch (Exception e)
     {
         return(StatusCode(500, new
         {
             Errors = new List <string> {
                 e.Message
             }
         }));
     }
 }