예제 #1
0
        public async Task CreateTimeEntry(Guid projectId, Guid issueId, Guid timeEntryId, decimal hours,
                                          string description, DateTime dueDate, Guid userId, Guid activityId, CancellationToken cancellationToken)
        {
            var project = await _projectRepository.Get(projectId, cancellationToken);

            if (project == null)
            {
                throw new ProjectNotFoundException();
            }

            var issue = await _issueRepository.Get(issueId, cancellationToken);

            if (issue == null)
            {
                throw new IssueNotFoundException();
            }

            var user = await _userRepository.Get(userId, cancellationToken);

            if (user == null)
            {
                throw new UserNotFoundException();
            }

            var activity = await _timeEntryActivityRepository.Get(activityId, cancellationToken);

            if (activity == null)
            {
                throw new TimeEntryActivityNotFoundException();
            }

            var timeEntry = await _timeEntryRepository.Get(timeEntryId, cancellationToken);

            if (timeEntry != null)
            {
                throw new TimeEntryAlreadyExistsException();
            }

            timeEntry = new TimeEntry(timeEntryId, hours, description, dueDate, projectId, userId, activityId);

            issue.AddTimeEntry(timeEntry);

            await _issueRepository.Save(issue);
        }
예제 #2
0
        public async Task <IActionResult> Create(
            CancellationToken cancellationToken,
            [FromBody] CreateTimeEntryActivityBinding binding,
            [FromServices] ITimeEntryActivityRepository timeEntryActivityRepository)
        {
            var timeEntryActivity = await timeEntryActivityRepository.Get(binding.Id, cancellationToken);

            if (timeEntryActivity != null)
            {
                if (!timeEntryActivity.Name.Equals(binding.Name))
                {
                    throw new ApiException(HttpStatusCode.Conflict, ErrorCode.TimeEntryActivityAlreadyExists,
                                           "Issue status already exists with other parameters");
                }
            }

            timeEntryActivity = new TimeEntryActivity(binding.Id, binding.Name, binding.IsActive);

            await timeEntryActivityRepository.Save(timeEntryActivity);

            return(CreatedAtRoute("GetTimeEntryActivityAdminRoute", new { id = timeEntryActivity.Id }, null));
        }