public async Task <UserProjectDetailsResponse> CreateProjectAsync( CreateUserProjectRequest projectToCreate, string userName) { var user = await _userRepository.GetUserIdByNameAsync(userName); if (!(await _userProjectRepository.IsUserProjectExistsAsync(projectToCreate.Title, user))) { var projectToAdd = _mapper.Map <UserProject>(projectToCreate); projectToAdd.User = await _userRepository.GetUserByNameAsync(userName); var result = await _userProjectRepository.AddUserProjectAsync(projectToAdd); if (result != null) { return(_mapper.Map <UserProjectDetailsResponse>(result)); } else { _logger.LogWarning("CreateProjectAsync result is NULL. ", projectToCreate, projectToAdd.User); return(null); } } else { _logger.LogInformation("CreateProjectAsync project with these credentials for this user already exists. Project: {@ProjectToCreate}; User: {@UserName}", projectToCreate, userName); return(null); } }
public async Task <IActionResult> CreateNewProjectAsync(CreateUserProjectRequest project) { var result = await _userProjectService.CreateProjectAsync(project, "admin"); if (result == null) { return(BadRequest()); } return(Ok(result)); }