Ejemplo n.º 1
0
        public async Task <IActionResult> AddProject([FromBody] ProjectDTO projectDTO)
        {
            ProjectDTO addedProject = null;


            if (!User.Identity.IsAuthenticated)
            {
                return(Unauthorized());
            }

            var userId = User.FindFirst(ClaimTypes.UserData).Value;

            addedProject = _projectService.AddProject(projectDTO, userId);
            if (addedProject == null)
            {
                return(new StatusCodeResult(StatusCodes.Status409Conflict));
            }

            var accountId = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            var res       = await _accountService.AddUserRole("all", projectDTO.Id, accountId);

            if (addedProject != null && res.Succeeded)
            {
                return(new CreatedAtRouteResult("GetProjectByAcc", new { projectId = addedProject.Id }, addedProject));
            }

            return(new StatusCodeResult(StatusCodes.Status409Conflict));
        }