Ejemplo n.º 1
0
        public async Task <Issue> AddAsync(Issue issue)
        {
            var issueEntity = _mapper.Map <Data.Issues.Issue>(issue);

            issueEntity.Date = DateTime.Now;

            await _issueRepository.CreateAsync(issueEntity);

            return(_mapper.Map(issueEntity, issue));
        }
Ejemplo n.º 2
0
        private IList <HistoryChange> GetIssueChanges(Issue pristineIssue, Issue updatedIssue)
        {
            var builder = new HistoryChangesBuilder(pristineIssue, updatedIssue);

            builder.AppendDiff(nameof(Issue.Title), issue => issue.Title);
            builder.AppendDiff(nameof(Issue.Description), issue => issue.Description);
            builder.AppendDiff(nameof(Issue.Priority), issue => issue.Priority);
            builder.AppendDiff(nameof(Issue.Status), issue => issue.Status);
            builder.AppendDiff(nameof(Issue.Type), issue => issue.Type);
            builder.AppendDiff(nameof(Issue.Assigned), issue => issue.Assigned.Id);

            var changes = builder.Build();

            return(changes);
        }
Ejemplo n.º 3
0
        public async Task <Issue> UpdateAsync(Issue issue, User updater)
        {
            var pristineIssue = await GetByIdAsync(issue.Id);

            if (pristineIssue == null)
            {
                throw new NotFoundException();
            }

            var changes       = GetIssueChanges(pristineIssue, issue);
            var historyEntity = new Data.Histories.History
            {
                IssueId   = pristineIssue.Id,
                UpdaterId = updater.Id,
                Date      = DateTime.Now,
                Changes   = changes.Select(_mapper.Map <Data.Histories.HistoryChange>).ToList(),
            };

            await _historyRepository.CreateAsync(historyEntity);

            var history = _mapper.Map <History>(historyEntity);

            if (pristineIssue.Histories == null)
            {
                issue.Histories = new List <History>();
            }
            else
            {
                issue.Histories = pristineIssue.Histories;
            }
            issue.Histories.Add(history);

            var updatedIssueEntity = _mapper.Map <Data.Issues.Issue>(issue);
            await _issueRepository.UpdateAsync(updatedIssueEntity);

            return(_mapper.Map(updatedIssueEntity, issue));
        }
Ejemplo n.º 4
0
 public Task DeleteAsync(Issue issue, User updater)
 {
     issue.Status = Status.Removed;
     return(UpdateAsync(issue, updater));
 }