Ejemplo n.º 1
0
        public async Task <IActionResult> GetProjectTickets(int id, [FromQuery] TicketParams ticketParams)
        {
            var ticketsFromRepo = await _repo.GetProjectTickets(id, ticketParams);

            var tickets = _mapper.Map <IEnumerable <TicketShortDto> >(ticketsFromRepo);

            return(Ok(new { tickets, ticketParams.Length }));
        }
Ejemplo n.º 2
0
        public AbstractTicketParam parse()
        {
            if (!string.IsNullOrWhiteSpace(dto.Description))
            {
                var template = Handlebars.Compile(dto.Description);
                var desc     = template(new { });
                dto.Description = desc;
            }
            if (!string.IsNullOrWhiteSpace(dto.Comment))
            {
                var template = Handlebars.Compile(dto.Comment);
                var comment  = template(new { });
                dto.Comment = comment;
            }


            var param = new TicketParams()
            {
                TicketId     = dto.TicketId,
                ActivityCode = dto.ActivityCode,
                ActionCode   = dto.ActionCode,
                Subject      = dto.Subject,
                Description  = dto.Description,

                TeamId             = dto.TeamId,
                Assignee           = dto.Assignee,
                StatusId           = dto.StatusId,
                SiteId             = dto.SiteId,
                ImpactId           = dto.ImpactId,
                DeptOwnerId        = dto.DeptOwnerId,
                CurrLoginUserId    = dto.CurrUser.id,
                PriorityId         = dto.PriorityId,
                RequestorId        = dto.RequestorId,
                SourceId           = dto.SourceId,
                TicketItemId       = dto.TicketItemId,
                TicketTypeId       = dto.TicketTypeId,
                UrgencyId          = dto.UrgencyId,
                UserAttachFiles    = dto.UserAttachFiles,
                UserAttachFilesDel = dto.UserAttachFilesDel,
                ActComment         = dto.Comment,
                EstimatedHours     = dto.EstimatedHours,
                DueDate            = dto.DueDate,
                TicketNoneReqEmp   = dto.TicketNoneReqEmp,
                AutomationType     = dto.IsAutomation? TicketParams.INTEGRATED_TYPE.EMAIL: TicketParams.INTEGRATED_TYPE.K2,
                SlaId     = dto.SlaId,
                RootCause = dto.RootCause,
                RefType   = dto.RefType,
                Reference = dto.Reference
            };

            if (String.IsNullOrEmpty(param.ActivityCode))
            {
                param.ActivityCode = TicketActivityHandler.ACTIVITY_CODE;
            }
            return(param);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> CustomerTicket([FromQuery] TicketParams ticketParams)
        {
            var tickets = await _repository.GetTickets(ticketParams);

            var ticketsToReturn = _mapper.Map <IEnumerable <TicketForListDto> >(tickets);

            Response.AddPagination(tickets.CurrentPage, tickets.PageSize, tickets.TotalCount, tickets.TotalPages);

            return(Ok(ticketsToReturn));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> GetUserTickets(string id, [FromQuery] TicketParams ticketParams)
        {
            int pageSize  = ticketParams.PageSize;
            int pageIndex = ticketParams.PageIndex;

            var ticketsFromRepo = await _repo.GetUserTickets(id, ticketParams);

            var tickets = _mapper.Map <IEnumerable <TicketShortDto> >(ticketsFromRepo);

            return(Ok(new { tickets, ticketParams.Length }));
        }
Ejemplo n.º 5
0
        public async Task <IEnumerable <Ticket> > GetProjectTickets(int id, TicketParams ticketParams)
        {
            var tickets = _context.Tickets
                          .Include(t => t.Status)
                          .Include(t => t.Category)
                          .Include(t => t.Priority)
                          .Include(t => t.User)
                          .Include(t => t.project).Where(t => t.project.Id == id).AsQueryable();


            tickets = TQuery.TicketQuery(ticketParams, tickets);
            return(await tickets.ToListAsync());
        }
Ejemplo n.º 6
0
        public async Task <IEnumerable <Ticket> > GetUserTickets(string id, TicketParams ticketParams)
        {
            var tickets = _context.Tickets
                          .OrderBy(t => t.SubmissionDate)
                          .Include(t => t.Status)
                          .Include(t => t.Category)
                          .Include(t => t.Priority)
                          .Include(t => t.project)
                          .Include(t => t.User).Where(t => t.User.Id.Equals(id))
                          .AsQueryable();

            tickets = TQuery.TicketQuery(ticketParams, tickets);
            return(await tickets.ToListAsync());
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> GetTickets([FromQuery] TicketParams ticketParams)
        {
            if (!string.IsNullOrEmpty(ticketParams.Token))
            {
                ticketParams.Token = _tokenService.GetTokenClaim(ticketParams.Token, "nameid");
            }

            var tickets = await _repository.GetTickets(ticketParams);

            var ticketsToReturn = _mapper.Map <IEnumerable <TicketForListDto> >(tickets);

            Response.AddPagination(tickets.CurrentPage, tickets.PageSize, tickets.TotalCount, tickets.TotalPages);

            return(Ok(ticketsToReturn));
        }
Ejemplo n.º 8
0
        public async Task <PagedList <Ticket> > GetTickets(TicketParams ticketParams)
        {
            var tickets = _context.Tickets
                          .Include(t => t.Item)
                          .Include(ps => ps.Item.ProductSpecification)
                          .Include(c => c.Item.Customer)
                          .Include(u => u.User).AsQueryable();

            if (ticketParams.PersonId != 0)
            {
                var customers = _context.Customers.Include(c => c.Person);
                var customer  = customers.FirstOrDefault(c => c.Person.Id == ticketParams.PersonId);
                if (customer != null)
                {
                    tickets = tickets.Where(t => t.Item.CustomerId == customer.Id);
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(ticketParams.Token))
                {
                    tickets = tickets.Where(t => t.UserId == Convert.ToInt32(ticketParams.Token));
                }

                if (!string.IsNullOrEmpty(ticketParams.OrderBy) && ticketParams.OrderBy == "lastOpen")
                {
                    tickets = tickets.OrderByDescending(u => u.Created);
                }
                if (!string.IsNullOrEmpty(ticketParams.OrderBy) && ticketParams.OrderBy == "lastClosed")
                {
                    tickets = tickets.OrderByDescending(u => u.Closed);
                }

                tickets = tickets.Where(t => t.Priority == ticketParams.Priority);
                tickets = tickets.Where(t => t.Status == ticketParams.Status);
            }

            return(await PagedList <Ticket> .CreateAsync(tickets, ticketParams.PageNumber, ticketParams.PageSize));
        }
        public async Task <PageList <Ticket> > GetTickets(TicketParams ticketParams)
        {
            var tickets = _context.Tickets
                          .Include(t => t.CreatedBy)
                          .Include(t => t.AssignedTo)
                          .Include(t => t.TicketPriority)
                          .Include(t => t.TicketStatus)
                          .Include(t => t.TicketType)
                          .Include(t => t.TicketQueue)
                          .Include(t => t.Client)
                          .AsQueryable();

            if (ticketParams.AssignedTo > 0)
            {
                tickets = tickets.Where(t => t.AssignedToId == ticketParams.AssignedTo);
            }

            if (ticketParams.CreatedBy > 0)
            {
                tickets = tickets.Where(t => t.CreatedById == ticketParams.CreatedBy);
            }

            if (!string.IsNullOrEmpty(ticketParams.Filter))
            {
                tickets = tickets.Where(t => t.Description.Contains(ticketParams.Filter) || t.Details.Contains(ticketParams.Filter));
            }

            if (ticketParams.TicketPriorityId > 0)
            {
                tickets = tickets.Where(t => t.TicketPriorityId == ticketParams.TicketPriorityId);
            }
            else if (!string.IsNullOrEmpty(ticketParams.TicketPriority))
            {
                tickets = tickets.Where(t => t.TicketPriority.Name == ticketParams.TicketPriority);
            }


            if (ticketParams.TicketStatusId > 0)
            {
                tickets = tickets.Where(t => t.TicketStatusId == ticketParams.TicketStatusId);
            }
            else if (!string.IsNullOrEmpty(ticketParams.TicketStatus))
            {
                tickets = tickets.Where(t => t.TicketStatus.Name == ticketParams.TicketStatus);
            }


            if (ticketParams.TicketTypeId > 0)
            {
                tickets = tickets.Where(t => t.TicketTypeId == ticketParams.TicketTypeId);
            }
            else if (!string.IsNullOrEmpty(ticketParams.TicketType))
            {
                tickets = tickets.Where(t => t.TicketType.Name == ticketParams.TicketType);
            }


            if (ticketParams.TicketQueueId > 0)
            {
                tickets = tickets.Where(t => t.TicketQueueId == ticketParams.TicketQueueId);
            }
            else if (!string.IsNullOrEmpty(ticketParams.TicketQueue))
            {
                tickets = tickets.Where(t => t.TicketQueue.Name == ticketParams.TicketQueue);
            }

            tickets = Sort(tickets, ticketParams.Sort, ticketParams.Direction);

            return(await PageList <Ticket> .CreateAsync(tickets, ticketParams.PageNumber, ticketParams.PageSize));
        }
        public async Task <int> GetTicketCount(TicketParams ticketParams)
        {
            var tickets = _context.Tickets
                          .Include(t => t.CreatedBy)
                          .Include(t => t.AssignedTo)
                          .Include(t => t.TicketPriority)
                          .Include(t => t.TicketStatus)
                          .Include(t => t.TicketType)
                          .Include(t => t.TicketQueue)
                          .Include(t => t.Client)
                          .AsQueryable();

            if (ticketParams.AssignedTo > 0)
            {
                tickets = tickets.Where(t => t.AssignedToId == ticketParams.AssignedTo);
            }

            if (ticketParams.CreatedBy > 0)
            {
                tickets = tickets.Where(t => t.CreatedById == ticketParams.CreatedBy);
            }

            if (ticketParams.TicketPriorityId > 0)
            {
                tickets = tickets.Where(t => t.TicketPriorityId == ticketParams.TicketPriorityId);
            }
            else if (!string.IsNullOrEmpty(ticketParams.TicketPriority))
            {
                tickets = tickets.Where(t => t.TicketPriority.Name == ticketParams.TicketPriority);
            }


            if (ticketParams.TicketStatusId > 0)
            {
                tickets = tickets.Where(t => t.TicketStatusId == ticketParams.TicketStatusId);
            }
            else if (!string.IsNullOrEmpty(ticketParams.TicketStatus))
            {
                tickets = tickets.Where(t => t.TicketStatus.Name == ticketParams.TicketStatus);
            }


            if (ticketParams.TicketTypeId > 0)
            {
                tickets = tickets.Where(t => t.TicketTypeId == ticketParams.TicketTypeId);
            }
            else if (!string.IsNullOrEmpty(ticketParams.TicketType))
            {
                tickets = tickets.Where(t => t.TicketType.Name == ticketParams.TicketType);
            }


            if (ticketParams.TicketQueueId > 0)
            {
                tickets = tickets.Where(t => t.TicketQueueId == ticketParams.TicketQueueId);
            }
            else if (!string.IsNullOrEmpty(ticketParams.TicketQueue))
            {
                tickets = tickets.Where(t => t.TicketQueue.Name == ticketParams.TicketQueue);
            }


            var count = await tickets.CountAsync();

            return(count);
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> TicketCount([FromQuery] TicketParams ticketParams)
        {
            var count = await _repo.GetTicketCount(ticketParams);

            return(Ok(count));
        }
Ejemplo n.º 12
0
        public async Task VerifyGetTickets()
        {
            //Arange
            var tickets = new List <Ticket>
            {
                new Ticket
                {
                    Id               = 1,
                    Number           = "INC123456",
                    Description      = "This is a test Ticket",
                    Details          = "Test Ticket Details",
                    CreatedAt        = DateTime.Now,
                    UpdatedAt        = DateTime.Now,
                    CreatedById      = 1,
                    AssignedToId     = 1,
                    TicketTypeId     = 1,
                    TicketPriorityId = 1,
                    TicketStatusId   = 1,
                    TicketQueueId    = 1,
                    ClientId         = 1,
                    ConfigItemId     = 1,
                },
                new Ticket
                {
                    Id               = 1,
                    Number           = "INC123456",
                    Description      = "This is a test Ticket",
                    Details          = "Test Ticket Details",
                    CreatedAt        = DateTime.Now,
                    UpdatedAt        = DateTime.Now,
                    CreatedById      = 1,
                    AssignedToId     = 1,
                    TicketTypeId     = 1,
                    TicketPriorityId = 1,
                    TicketStatusId   = 1,
                    TicketQueueId    = 1,
                    ClientId         = 1,
                    ConfigItemId     = 1,
                }
            }.AsQueryable();

            var mockSet = new Mock <DbSet <Ticket> >();

            mockSet.As <IAsyncEnumerable <Ticket> >().Setup(m => m.GetEnumerator())
            .Returns(new TestAsyncEnumerator <Ticket>(tickets.GetEnumerator()));

            mockSet.As <IQueryable <Ticket> >().Setup(m => m.Provider)
            .Returns(new TestAsyncQueryProvider <Ticket>(tickets.Provider));

            mockSet.As <IQueryable <Ticket> >().Setup(m => m.Expression).Returns(tickets.Expression);
            mockSet.As <IQueryable <Ticket> >().Setup(m => m.ElementType).Returns(tickets.ElementType);
            mockSet.As <IQueryable <Ticket> >().Setup(m => m.GetEnumerator()).Returns(tickets.GetEnumerator());

            var mockContext = new Mock <AppDbContext>();

            mockContext.Setup(c => c.Tickets).Returns(mockSet.Object);

            var ticketRepo = new TicketRepository(mockContext.Object);
            var userRepo   = new Mock <IUsersRepository>();
            var clientRepo = new Mock <IClientRepository>();
            var mapper     = new Mock <IMapper>();
            var controller = new TicketsController(ticketRepo, mapper.Object,
                                                   userRepo.Object, clientRepo.Object);

            var ticketParams = new TicketParams();

            //Act
            var actionResult = await controller.GetTickets(ticketParams);

            var repoResult = await ticketRepo.GetTickets(ticketParams);

            //Assert
            var okResult     = actionResult.Should().BeOfType <OkObjectResult>().Subject;
            var ticketResult = okResult.Value.Should().BeAssignableTo <ICollection <TicketListDto> >().Subject;

            Assert.Equal(3, repoResult.Count);
        }