Ejemplo n.º 1
0
        public async Task <int> Count(CustomerPhoneFilter filter)
        {
            IQueryable <CustomerPhoneDAO> CustomerPhones = DataContext.CustomerPhone.AsNoTracking();

            CustomerPhones = DynamicFilter(CustomerPhones, filter);
            return(await CustomerPhones.CountAsync());
        }
Ejemplo n.º 2
0
        public async Task <List <CustomerPhone> > List(CustomerPhoneFilter CustomerPhoneFilter)
        {
            try
            {
                List <CustomerPhone> CustomerPhones = await UOW.CustomerPhoneRepository.List(CustomerPhoneFilter);

                return(CustomerPhones);
            }
            catch (Exception ex)
            {
                await Logging.CreateSystemLog(ex, nameof(CustomerPhoneService));
            }
            return(null);
        }
Ejemplo n.º 3
0
        public async Task <int> Count(CustomerPhoneFilter CustomerPhoneFilter)
        {
            try
            {
                int result = await UOW.CustomerPhoneRepository.Count(CustomerPhoneFilter);

                return(result);
            }
            catch (Exception ex)
            {
                await Logging.CreateSystemLog(ex, nameof(CustomerPhoneService));
            }
            return(0);
        }
Ejemplo n.º 4
0
        public async Task <List <CustomerPhone> > List(CustomerPhoneFilter filter)
        {
            if (filter == null)
            {
                return(new List <CustomerPhone>());
            }
            IQueryable <CustomerPhoneDAO> CustomerPhoneDAOs = DataContext.CustomerPhone.AsNoTracking();

            CustomerPhoneDAOs = DynamicFilter(CustomerPhoneDAOs, filter);
            CustomerPhoneDAOs = DynamicOrder(CustomerPhoneDAOs, filter);
            List <CustomerPhone> CustomerPhones = await DynamicSelect(CustomerPhoneDAOs, filter);

            return(CustomerPhones);
        }
Ejemplo n.º 5
0
 public async Task <CustomerPhoneFilter> ToFilter(CustomerPhoneFilter filter)
 {
     if (filter.OrFilter == null)
     {
         filter.OrFilter = new List <CustomerPhoneFilter>();
     }
     if (CurrentContext.Filters == null || CurrentContext.Filters.Count == 0)
     {
         return(filter);
     }
     foreach (var currentFilter in CurrentContext.Filters)
     {
         CustomerPhoneFilter subFilter = new CustomerPhoneFilter();
         filter.OrFilter.Add(subFilter);
         List <FilterPermissionDefinition> FilterPermissionDefinitions = currentFilter.Value;
         foreach (FilterPermissionDefinition FilterPermissionDefinition in FilterPermissionDefinitions)
         {
             if (FilterPermissionDefinition.Name == nameof(subFilter.Id))
             {
                 subFilter.Id = FilterBuilder.Merge(subFilter.Id, FilterPermissionDefinition.IdFilter);
             }
             if (FilterPermissionDefinition.Name == nameof(subFilter.CustomerId))
             {
                 subFilter.CustomerId = FilterBuilder.Merge(subFilter.CustomerId, FilterPermissionDefinition.IdFilter);
             }
             if (FilterPermissionDefinition.Name == nameof(subFilter.Phone))
             {
                 subFilter.Phone = FilterBuilder.Merge(subFilter.Phone, FilterPermissionDefinition.StringFilter);
             }
             if (FilterPermissionDefinition.Name == nameof(subFilter.PhoneTypeId))
             {
                 subFilter.PhoneTypeId = FilterBuilder.Merge(subFilter.PhoneTypeId, FilterPermissionDefinition.IdFilter);
             }
             if (FilterPermissionDefinition.Name == nameof(CurrentContext.UserId) && FilterPermissionDefinition.IdFilter != null)
             {
                 if (FilterPermissionDefinition.IdFilter.Equal.HasValue && FilterPermissionDefinition.IdFilter.Equal.Value == CurrentUserEnum.IS.Id)
                 {
                 }
                 if (FilterPermissionDefinition.IdFilter.Equal.HasValue && FilterPermissionDefinition.IdFilter.Equal.Value == CurrentUserEnum.ISNT.Id)
                 {
                 }
             }
         }
     }
     return(filter);
 }
Ejemplo n.º 6
0
        public async Task <bool> ValidateId(CustomerPhone CustomerPhone)
        {
            CustomerPhoneFilter CustomerPhoneFilter = new CustomerPhoneFilter
            {
                Skip = 0,
                Take = 10,
                Id   = new IdFilter {
                    Equal = CustomerPhone.Id
                },
                Selects = CustomerPhoneSelect.Id
            };

            int count = await UOW.CustomerPhoneRepository.Count(CustomerPhoneFilter);

            if (count == 0)
            {
                CustomerPhone.AddError(nameof(CustomerPhoneValidator), nameof(CustomerPhone.Id), ErrorCode.IdNotExisted);
            }
            return(count == 1);
        }
Ejemplo n.º 7
0
        private IQueryable <CustomerPhoneDAO> DynamicOrder(IQueryable <CustomerPhoneDAO> query, CustomerPhoneFilter filter)
        {
            switch (filter.OrderType)
            {
            case OrderType.ASC:
                switch (filter.OrderBy)
                {
                case CustomerPhoneOrder.Id:
                    query = query.OrderBy(q => q.Id);
                    break;

                case CustomerPhoneOrder.Customer:
                    query = query.OrderBy(q => q.CustomerId);
                    break;

                case CustomerPhoneOrder.Phone:
                    query = query.OrderBy(q => q.Phone);
                    break;

                case CustomerPhoneOrder.PhoneType:
                    query = query.OrderBy(q => q.PhoneTypeId);
                    break;
                }
                break;

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

                case CustomerPhoneOrder.Customer:
                    query = query.OrderByDescending(q => q.CustomerId);
                    break;

                case CustomerPhoneOrder.Phone:
                    query = query.OrderByDescending(q => q.Phone);
                    break;

                case CustomerPhoneOrder.PhoneType:
                    query = query.OrderByDescending(q => q.PhoneTypeId);
                    break;
                }
                break;
            }
            query = query.Skip(filter.Skip).Take(filter.Take);
            return(query);
        }
Ejemplo n.º 8
0
        private IQueryable <CustomerPhoneDAO> OrFilter(IQueryable <CustomerPhoneDAO> query, CustomerPhoneFilter filter)
        {
            if (filter.OrFilter == null || filter.OrFilter.Count == 0)
            {
                return(query);
            }
            IQueryable <CustomerPhoneDAO> initQuery = query.Where(q => false);

            foreach (CustomerPhoneFilter CustomerPhoneFilter in filter.OrFilter)
            {
                IQueryable <CustomerPhoneDAO> queryable = query;
                if (CustomerPhoneFilter.Id != null && CustomerPhoneFilter.Id.HasValue)
                {
                    queryable = queryable.Where(q => q.Id, CustomerPhoneFilter.Id);
                }
                if (CustomerPhoneFilter.CustomerId != null && CustomerPhoneFilter.CustomerId.HasValue)
                {
                    queryable = queryable.Where(q => q.CustomerId, CustomerPhoneFilter.CustomerId);
                }
                if (CustomerPhoneFilter.Phone != null && CustomerPhoneFilter.Phone.HasValue)
                {
                    queryable = queryable.Where(q => q.Phone, CustomerPhoneFilter.Phone);
                }
                if (CustomerPhoneFilter.PhoneTypeId != null && CustomerPhoneFilter.PhoneTypeId.HasValue)
                {
                    queryable = queryable.Where(q => q.PhoneTypeId, CustomerPhoneFilter.PhoneTypeId);
                }
                initQuery = initQuery.Union(queryable);
            }
            return(initQuery);
        }
Ejemplo n.º 9
0
 private IQueryable <CustomerPhoneDAO> DynamicFilter(IQueryable <CustomerPhoneDAO> query, CustomerPhoneFilter 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.CustomerId != null && filter.CustomerId.HasValue)
     {
         query = query.Where(q => q.CustomerId, filter.CustomerId);
     }
     if (filter.Phone != null && filter.Phone.HasValue)
     {
         query = query.Where(q => q.Phone, filter.Phone);
     }
     if (filter.PhoneTypeId != null && filter.PhoneTypeId.HasValue)
     {
         query = query.Where(q => q.PhoneTypeId, filter.PhoneTypeId);
     }
     query = OrFilter(query, filter);
     return(query);
 }
Ejemplo n.º 10
0
        private async Task <List <CustomerPhone> > DynamicSelect(IQueryable <CustomerPhoneDAO> query, CustomerPhoneFilter filter)
        {
            List <CustomerPhone> CustomerPhones = await query.Select(q => new CustomerPhone()
            {
                Id          = filter.Selects.Contains(CustomerPhoneSelect.Id) ? q.Id : default(long),
                CustomerId  = filter.Selects.Contains(CustomerPhoneSelect.Customer) ? q.CustomerId : default(long),
                Phone       = filter.Selects.Contains(CustomerPhoneSelect.Phone) ? q.Phone : default(string),
                PhoneTypeId = filter.Selects.Contains(CustomerPhoneSelect.PhoneType) ? q.PhoneTypeId : default(long),
                Customer    = filter.Selects.Contains(CustomerPhoneSelect.Customer) && q.Customer != null ? new Customer
                {
                    Id                 = q.Customer.Id,
                    Code               = q.Customer.Code,
                    Name               = q.Customer.Name,
                    Phone              = q.Customer.Phone,
                    Address            = q.Customer.Address,
                    NationId           = q.Customer.NationId,
                    ProvinceId         = q.Customer.ProvinceId,
                    DistrictId         = q.Customer.DistrictId,
                    WardId             = q.Customer.WardId,
                    CustomerTypeId     = q.Customer.CustomerTypeId,
                    Birthday           = q.Customer.Birthday,
                    Email              = q.Customer.Email,
                    ProfessionId       = q.Customer.ProfessionId,
                    CustomerResourceId = q.Customer.CustomerResourceId,
                    SexId              = q.Customer.SexId,
                    StatusId           = q.Customer.StatusId,
                    CompanyId          = q.Customer.CompanyId,
                    ParentCompanyId    = q.Customer.ParentCompanyId,
                    TaxCode            = q.Customer.TaxCode,
                    Fax                = q.Customer.Fax,
                    Website            = q.Customer.Website,
                    NumberOfEmployee   = q.Customer.NumberOfEmployee,
                    BusinessTypeId     = q.Customer.BusinessTypeId,
                    Investment         = q.Customer.Investment,
                    RevenueAnnual      = q.Customer.RevenueAnnual,
                    IsSupplier         = q.Customer.IsSupplier,
                    Descreption        = q.Customer.Descreption,
                    Used               = q.Customer.Used,
                    RowId              = q.Customer.RowId,
                } : null,
                PhoneType = filter.Selects.Contains(CustomerPhoneSelect.PhoneType) && q.PhoneType != null ? new PhoneType
                {
                    Id       = q.PhoneType.Id,
                    Code     = q.PhoneType.Code,
                    Name     = q.PhoneType.Name,
                    StatusId = q.PhoneType.StatusId,
                    Used     = q.PhoneType.Used,
                    RowId    = q.PhoneType.RowId,
                } : null,
            }).ToListAsync();

            return(CustomerPhones);
        }