Example #1
0
        public async Task <IActionResult> ChangeAccessRightUserInProject([FromBody] ChangeAccessRightUserInProjectViewModel model)
        {
            EnumProjectAccessRight projectAccessRight = await _getAccessUser.GetUserAccessRightProject(Convert.ToInt32(HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier)), model.ProjectId);

            if (!HttpContext.User.IsInRole("admin") && projectAccessRight != EnumProjectAccessRight.Admin)
            {
                return(StatusCode(403, "Access Denied !"));
            }

            if (Convert.ToInt32(HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier)) == model.UserId)
            {
                return(BadRequest("You cannot change your access right in project"));
            }

            Result result = await _projectGateway.UpdateAccessRightUserInProject(model.UserId, model.ProjectId, model.AccessRightId);

            if (result.ErrorMessage == "User not belongs in this project")
            {
                return(BadRequest(result.ErrorMessage));
            }

            return(Ok("Access right changed"));
        }