public async Task <IActionResult> Update([FromRoute] string id, [FromBody] ProjectCreateDto dto)
        {
            if (!dto.IsValid())
            {
                return(BadRequest(new { message = "Invalid information" }));
            }

            var userId  = User.GetUserId();
            var project = await _repo.GetProject(id, userId);

            if (project == null)
            {
                return(NotFound("Project not found."));
            }

            project.Name        = dto.Name;
            project.Description = dto.Description;
            project.StartDate   = dto.StartDate;
            project.EndDate     = dto.EndDate;

            if (await _repo.SaveAll())
            {
                return(Ok(new
                {
                    project.Name,
                    project.Description,
                    project.StartDate,
                    project.EndDate
                }));
            }

            return(BadRequest());
        }
        public async Task <IActionResult> Create([FromBody] ProjectCreateDto dto)
        {
            if (!dto.IsValid())
            {
                return(BadRequest(new { message = "Invalid information" }));
            }

            var userId = User.GetUserId();
            var user   = await _repo.GetUser(userId);

            if (user == null)
            {
                return(NotFound(new { message = "User not found" }));
            }

            var newProject = _mapper.Map <Project>(dto);

            newProject.CreatedById = userId;

            _repo.Add(newProject);

            if (await _repo.SaveAll())
            {
                var projectUser = new ProjectUser
                {
                    ProjectId  = newProject.Id,
                    UserId     = userId,
                    UserRole   = Roles.MANAGER,
                    LastActive = DateTime.Now
                };

                _repo.Add(projectUser);

                if (await _repo.SaveAll())
                {
                    return(Ok(new { id = newProject.Id }));
                }

                return(BadRequest(new { message = "Error saving user data." }));
            }

            return(BadRequest(new { message = "Error creating the project." }));
        }