Exemplo n.º 1
0
        public async Task <QueryResult <SupportTicket> > GetAllTicketsAsync(SupportTicketQuery queryObj)
        {
            var query = this.context.SupportTickets
                        .Include(st => st.User)
                        .ThenInclude(stu => stu.UserRoles)
                        .ThenInclude(stur => stur.Role)
                        .Include(st => st.Status)
                        .Include(st => st.Topic)
                        .Include(st => st.Priority)
                        .AsQueryable();

            var FilterColumnsMap = new Dictionary <string, Expression <Func <SupportTicket, bool> > >()
            {
                ["UserId"]     = st => st.UserId == queryObj.UserId,
                ["TopicId"]    = st => st.TopicId == queryObj.TopicId,
                ["StatusId"]   = st => st.StatusId == queryObj.StatusId,
                ["PriorityId"] = st => st.PriorityId == queryObj.PriorityId
            };

            query = this.ApplyTicketFiltering(query, queryObj, FilterColumnsMap);

            query.ApplyPaging(queryObj);

            var result = new QueryResult <SupportTicket>();

            result.TotalItems = await query.CountAsync();

            result.Items = await query.ToListAsync();

            return(result);;
        }
Exemplo n.º 2
0
        private IQueryable <SupportTicket> ApplyTicketFiltering(IQueryable <SupportTicket> query, SupportTicketQuery queryObj, Dictionary <string, Expression <Func <SupportTicket, bool> > > columnsMap)
        {
            if (!string.IsNullOrWhiteSpace(queryObj.UserId) && columnsMap.ContainsKey(QueryFilter.UserId.ToString()))
            {
                return(query.Where(columnsMap[QueryFilter.UserId.ToString()]).AsQueryable());
            }

            if (queryObj.TopicId.HasValue && columnsMap.ContainsKey(QueryFilter.TopicId.ToString()))
            {
                return(query.Where(columnsMap[QueryFilter.TopicId.ToString()]).AsQueryable());
            }

            if (queryObj.StatusId.HasValue && columnsMap.ContainsKey(QueryFilter.StatusId.ToString()))
            {
                return(query.Where(columnsMap[QueryFilter.StatusId.ToString()]).AsQueryable());
            }

            if (queryObj.PriorityId.HasValue && columnsMap.ContainsKey(QueryFilter.PriorityId.ToString()))
            {
                return(query.Where(columnsMap[QueryFilter.PriorityId.ToString()]).AsQueryable());
            }

            return(query);
        }