public BeforeTicketsLinkedWorkflow(int fromTicketId, int toTicketId, TicketLinkType linkType)
     : base(fromTicketId, toTicketId, linkType)
 {
 }
Пример #2
0
        public virtual async Task <ProcessResult> Link(int fromTicketId, int toTicketId, TicketLinkType linkType)
        {
            if (fromTicketId == toTicketId)
            {
                throw new ArgumentException("Cannot link a ticket to itself.");
            }

            if (_repository.SingleAsync(new GetTicketById(fromTicketId).AsNoTracking()) == null)
            {
                return(new TicketNotFoundResult(fromTicketId));
            }

            if (_repository.SingleAsync(new GetTicketById(toTicketId).AsNoTracking()) == null)
            {
                return(new TicketNotFoundResult(toTicketId));
            }

            var fromTicket = await _repository.GetAsync(new GetTicketLinkById(fromTicketId, toTicketId).AsNoTracking());

            if (fromTicket != null)
            {
                return(new TicketsAlreadyLinkedResult(fromTicketId, toTicketId, fromTicket.LinkType));
            }

            var toTicket = await _repository.GetAsync(new GetTicketLinkById(toTicketId, fromTicketId).AsNoTracking());

            if (toTicket != null)
            {
                return(new TicketsAlreadyLinkedResult(toTicketId, fromTicketId, toTicket.LinkType));
            }

            await _workflowService.Process(new BeforeTicketsLinkedWorkflow(fromTicketId, toTicketId, linkType));

            var ticketLink = new TicketLink(fromTicketId, toTicketId);
            await _repository.AddAsync(ticketLink);

            await _repository.SaveAsync();

            var workflow     = _workflowService.Process(new TicketsLinkedWorkflow(fromTicketId, toTicketId, linkType));
            var notification = _notificationService.Queue(new TicketsLinkedNotification(fromTicketId, toTicketId, linkType));
            await Task.WhenAll(workflow, notification);

            return(new TicketsLinkedResult(fromTicketId, toTicketId, linkType));
        }
Пример #3
0
 public TicketsLinkedEvent(int fromTicketId, int toTicketId, TicketLinkType linkType)
 {
     FromTicketId = fromTicketId;
     ToTicketId   = toTicketId;
     LinkType     = linkType;
 }
Пример #4
0
 public TicketsLinkedNotification(int fromTicketId, int toTicketId, TicketLinkType linkType)
     : base(fromTicketId, toTicketId, linkType)
 {
 }