Пример #1
0
        public async Task <ApiResponse <WorkLogDto> > UpdateWorkLog(WorkLogUpdateRequest workLogUpdateRequest)
        {
            try
            {
                var workLog = await _worklogRepository.GetByIdAsync(workLogUpdateRequest.WorkLogId);

                if (workLog == null)
                {
                    return(new ApiResponse <WorkLogDto>()
                    {
                        StatusCode = 400,
                        IsSuccess = false,
                        ResponseException = new ApiError(ErrorCode.WorkLogNotFound, ErrorCode.WorkLogNotFound.GetDescription())
                    });
                }
                workLog.Description  = workLogUpdateRequest.Description;
                workLog.ActivityType = workLogUpdateRequest.ActivityType;
                workLog.StartDate    = workLogUpdateRequest.StartDate;
                workLog.TimeSpent    = workLogUpdateRequest.TimeSpent;
                workLog = await _worklogRepository.UpdateAsync(workLog);

                return(new ApiResponse <WorkLogDto>(_worklogMapper.MapToModel(workLog)));
            }
            catch (Exception e)
            {
                _logger.LogError(e, "An error occured while updating workLog");
                return(ApiResponse <WorkLogDto> .InternalError());
            }
        }
Пример #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());
            }
        }
Пример #3
0
        public async Task <ApiResponse <IssueDto> > AssignIssueToUser(AssignIssueToUserRequest request)
        {
            try
            {
                var entityFound = await _issueRepository.GetByIdAsync(request.IssueId);

                if (entityFound == null)
                {
                    _logger.LogWarning("Failed to found issue by id {0}", request.IssueId);
                    return(new ApiResponse <IssueDto>()
                    {
                        StatusCode = 400,
                        IsSuccess = false,
                        ResponseException = new ApiError(ErrorCode.IssueNotFound, ErrorCode.IssueNotFound.GetDescription())
                    });
                }

                var userFoundResponse = await _userService.GetUsersById(request.UserId);

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

                entityFound.AssignedToUserId = request.UserId;
                entityFound.UpdatedAt        = _systemClock.UtcNow;
                await _issueRepository.UpdateAsync(entityFound);

                return(new ApiResponse <IssueDto>(_issueMapper.MapToModel(entityFound)));
            }
            catch (Exception ex)
            {
                _logger.LogWarning(ex, "An error occured while assigning user {0} for issue {1} ", request.UserId, request.IssueId);
                return(ApiResponse <IssueDto> .InternalError());
            }
        }
Пример #4
0
        public async Task <ApiResponse <TimeTrackingUserDto> > AddUserToTeam(AssignUserToTeamRequest request)
        {
            try
            {
                var teamFounded = await _teamRepository.GetByIdAsync(request.TeamId);

                if (teamFounded == null)
                {
                    _logger.LogWarning("Failed to found team by id {0}", request.TeamId);
                    return(new ApiResponse <TimeTrackingUserDto>()
                    {
                        StatusCode = 400,
                        IsSuccess = false,
                        ResponseException = new ApiError(ErrorCode.TeamNotFound, ErrorCode.TeamNotFound.GetDescription())
                    });
                }
                var userFound = await _userRepository.GetByIdAsync(request.UserId);

                if (userFound == null)
                {
                    _logger.LogWarning("Failed to find user by id {0}", request.UserId);
                    return(new ApiResponse <TimeTrackingUserDto>()
                    {
                        StatusCode = 400,
                        IsSuccess = false,
                        ResponseException = new ApiError(ErrorCode.UserNotFound, ErrorCode.UserNotFound.GetDescription())
                    });
                }

                userFound.TeamId = request.TeamId;
                userFound        = await _userRepository.UpdateAsync(userFound);

                return(new ApiResponse <TimeTrackingUserDto>(_userMapper.MapToModel(userFound)));
            }
            catch (Exception ex)
            {
                _logger.LogWarning(ex, "An error occured while assigning user {0] to team team {1} ", request.UserId, request.TeamId);
                return(ApiResponse <TimeTrackingUserDto> .InternalError());
            }
        }
        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());
            }
        }
 public async Task <ApiResponse <List <UserDto> > > GetAllUsers()
 {
     return(new ApiResponse <List <UserDto> >(
                (await _userRepository.GetAllAsync())
                .Select(user => _userMapper.MapToModel(user)).ToList()));
 }