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"));
            }
        }
Exemple #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));
     }
 }
 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."));
     }
 }
 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));
     }
 }
Exemple #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));
            }
        }
Exemple #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."));
     }
 }
Exemple #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")));
            }
        }
Exemple #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
             }
         }));
     }
 }