Ejemplo n.º 1
0
        public async Task <IActionResult> UpdateProject(string builderId, string projectId, [FromBody] ProjectUpdateModel projectUpdateModel)
        {
            var currentUserId = User.Identity.Name;

            try
            {
                if (User.IsInRole(Role.Admin))
                {
                    await _buildersService.UpdateProjectFromAdmin(projectId, projectUpdateModel);
                }
                else if (User.IsInRole(Role.Builder))
                {
                    await _buildersService.UpdateProjectFromBuilder(currentUserId, builderId, projectId, projectUpdateModel);
                }
                else
                {
                    return(Forbid("You must be part of the Buildup program"));
                }
            }
            catch (UnauthorizedAccessException e)
            {
                return(Forbid($"You are not allowed to update this project: {e.Message}"));
            }
            catch (Exception e)
            {
                return(BadRequest($"Can't update the project: {e.Message}"));
            }

            return(Ok());
        }