コード例 #1
0
        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);
            }
        }
コード例 #2
0
ファイル: UserProjectController.cs プロジェクト: Atlanf/Blog
        public async Task <IActionResult> CreateNewProjectAsync(CreateUserProjectRequest project)
        {
            var result = await _userProjectService.CreateProjectAsync(project, "admin");

            if (result == null)
            {
                return(BadRequest());
            }
            return(Ok(result));
        }