Example #1
0
        public async Task <Response <TicketViewModel> > Handle(AddTicketCommand request,
                                                               CancellationToken cancellationToken)
        {
            var ticket = CreateTicket(request);
            await _ticketRepo.AddAsync(ticket);

            return(Response <TicketViewModel> .Success(_mapper.Map <TicketViewModel>(_ticketRepo.GetQueryable()
                                                                                     .Include(x => x.User).Single(x => x.Id == ticket.Id))));
        }
Example #2
0
        private Ticket CreateTicket(AddTicketCommand request)
        {
            var ticket = new Ticket
            {
                LastMessageText = request.Description,
                UserId          = _workContext.CurrentUserId,
                State           = TicketState.Open,
                UpdatedOn       = DateTime.Now,
                CreatedOn       = DateTime.Now,
                TicketReason    = request.Title,
                OperatorUnReadedMessagesCount = 1,
                TicketItems = new List <TicketItem>
                {
                    new TicketItem
                    {
                        UserId  = _workContext.CurrentUserId,
                        Message = request.Description,
                    }
                }
            };

            if (request.CourseId.HasValue && request.CourseId != 0)
            {
                ticket.CategoryId = _ticktCategoryRepository.GetQueryable()
                                    .First(x => x.CategoryType == TicketCategoryType.RelatedToTeacher).Id;
            }
            if (request.CategoryId.HasValue && request.CategoryId.Value != 0)
            {
                ticket.CategoryId = request.CategoryId.Value;
            }
            else
            {
                ticket.CategoryId = _ticktCategoryRepository.GetQueryable()
                                    .First(x => x.CategoryType == TicketCategoryType.RelatedToSupport).Id;
            }

            return(ticket);
        }