Ejemplo n.º 1
0
        public async Task <ApiResponse <WorkLogDto> > CreateWorkLog(WorkLogDto dto)
        {
            try
            {
                var issueFoundResponse = await _issueService.GetIssueByIdAsync(dto.IssueId);

                if (!issueFoundResponse.IsSuccess)
                {
                    return(issueFoundResponse.ToFailed <WorkLogDto>());
                }
                var entityToAdd = _worklogMapper.MapToEntity(dto);
                entityToAdd.IssueId = dto.IssueId;
                entityToAdd.UserId  = _userProvider.GetUserId();
                entityToAdd         = await _worklogRepository.AddAsync(entityToAdd);

                if (entityToAdd != null)
                {
                    return(new ApiResponse <WorkLogDto>(dto));
                }
                _logger.LogWarning("Failed to create entity {0}", JsonConvert.SerializeObject(dto));
                return(new ApiResponse <WorkLogDto>()
                {
                    StatusCode = 400,
                    IsSuccess = false,
                    ResponseException = new ApiError(ErrorCode.WorkLogCreationFailed, ErrorCode.WorkLogCreationFailed.GetDescription())
                });
            }
            catch (Exception ex)
            {
                _logger.LogWarning(ex, "An error occured while creating new worklog {0} ", JsonConvert.SerializeObject(dto));
                return(ApiResponse <WorkLogDto> .InternalError());
            }
        }
Ejemplo n.º 2
0
        public async Task <ApiResponse <ProjectDto> > CreateProjectAsync(ProjectDto dto)
        {
            try
            {
                var entityToAdd = _projectMapper.MapToEntity(dto);
                entityToAdd = await _projectRepository.AddAsync(entityToAdd);

                if (entityToAdd != null)
                {
                    return(new ApiResponse <ProjectDto>(_projectMapper.MapToModel(entityToAdd)));
                }
                _logger.LogWarning("Failed to create entity {0}", JsonConvert.SerializeObject(dto));
                return(new ApiResponse <ProjectDto>()
                {
                    StatusCode = 400,
                    IsSuccess = false,
                    ResponseException = new ApiError(ErrorCode.ProjectCreationFailed, ErrorCode.IssueCreationFailed.GetDescription())
                });
            }
            catch (Exception e)
            {
                _logger.LogError(e, "An error occured while adding project entity {0}", JsonConvert.SerializeObject(dto));
                return(ApiResponse <ProjectDto> .InternalError());
            }
        }
Ejemplo n.º 3
0
        public async Task <ApiResponse <IssueDto> > CreateIssue(IssueDto dto)
        {
            try
            {
                var entityToAdd = _issueMapper.MapToEntity(dto);
                if (dto.MilestoneId.HasValue)
                {
                    var mileStoneFoundResponse = await _mileStoneService.GetMileStoneById(dto.MilestoneId.Value);

                    if (!mileStoneFoundResponse.IsSuccess)
                    {
                        return(mileStoneFoundResponse.ToFailed <IssueDto>());
                    }
                }

                var projectFindResponse = await _projectService.GetProjectByIdAsync(dto.ProjectId);

                if (!projectFindResponse.IsSuccess)
                {
                    return(projectFindResponse.ToFailed <IssueDto>());
                }
                entityToAdd.ProjectId = dto.ProjectId;
                entityToAdd.OpenedAt  = _systemClock.UtcNow;
                entityToAdd.Status    = Status.Open;
                entityToAdd           = await _issueRepository.AddAsync(entityToAdd);

                if (entityToAdd != null)
                {
                    return(new ApiResponse <IssueDto>(dto));
                }
                _logger.LogWarning("Failed to create entity {0}", JsonConvert.SerializeObject(dto));
                return(new ApiResponse <IssueDto>()
                {
                    StatusCode = 400,
                    IsSuccess = false,
                    ResponseException = new ApiError(ErrorCode.IssueCreationFailed, ErrorCode.IssueCreationFailed.GetDescription())
                });
            }
            catch (Exception ex)
            {
                _logger.LogWarning(ex, "An error occured while creating new issue {0} ", JsonConvert.SerializeObject(dto));
                return(ApiResponse <IssueDto> .InternalError());
            }
        }
Ejemplo n.º 4
0
        public async Task <ApiResponse <MilestoneDto> > CreateMileStoneAsync(MilestoneDto dto)
        {
            try
            {
                var projectFound = await _projectRepository.GetByIdAsync(dto.ProjectId);

                if (projectFound == null)
                {
                    _logger.LogWarning("Failed to found project by id {0}", dto.ProjectId);
                    return(new ApiResponse <MilestoneDto>()
                    {
                        StatusCode = 400,
                        IsSuccess = false,
                        ResponseException = new ApiError(ErrorCode.ProjectNotFound, ErrorCode.ProjectNotFound.GetDescription())
                    });
                }
                var entityToAdd = _milestoneMapper.MapToEntity(dto);
                entityToAdd.CreatedByUserId = _userProvider.GetUserId();
                entityToAdd = await _milestoneRepository.AddAsync(entityToAdd);

                if (entityToAdd != null)
                {
                    return(new ApiResponse <MilestoneDto>(_milestoneMapper.MapToModel(entityToAdd)));
                }
                _logger.LogWarning("Failed to create milestone entity {0}", JsonConvert.SerializeObject(dto));
                return(new ApiResponse <MilestoneDto>()
                {
                    StatusCode = 400,
                    IsSuccess = false,
                    ResponseException = new ApiError(ErrorCode.MilestoneCreationFiled, ErrorCode.MilestoneCreationFiled.GetDescription())
                });
            }
            catch (Exception e)
            {
                _logger.LogError(e, "An error occured while creating milestone {0}", JsonConvert.SerializeObject(dto));
                return(ApiResponse <MilestoneDto> .InternalError());
            }
        }
Ejemplo n.º 5
0
        public async Task <ApiResponse <TeamDto> > CreateTeamAsync(TeamDto dto)
        {
            try
            {
                var projectFound = await _projectRepository.GetByIdAsync(dto.ProjectId);

                if (projectFound == null)
                {
                    _logger.LogWarning("Failed to found project by id {0}", dto.ProjectId);
                    return(new ApiResponse <TeamDto>()
                    {
                        StatusCode = 400,
                        IsSuccess = false,
                        ResponseException = new ApiError(ErrorCode.ProjectNotFound, ErrorCode.ProjectNotFound.GetDescription())
                    });
                }
                var entityToAdd = _teamMapper.MapToEntity(dto);
                entityToAdd = await _teamRepository.AddAsync(entityToAdd);

                if (entityToAdd != null)
                {
                    return(new ApiResponse <TeamDto>(dto));
                }
                _logger.LogWarning("Failed to create entity {0}", JsonConvert.SerializeObject(dto));
                return(new ApiResponse <TeamDto>()
                {
                    StatusCode = 400,
                    IsSuccess = false,
                    ResponseException = new ApiError(ErrorCode.TeamCreationFailed, ErrorCode.TeamCreationFailed.GetDescription())
                });
            }
            catch (Exception ex)
            {
                _logger.LogWarning(ex, "An error occured while creating new team {0} ", JsonConvert.SerializeObject(dto));
                return(ApiResponse <TeamDto> .InternalError());
            }
        }