Ejemplo n.º 1
0
        public ActionResult Edit(ArticleViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                if (viewModel.Id == 0)
                {
                    var article  = _mapper.MapToModel(viewModel);
                    var authorId = User.Identity.GetUserId();
                    _repo.Create(article, authorId);

                    TempData["SuccessMessage"] = "Article Created";
                    return(RedirectToAction("Index"));
                }
                else
                {
                    var article = _repo.Find(viewModel.Id);
                    _mapper.MapToModel(viewModel, article);
                    _repo.Update(article);

                    ViewBag.SuccessMessage = "Article Saved";
                    return(View(viewModel));
                }
            }

            return(View(viewModel));
        }
Ejemplo n.º 2
0
        public async Task <ApiResponse <MilestoneDetailsDto> > GetMileStoneById(Guid mileStoneId)
        {
            try
            {
                var milestone = await _milestoneRepository.GetByIdAsync(mileStoneId);

                if (milestone == null)
                {
                    return(new ApiResponse <MilestoneDetailsDto>()
                    {
                        StatusCode = 400,
                        IsSuccess = false,
                        ResponseException = new ApiError(ErrorCode.MileStoneNotFound, ErrorCode.MileStoneNotFound.GetDescription())
                    });
                }
                else
                {
                    var milestoneDetailsDto = _milestoneDetailsMapper.MapToModel(milestone);
                    return(new ApiResponse <MilestoneDetailsDto>(milestoneDetailsDto));
                }
            }
            catch (Exception e)
            {
                _logger.LogWarning(e, "An error occured while getting milestone by id {0} ", mileStoneId);
                return(ApiResponse <MilestoneDetailsDto> .InternalError());
            }
        }
Ejemplo n.º 3
0
        public bool HandleMessage(string message)
        {
            try
            {
                _logger.Info($"Message received '{message}'");

                var model = _mapper.MapToModel(message);

                if (model.IsSpecificCase)
                {
                    _completeCaseService.CompleteCase(model);
                }
                else
                {
                    _autoCompleteCasesService.CompleteCases(model);
                }

                //assuming we have completed case(s) we want to trigger the case monitor system
                TriggerCaseMonitor();

                _logger.Info($"Message processed '{message}'");

                return(true);
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
                _logger.Info($"Error processing message '{message}'");

                return(false);
            }
        }
Ejemplo n.º 4
0
        public async Task <ApiResponse <UserActivityDto> > GetAllActivitiesForUser(ActivitiesRequest request)
        {
            try
            {
                var userFoundResponse = await _userService.GetUsersById(request.UserId);

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

                var workLogActivities = (await _worklogRepository.GetActivitiesWithDetailsByUserId(request.UserId, request.ProjectId));
                var userActivity      = new UserActivityDto()
                {
                    UserId                = request.UserId,
                    UserName              = userFoundResponse.Data.FirstName,
                    UserSurname           = userFoundResponse.Data.LastName,
                    UserEmail             = userFoundResponse.Data.Email,
                    ProjectName           = workLogActivities?.Select(e => e.Issue?.Project?.Name).FirstOrDefault(),
                    TotalWorkLogInSeconds = workLogActivities?.Sum(e => e.TimeSpent),
                    WorkLogItems          = workLogActivities?.Select(e => _worklogDetailsMapper.MapToModel(e)).ToList(),
                };
                return(new ApiResponse <UserActivityDto>(userActivity));
            }
            catch (Exception e)
            {
                _logger.LogWarning(e, "An error occured while fetching workLog activities for user {0} ", request.UserId);
                return(ApiResponse <UserActivityDto> .InternalError());
            }
        }
Ejemplo n.º 5
0
        public async Task <ApiResponse <IssueDetailsDto> > GetIssueByIdAsync(Guid issueId)
        {
            try
            {
                var issueWithDetails = await _issueRepository.GetIssueWithDetails(issueId);

                if (issueWithDetails == null)
                {
                    return(new ApiResponse <IssueDetailsDto>()
                    {
                        StatusCode = 400,
                        IsSuccess = false,
                        ResponseException = new ApiError(ErrorCode.IssueNotFound, ErrorCode.IssueNotFound.GetDescription())
                    });
                }
                else
                {
                    var issueDetailed = _issueDetailsMapper.MapToModel(issueWithDetails);
                    issueDetailed.TotalRemainingTimeInSeconds = (long)(issueWithDetails.ClosedAt - issueWithDetails.OpenedAt).TotalSeconds;
                    issueDetailed.TotalSpentTimeInSeconds     = issueWithDetails.WorkLogs.Sum(e => e.TimeSpent);
                    return(new ApiResponse <IssueDetailsDto>(issueDetailed));
                }
            }
            catch (Exception ex)
            {
                _logger.LogWarning(ex, "An error occured while getting issue by id {0} ", issueId);
                return(ApiResponse <IssueDetailsDto> .InternalError());
            }
        }
Ejemplo n.º 6
0
        public async Task <ApiResponse <ProjectDetailsDto> > GetProjectByIdAsync(Guid projectId)
        {
            try
            {
                var project = await _projectRepository.GetByIdAsync(projectId);

                if (project == null)
                {
                    return(new ApiResponse <ProjectDetailsDto>()
                    {
                        StatusCode = 400,
                        IsSuccess = false,
                        ResponseException = new ApiError(ErrorCode.ProjectNotFound, ErrorCode.ProjectNotFound.GetDescription())
                    });
                }
                else
                {
                    var projectDetailsDto = _projectDetailsMapper.MapToModel(project);
                    return(new ApiResponse <ProjectDetailsDto>(projectDetailsDto));
                }
            }
            catch (Exception e)
            {
                _logger.LogWarning(e, "An error occured while getting project by id {0} ", projectId);
                return(ApiResponse <ProjectDetailsDto> .InternalError());
            }
        }
Ejemplo n.º 7
0
        public async Task <ApiResponse <TimeTrackingUserDetailsDto> > GetUsersById(Guid userId)
        {
            try
            {
                var user = await _userRepository.GetByIdAsync(userId);

                if (user == null)
                {
                    return(new ApiResponse <TimeTrackingUserDetailsDto>(new ApiError()
                    {
                        ErrorCode = ErrorCode.UserNotFound,
                        ErrorMessage = ErrorCode.UserNotFound.GetDescription(),
                    }, statusCode: 400));
                }

                return(new ApiResponse <TimeTrackingUserDetailsDto>(_userDetailsMapper.MapToModel(user)));
            }
            catch (Exception e)
            {
                _logger.LogWarning(e, "An error occured while getting user by id {0} ", userId);
                return(ApiResponse <TimeTrackingUserDetailsDto> .InternalError());
            }
        }
Ejemplo n.º 8
0
        public async Task <ApiResponse <TeamDetailsDto> > GetTeamById(Guid teamId)
        {
            try
            {
                var teamFounded = await _teamRepository.GetByIdWithDetails(teamId);

                if (teamFounded == null)
                {
                    _logger.LogWarning("Failed to found team by id {0}", teamId);
                    return(new ApiResponse <TeamDetailsDto>()
                    {
                        StatusCode = 400,
                        IsSuccess = false,
                        ResponseException = new ApiError(ErrorCode.TeamNotFound, ErrorCode.TeamNotFound.GetDescription())
                    });
                }
                return(new ApiResponse <TeamDetailsDto>(_teamDetailsMapper.MapToModel(teamFounded)));
            }
            catch (Exception e)
            {
                _logger.LogWarning(e, "An error occured while getting team by id {0} ", teamId);
                return(ApiResponse <TeamDetailsDto> .InternalError());
            }
        }