Exemplo n.º 1
0
        public async Task <int> Count(CallStatusFilter filter)
        {
            IQueryable <CallStatusDAO> CallStatuses = DataContext.CallStatus.AsNoTracking();

            CallStatuses = DynamicFilter(CallStatuses, filter);
            return(await CallStatuses.CountAsync());
        }
Exemplo n.º 2
0
        public async Task <ActionResult <List <CallLog_CallStatusDTO> > > FilterListCallStatus([FromBody] CallLog_CallStatusFilterDTO CallLog_CallStatusFilterDTO)
        {
            if (UnAuthorization)
            {
                return(Forbid());
            }
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            CallStatusFilter CallStatusFilter = new CallStatusFilter();

            CallStatusFilter.Skip      = 0;
            CallStatusFilter.Take      = int.MaxValue;
            CallStatusFilter.Take      = 20;
            CallStatusFilter.OrderBy   = CallStatusOrder.Id;
            CallStatusFilter.OrderType = OrderType.ASC;
            CallStatusFilter.Selects   = CallStatusSelect.ALL;

            List <CallStatus> CallStatuses = await CallStatusService.List(CallStatusFilter);

            List <CallLog_CallStatusDTO> CallLog_CallStatusDTOs = CallStatuses
                                                                  .Select(x => new CallLog_CallStatusDTO(x)).ToList();

            return(CallLog_CallStatusDTOs);
        }
Exemplo n.º 3
0
        public async Task <List <CallStatus> > List(CallStatusFilter CallStatusFilter)
        {
            try
            {
                List <CallStatus> CallStatuss = await UOW.CallStatusRepository.List(CallStatusFilter);

                return(CallStatuss);
            }
            catch (Exception ex)
            {
                await Logging.CreateSystemLog(ex, nameof(CallStatusService));
            }
            return(null);
        }
Exemplo n.º 4
0
        public async Task <int> Count(CallStatusFilter CallStatusFilter)
        {
            try
            {
                int result = await UOW.CallStatusRepository.Count(CallStatusFilter);

                return(result);
            }
            catch (Exception ex)
            {
                await Logging.CreateSystemLog(ex, nameof(CallStatusService));
            }
            return(0);
        }
Exemplo n.º 5
0
        public async Task <List <CallStatus> > List(CallStatusFilter filter)
        {
            if (filter == null)
            {
                return(new List <CallStatus>());
            }
            IQueryable <CallStatusDAO> CallStatusDAOs = DataContext.CallStatus.AsNoTracking();

            CallStatusDAOs = DynamicFilter(CallStatusDAOs, filter);
            CallStatusDAOs = DynamicOrder(CallStatusDAOs, filter);
            List <CallStatus> CallStatuses = await DynamicSelect(CallStatusDAOs, filter);

            return(CallStatuses);
        }
Exemplo n.º 6
0
        private IQueryable <CallStatusDAO> DynamicOrder(IQueryable <CallStatusDAO> query, CallStatusFilter filter)
        {
            switch (filter.OrderType)
            {
            case OrderType.ASC:
                switch (filter.OrderBy)
                {
                case CallStatusOrder.Id:
                    query = query.OrderBy(q => q.Id);
                    break;

                case CallStatusOrder.Code:
                    query = query.OrderBy(q => q.Code);
                    break;

                case CallStatusOrder.Name:
                    query = query.OrderBy(q => q.Name);
                    break;
                }
                break;

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

                case CallStatusOrder.Code:
                    query = query.OrderByDescending(q => q.Code);
                    break;

                case CallStatusOrder.Name:
                    query = query.OrderByDescending(q => q.Name);
                    break;
                }
                break;
            }
            query = query.Skip(filter.Skip).Take(filter.Take);
            return(query);
        }
Exemplo n.º 7
0
        private IQueryable <CallStatusDAO> OrFilter(IQueryable <CallStatusDAO> query, CallStatusFilter filter)
        {
            if (filter.OrFilter == null || filter.OrFilter.Count == 0)
            {
                return(query);
            }
            IQueryable <CallStatusDAO> initQuery = query.Where(q => false);

            foreach (CallStatusFilter CallStatusFilter in filter.OrFilter)
            {
                IQueryable <CallStatusDAO> queryable = query;
                if (CallStatusFilter.Id != null && CallStatusFilter.Id.HasValue)
                {
                    queryable = queryable.Where(q => q.Id, CallStatusFilter.Id);
                }
                if (CallStatusFilter.Code != null && CallStatusFilter.Code.HasValue)
                {
                    queryable = queryable.Where(q => q.Code, CallStatusFilter.Code);
                }
                if (CallStatusFilter.Name != null && CallStatusFilter.Name.HasValue)
                {
                    queryable = queryable.Where(q => q.Name, CallStatusFilter.Name);
                }
                initQuery = initQuery.Union(queryable);
            }
            return(initQuery);
        }
Exemplo n.º 8
0
 private IQueryable <CallStatusDAO> DynamicFilter(IQueryable <CallStatusDAO> query, CallStatusFilter filter)
 {
     if (filter == null)
     {
         return(query.Where(q => false));
     }
     if (filter.Id != null && filter.Id.HasValue)
     {
         query = query.Where(q => q.Id, filter.Id);
     }
     if (filter.Code != null && filter.Code.HasValue)
     {
         query = query.Where(q => q.Code, filter.Code);
     }
     if (filter.Name != null && filter.Name.HasValue)
     {
         query = query.Where(q => q.Name, filter.Name);
     }
     query = OrFilter(query, filter);
     return(query);
 }
Exemplo n.º 9
0
        private async Task <List <CallStatus> > DynamicSelect(IQueryable <CallStatusDAO> query, CallStatusFilter filter)
        {
            List <CallStatus> CallStatuses = await query.Select(q => new CallStatus()
            {
                Id   = filter.Selects.Contains(CallStatusSelect.Id) ? q.Id : default(long),
                Code = filter.Selects.Contains(CallStatusSelect.Code) ? q.Code : default(string),
                Name = filter.Selects.Contains(CallStatusSelect.Name) ? q.Name : default(string),
            }).ToListAsync();

            return(CallStatuses);
        }