public SmsQueueStatusFilter ToFilter(SmsQueueStatusFilter filter)
        {
            if (filter.OrFilter == null)
            {
                filter.OrFilter = new List <SmsQueueStatusFilter>();
            }
            if (CurrentContext.Filters == null || CurrentContext.Filters.Count == 0)
            {
                return(filter);
            }
            foreach (var currentFilter in CurrentContext.Filters)
            {
                SmsQueueStatusFilter subFilter = new SmsQueueStatusFilter();
                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.Code))
                    {
                        subFilter.Code = FilterPermissionDefinition.StringFilter;
                    }

                    if (FilterPermissionDefinition.Name == nameof(subFilter.Name))
                    {
                        subFilter.Name = FilterPermissionDefinition.StringFilter;
                    }
                }
            }
            return(filter);
        }
        public async Task <int> Count(SmsQueueStatusFilter filter)
        {
            IQueryable <SmsQueueStatusDAO> SmsQueueStatuses = DataContext.SmsQueueStatus.AsNoTracking();

            SmsQueueStatuses = DynamicFilter(SmsQueueStatuses, filter);
            return(await SmsQueueStatuses.CountAsync());
        }
        public async Task <List <SmsQueueStatus> > List(SmsQueueStatusFilter filter)
        {
            if (filter == null)
            {
                return(new List <SmsQueueStatus>());
            }
            IQueryable <SmsQueueStatusDAO> SmsQueueStatusDAOs = DataContext.SmsQueueStatus.AsNoTracking();

            SmsQueueStatusDAOs = DynamicFilter(SmsQueueStatusDAOs, filter);
            SmsQueueStatusDAOs = DynamicOrder(SmsQueueStatusDAOs, filter);
            List <SmsQueueStatus> SmsQueueStatuses = await DynamicSelect(SmsQueueStatusDAOs, filter);

            return(SmsQueueStatuses);
        }
        public async Task <bool> ValidateId(SmsQueueStatus SmsQueueStatus)
        {
            SmsQueueStatusFilter SmsQueueStatusFilter = new SmsQueueStatusFilter
            {
                Skip = 0,
                Take = 10,
                Id   = new IdFilter {
                    Equal = SmsQueueStatus.Id
                },
                Selects = SmsQueueStatusSelect.Id
            };

            int count = await UOW.SmsQueueStatusRepository.Count(SmsQueueStatusFilter);

            if (count == 0)
            {
                SmsQueueStatus.AddError(nameof(SmsQueueStatusValidator), nameof(SmsQueueStatus.Id), ErrorCode.IdNotExisted);
            }
            return(count == 1);
        }
        public async Task <List <SmsQueueStatus> > List(SmsQueueStatusFilter SmsQueueStatusFilter)
        {
            try
            {
                List <SmsQueueStatus> SmsQueueStatuss = await UOW.SmsQueueStatusRepository.List(SmsQueueStatusFilter);

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

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

                    throw new MessageException(ex.InnerException);
                }
            }
        }
        public async Task <int> Count(SmsQueueStatusFilter SmsQueueStatusFilter)
        {
            try
            {
                int result = await UOW.SmsQueueStatusRepository.Count(SmsQueueStatusFilter);

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

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

                    throw new MessageException(ex.InnerException);
                }
            }
        }
        private IQueryable <SmsQueueStatusDAO> DynamicOrder(IQueryable <SmsQueueStatusDAO> query, SmsQueueStatusFilter filter)
        {
            switch (filter.OrderType)
            {
            case OrderType.ASC:
                switch (filter.OrderBy)
                {
                case SmsQueueStatusOrder.Id:
                    query = query.OrderBy(q => q.Id);
                    break;

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

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

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

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

                case SmsQueueStatusOrder.Name:
                    query = query.OrderByDescending(q => q.Name);
                    break;
                }
                break;
            }
            query = query.Skip(filter.Skip).Take(filter.Take);
            return(query);
        }
        private IQueryable <SmsQueueStatusDAO> OrFilter(IQueryable <SmsQueueStatusDAO> query, SmsQueueStatusFilter filter)
        {
            if (filter.OrFilter == null || filter.OrFilter.Count == 0)
            {
                return(query);
            }
            IQueryable <SmsQueueStatusDAO> initQuery = query.Where(q => false);

            foreach (SmsQueueStatusFilter SmsQueueStatusFilter in filter.OrFilter)
            {
                IQueryable <SmsQueueStatusDAO> queryable = query;
                if (SmsQueueStatusFilter.Id != null)
                {
                    queryable = queryable.Where(q => q.Id, SmsQueueStatusFilter.Id);
                }
                if (SmsQueueStatusFilter.Code != null)
                {
                    queryable = queryable.Where(q => q.Code, SmsQueueStatusFilter.Code);
                }
                if (SmsQueueStatusFilter.Name != null)
                {
                    queryable = queryable.Where(q => q.Name, SmsQueueStatusFilter.Name);
                }
                initQuery = initQuery.Union(queryable);
            }
            return(initQuery);
        }
 private IQueryable <SmsQueueStatusDAO> DynamicFilter(IQueryable <SmsQueueStatusDAO> query, SmsQueueStatusFilter 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.Code != null)
     {
         query = query.Where(q => q.Code, filter.Code);
     }
     if (filter.Name != null)
     {
         query = query.Where(q => q.Name, filter.Name);
     }
     query = OrFilter(query, filter);
     return(query);
 }
        private async Task <List <SmsQueueStatus> > DynamicSelect(IQueryable <SmsQueueStatusDAO> query, SmsQueueStatusFilter filter)
        {
            List <SmsQueueStatus> SmsQueueStatuses = await query.Select(q => new SmsQueueStatus()
            {
                Id        = filter.Selects.Contains(SmsQueueStatusSelect.Id) ? q.Id : default(long),
                Code      = filter.Selects.Contains(SmsQueueStatusSelect.Code) ? q.Code : default(string),
                Name      = filter.Selects.Contains(SmsQueueStatusSelect.Name) ? q.Name : default(string),
                CreatedAt = q.CreatedAt,
                UpdatedAt = q.UpdatedAt,
            }).ToListAsync();

            return(SmsQueueStatuses);
        }