Exemplo n.º 1
0
        private IQueryable <SLAPolicyDAO> OrFilter(IQueryable <SLAPolicyDAO> query, SLAPolicyFilter filter)
        {
            if (filter.OrFilter == null || filter.OrFilter.Count == 0)
            {
                return(query);
            }
            IQueryable <SLAPolicyDAO> initQuery = query.Where(q => false);

            foreach (SLAPolicyFilter SLAPolicyFilter in filter.OrFilter)
            {
                IQueryable <SLAPolicyDAO> queryable = query;
                if (SLAPolicyFilter.Id != null)
                {
                    queryable = queryable.Where(q => q.Id, SLAPolicyFilter.Id);
                }
                if (SLAPolicyFilter.TicketIssueLevelId != null)
                {
                    queryable = queryable.Where(q => q.TicketIssueLevelId.HasValue).Where(q => q.TicketIssueLevelId, SLAPolicyFilter.TicketIssueLevelId);
                }
                if (SLAPolicyFilter.TicketPriorityId != null)
                {
                    queryable = queryable.Where(q => q.TicketPriorityId.HasValue).Where(q => q.TicketPriorityId, SLAPolicyFilter.TicketPriorityId);
                }
                if (SLAPolicyFilter.FirstResponseTime != null)
                {
                    queryable = queryable.Where(q => q.FirstResponseTime.HasValue).Where(q => q.FirstResponseTime, SLAPolicyFilter.FirstResponseTime);
                }
                if (SLAPolicyFilter.ResolveTime != null)
                {
                    queryable = queryable.Where(q => q.ResolveTime.HasValue).Where(q => q.ResolveTime, SLAPolicyFilter.ResolveTime);
                }
                initQuery = initQuery.Union(queryable);
            }
            return(initQuery);
        }
Exemplo n.º 2
0
        public async Task <int> Count(SLAPolicyFilter filter)
        {
            IQueryable <SLAPolicyDAO> SLAPolicies = DataContext.SLAPolicy.AsNoTracking();

            SLAPolicies = DynamicFilter(SLAPolicies, filter);
            return(await SLAPolicies.CountAsync());
        }
Exemplo n.º 3
0
        public async Task <List <SLAPolicy> > List(SLAPolicyFilter filter)
        {
            if (filter == null)
            {
                return(new List <SLAPolicy>());
            }
            IQueryable <SLAPolicyDAO> SLAPolicyDAOs = DataContext.SLAPolicy.AsNoTracking();

            SLAPolicyDAOs = DynamicFilter(SLAPolicyDAOs, filter);
            SLAPolicyDAOs = DynamicOrder(SLAPolicyDAOs, filter);
            List <SLAPolicy> SLAPolicies = await DynamicSelect(SLAPolicyDAOs, filter);

            return(SLAPolicies);
        }
Exemplo n.º 4
0
        public SLAPolicyFilter ToFilter(SLAPolicyFilter filter)
        {
            if (filter.OrFilter == null)
            {
                filter.OrFilter = new List <SLAPolicyFilter>();
            }
            if (CurrentContext.Filters == null || CurrentContext.Filters.Count == 0)
            {
                return(filter);
            }
            foreach (var currentFilter in CurrentContext.Filters)
            {
                SLAPolicyFilter subFilter = new SLAPolicyFilter();
                filter.OrFilter.Add(subFilter);
                List <FilterPermissionDefinition> FilterPermissionDefinitions = currentFilter.Value;
                foreach (FilterPermissionDefinition FilterPermissionDefinition in FilterPermissionDefinitions)
                {
                    if (FilterPermissionDefinition.Name == nameof(subFilter.Id))
                    {
                        subFilter.Id = FilterPermissionDefinition.IdFilter;
                    }
                    if (FilterPermissionDefinition.Name == nameof(subFilter.TicketIssueLevelId))
                    {
                        subFilter.TicketIssueLevelId = FilterPermissionDefinition.IdFilter;
                    }
                    if (FilterPermissionDefinition.Name == nameof(subFilter.TicketPriorityId))
                    {
                        subFilter.TicketPriorityId = FilterPermissionDefinition.IdFilter;
                    }
                    if (FilterPermissionDefinition.Name == nameof(subFilter.FirstResponseTime))
                    {
                        subFilter.FirstResponseTime = FilterPermissionDefinition.LongFilter;
                    }



                    if (FilterPermissionDefinition.Name == nameof(subFilter.ResolveTime))
                    {
                        subFilter.ResolveTime = FilterPermissionDefinition.LongFilter;
                    }
                }
            }
            return(filter);
        }
Exemplo n.º 5
0
        public async Task <bool> ValidateId(SLAPolicy SLAPolicy)
        {
            SLAPolicyFilter SLAPolicyFilter = new SLAPolicyFilter
            {
                Skip = 0,
                Take = 10,
                Id   = new IdFilter {
                    Equal = SLAPolicy.Id
                },
                Selects = SLAPolicySelect.Id
            };

            int count = await UOW.SLAPolicyRepository.Count(SLAPolicyFilter);

            if (count == 0)
            {
                SLAPolicy.AddError(nameof(SLAPolicyValidator), nameof(SLAPolicy.Id), ErrorCode.IdNotExisted);
            }
            return(count == 1);
        }
Exemplo n.º 6
0
        public async Task <List <SLAPolicy> > List(SLAPolicyFilter SLAPolicyFilter)
        {
            try
            {
                List <SLAPolicy> SLAPolicys = await UOW.SLAPolicyRepository.List(SLAPolicyFilter);

                return(SLAPolicys);
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    await Logging.CreateSystemLog(ex, nameof(SLAPolicyService));

                    throw new MessageException(ex);
                }
                else
                {
                    await Logging.CreateSystemLog(ex.InnerException, nameof(SLAPolicyService));

                    throw new MessageException(ex.InnerException);
                }
            }
        }
Exemplo n.º 7
0
        public async Task <int> Count(SLAPolicyFilter SLAPolicyFilter)
        {
            try
            {
                int result = await UOW.SLAPolicyRepository.Count(SLAPolicyFilter);

                return(result);
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    await Logging.CreateSystemLog(ex, nameof(SLAPolicyService));

                    throw new MessageException(ex);
                }
                else
                {
                    await Logging.CreateSystemLog(ex.InnerException, nameof(SLAPolicyService));

                    throw new MessageException(ex.InnerException);
                }
            }
        }
Exemplo n.º 8
0
 private IQueryable <SLAPolicyDAO> DynamicFilter(IQueryable <SLAPolicyDAO> query, SLAPolicyFilter filter)
 {
     if (filter == null)
     {
         return(query.Where(q => false));
     }
     query = query.Where(q => !q.DeletedAt.HasValue);
     if (filter.CreatedAt != null)
     {
         query = query.Where(q => q.CreatedAt, filter.CreatedAt);
     }
     if (filter.UpdatedAt != null)
     {
         query = query.Where(q => q.UpdatedAt, filter.UpdatedAt);
     }
     if (filter.Id != null)
     {
         query = query.Where(q => q.Id, filter.Id);
     }
     if (filter.TicketIssueLevelId != null)
     {
         query = query.Where(q => q.TicketIssueLevelId.HasValue).Where(q => q.TicketIssueLevelId, filter.TicketIssueLevelId);
     }
     if (filter.TicketPriorityId != null)
     {
         query = query.Where(q => q.TicketPriorityId.HasValue).Where(q => q.TicketPriorityId, filter.TicketPriorityId);
     }
     if (filter.FirstResponseTime != null)
     {
         query = query.Where(q => q.FirstResponseTime.HasValue).Where(q => q.FirstResponseTime, filter.FirstResponseTime);
     }
     if (filter.ResolveTime != null)
     {
         query = query.Where(q => q.ResolveTime.HasValue).Where(q => q.ResolveTime, filter.ResolveTime);
     }
     query = OrFilter(query, filter);
     return(query);
 }
Exemplo n.º 9
0
        private async Task <List <SLAPolicy> > DynamicSelect(IQueryable <SLAPolicyDAO> query, SLAPolicyFilter filter)
        {
            List <SLAPolicy> SLAPolicies = await query.Select(q => new SLAPolicy()
            {
                Id = filter.Selects.Contains(SLAPolicySelect.Id) ? q.Id : default(long),
                TicketIssueLevelId = filter.Selects.Contains(SLAPolicySelect.TicketIssueLevel) ? q.TicketIssueLevelId : default(long?),
                TicketPriorityId   = filter.Selects.Contains(SLAPolicySelect.TicketPriority) ? q.TicketPriorityId : default(long?),
                FirstResponseTime  = filter.Selects.Contains(SLAPolicySelect.FirstResponseTime) ? q.FirstResponseTime : default(long?),
                ResolveTime        = filter.Selects.Contains(SLAPolicySelect.ResolveTime) ? q.ResolveTime : default(long?),
                IsAlert            = filter.Selects.Contains(SLAPolicySelect.IsAlert) ? q.IsAlert : default(bool?),
                IsAlertFRT         = filter.Selects.Contains(SLAPolicySelect.IsAlertFRT) ? q.IsAlertFRT : default(bool?),
                IsEscalation       = filter.Selects.Contains(SLAPolicySelect.IsEscalation) ? q.IsEscalation : default(bool?),
                IsEscalationFRT    = filter.Selects.Contains(SLAPolicySelect.IsEscalationFRT) ? q.IsEscalationFRT : default(bool?),
                TicketIssueLevel   = filter.Selects.Contains(SLAPolicySelect.TicketIssueLevel) && q.TicketIssueLevel != null ? new TicketIssueLevel
                {
                    Id            = q.TicketIssueLevel.Id,
                    Name          = q.TicketIssueLevel.Name,
                    OrderNumber   = q.TicketIssueLevel.OrderNumber,
                    TicketGroupId = q.TicketIssueLevel.TicketGroupId,
                    StatusId      = q.TicketIssueLevel.StatusId,
                    SLA           = q.TicketIssueLevel.SLA,
                    Used          = q.TicketIssueLevel.Used,
                } : null,
                TicketPriority = filter.Selects.Contains(SLAPolicySelect.TicketPriority) && q.TicketPriority != null ? new TicketPriority
                {
                    Id          = q.TicketPriority.Id,
                    Name        = q.TicketPriority.Name,
                    OrderNumber = q.TicketPriority.OrderNumber,
                    ColorCode   = q.TicketPriority.ColorCode,
                    StatusId    = q.TicketPriority.StatusId,
                    Used        = q.TicketPriority.Used,
                } : null,
                CreatedAt = q.CreatedAt,
                UpdatedAt = q.UpdatedAt,
            }).ToListAsync();

            return(SLAPolicies);
        }
Exemplo n.º 10
0
        private IQueryable <SLAPolicyDAO> DynamicOrder(IQueryable <SLAPolicyDAO> query, SLAPolicyFilter filter)
        {
            switch (filter.OrderType)
            {
            case OrderType.ASC:
                switch (filter.OrderBy)
                {
                case SLAPolicyOrder.Id:
                    query = query.OrderBy(q => q.Id);
                    break;

                case SLAPolicyOrder.TicketIssueLevel:
                    query = query.OrderBy(q => q.TicketIssueLevelId);
                    break;

                case SLAPolicyOrder.TicketPriority:
                    query = query.OrderBy(q => q.TicketPriorityId);
                    break;

                case SLAPolicyOrder.FirstResponseTime:
                    query = query.OrderBy(q => q.FirstResponseTime);
                    break;

                case SLAPolicyOrder.ResolveTime:
                    query = query.OrderBy(q => q.ResolveTime);
                    break;

                case SLAPolicyOrder.IsAlert:
                    query = query.OrderBy(q => q.IsAlert);
                    break;

                case SLAPolicyOrder.IsAlertFRT:
                    query = query.OrderBy(q => q.IsAlertFRT);
                    break;

                case SLAPolicyOrder.IsEscalation:
                    query = query.OrderBy(q => q.IsEscalation);
                    break;

                case SLAPolicyOrder.IsEscalationFRT:
                    query = query.OrderBy(q => q.IsEscalationFRT);
                    break;
                }
                break;

            case OrderType.DESC:
                switch (filter.OrderBy)
                {
                case SLAPolicyOrder.Id:
                    query = query.OrderByDescending(q => q.Id);
                    break;

                case SLAPolicyOrder.TicketIssueLevel:
                    query = query.OrderByDescending(q => q.TicketIssueLevelId);
                    break;

                case SLAPolicyOrder.TicketPriority:
                    query = query.OrderByDescending(q => q.TicketPriorityId);
                    break;

                case SLAPolicyOrder.FirstResponseTime:
                    query = query.OrderByDescending(q => q.FirstResponseTime);
                    break;

                case SLAPolicyOrder.ResolveTime:
                    query = query.OrderByDescending(q => q.ResolveTime);
                    break;

                case SLAPolicyOrder.IsAlert:
                    query = query.OrderByDescending(q => q.IsAlert);
                    break;

                case SLAPolicyOrder.IsAlertFRT:
                    query = query.OrderByDescending(q => q.IsAlertFRT);
                    break;

                case SLAPolicyOrder.IsEscalation:
                    query = query.OrderByDescending(q => q.IsEscalation);
                    break;

                case SLAPolicyOrder.IsEscalationFRT:
                    query = query.OrderByDescending(q => q.IsEscalationFRT);
                    break;
                }
                break;
            }
            query = query.Skip(filter.Skip).Take(filter.Take);
            return(query);
        }