public async Task <int> Count(UnitOfMeasureGroupingFilter filter)
        {
            IQueryable <UnitOfMeasureGroupingDAO> UnitOfMeasureGroupings = DataContext.UnitOfMeasureGrouping.AsNoTracking();

            UnitOfMeasureGroupings = DynamicFilter(UnitOfMeasureGroupings, filter);
            return(await UnitOfMeasureGroupings.CountAsync());
        }
        public async Task <List <UnitOfMeasureGrouping> > List(UnitOfMeasureGroupingFilter filter)
        {
            if (filter == null)
            {
                return(new List <UnitOfMeasureGrouping>());
            }
            IQueryable <UnitOfMeasureGroupingDAO> UnitOfMeasureGroupingDAOs = DataContext.UnitOfMeasureGrouping.AsNoTracking();

            UnitOfMeasureGroupingDAOs = DynamicFilter(UnitOfMeasureGroupingDAOs, filter);
            UnitOfMeasureGroupingDAOs = DynamicOrder(UnitOfMeasureGroupingDAOs, filter);
            List <UnitOfMeasureGrouping> UnitOfMeasureGroupings = await DynamicSelect(UnitOfMeasureGroupingDAOs, filter);

            return(UnitOfMeasureGroupings);
        }
Exemplo n.º 3
0
        public UnitOfMeasureGroupingFilter ToFilter(UnitOfMeasureGroupingFilter filter)
        {
            if (filter.OrFilter == null)
            {
                filter.OrFilter = new List <UnitOfMeasureGroupingFilter>();
            }
            if (CurrentContext.Filters == null || CurrentContext.Filters.Count == 0)
            {
                return(filter);
            }
            foreach (var currentFilter in CurrentContext.Filters)
            {
                UnitOfMeasureGroupingFilter subFilter = new UnitOfMeasureGroupingFilter();
                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;
                    }

                    if (FilterPermissionDefinition.Name == nameof(subFilter.Description))
                    {
                        subFilter.Description = FilterPermissionDefinition.StringFilter;
                    }

                    if (FilterPermissionDefinition.Name == nameof(subFilter.UnitOfMeasureId))
                    {
                        subFilter.UnitOfMeasureId = FilterPermissionDefinition.IdFilter;
                    }
                    if (FilterPermissionDefinition.Name == nameof(subFilter.StatusId))
                    {
                        subFilter.StatusId = FilterPermissionDefinition.IdFilter;
                    }
                }
            }
            return(filter);
        }
Exemplo n.º 4
0
        public async Task <bool> ValidateId(UnitOfMeasureGrouping UnitOfMeasureGrouping)
        {
            UnitOfMeasureGroupingFilter UnitOfMeasureGroupingFilter = new UnitOfMeasureGroupingFilter
            {
                Skip = 0,
                Take = 10,
                Id   = new IdFilter {
                    Equal = UnitOfMeasureGrouping.Id
                },
                Selects = UnitOfMeasureGroupingSelect.Id
            };

            int count = await UOW.UnitOfMeasureGroupingRepository.Count(UnitOfMeasureGroupingFilter);

            if (count == 0)
            {
                UnitOfMeasureGrouping.AddError(nameof(UnitOfMeasureGroupingValidator), nameof(UnitOfMeasureGrouping.Id), ErrorCode.IdNotExisted);
            }
            return(count == 1);
        }
Exemplo n.º 5
0
        public async Task <List <UnitOfMeasureGrouping> > List(UnitOfMeasureGroupingFilter UnitOfMeasureGroupingFilter)
        {
            try
            {
                List <UnitOfMeasureGrouping> UnitOfMeasureGroupings = await UOW.UnitOfMeasureGroupingRepository.List(UnitOfMeasureGroupingFilter);

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

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

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

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

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

                    throw new MessageException(ex.InnerException);
                }
            }
        }
        private IQueryable <UnitOfMeasureGroupingDAO> OrFilter(IQueryable <UnitOfMeasureGroupingDAO> query, UnitOfMeasureGroupingFilter filter)
        {
            if (filter.OrFilter == null || filter.OrFilter.Count == 0)
            {
                return(query);
            }
            IQueryable <UnitOfMeasureGroupingDAO> initQuery = query.Where(q => false);

            foreach (UnitOfMeasureGroupingFilter UnitOfMeasureGroupingFilter in filter.OrFilter)
            {
                IQueryable <UnitOfMeasureGroupingDAO> queryable = query;
                if (UnitOfMeasureGroupingFilter.Id != null)
                {
                    queryable = queryable.Where(q => q.Id, UnitOfMeasureGroupingFilter.Id);
                }
                if (UnitOfMeasureGroupingFilter.Code != null)
                {
                    queryable = queryable.Where(q => q.Code, UnitOfMeasureGroupingFilter.Code);
                }
                if (UnitOfMeasureGroupingFilter.Name != null)
                {
                    queryable = queryable.Where(q => q.Name, UnitOfMeasureGroupingFilter.Name);
                }
                if (UnitOfMeasureGroupingFilter.Description != null)
                {
                    queryable = queryable.Where(q => q.Description, UnitOfMeasureGroupingFilter.Description);
                }
                if (UnitOfMeasureGroupingFilter.UnitOfMeasureId != null)
                {
                    queryable = queryable.Where(q => q.UnitOfMeasureId, UnitOfMeasureGroupingFilter.UnitOfMeasureId);
                }
                if (UnitOfMeasureGroupingFilter.StatusId != null)
                {
                    queryable = queryable.Where(q => q.StatusId, UnitOfMeasureGroupingFilter.StatusId);
                }
                initQuery = initQuery.Union(queryable);
            }
            return(initQuery);
        }
 private IQueryable <UnitOfMeasureGroupingDAO> DynamicFilter(IQueryable <UnitOfMeasureGroupingDAO> query, UnitOfMeasureGroupingFilter 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);
     }
     if (filter.Description != null)
     {
         query = query.Where(q => q.Description, filter.Description);
     }
     if (filter.UnitOfMeasureId != null)
     {
         query = query.Where(q => q.UnitOfMeasureId, filter.UnitOfMeasureId);
     }
     if (filter.StatusId != null)
     {
         query = query.Where(q => q.StatusId, filter.StatusId);
     }
     query = OrFilter(query, filter);
     return(query);
 }
        private async Task <List <UnitOfMeasureGrouping> > DynamicSelect(IQueryable <UnitOfMeasureGroupingDAO> query, UnitOfMeasureGroupingFilter filter)
        {
            List <UnitOfMeasureGrouping> UnitOfMeasureGroupings = await query.Select(q => new UnitOfMeasureGrouping()
            {
                Id              = filter.Selects.Contains(UnitOfMeasureGroupingSelect.Id) ? q.Id : default(long),
                Code            = filter.Selects.Contains(UnitOfMeasureGroupingSelect.Code) ? q.Code : default(string),
                Name            = filter.Selects.Contains(UnitOfMeasureGroupingSelect.Name) ? q.Name : default(string),
                Description     = filter.Selects.Contains(UnitOfMeasureGroupingSelect.Description) ? q.Description : default(string),
                UnitOfMeasureId = filter.Selects.Contains(UnitOfMeasureGroupingSelect.UnitOfMeasure) ? q.UnitOfMeasureId : default(long),
                StatusId        = filter.Selects.Contains(UnitOfMeasureGroupingSelect.Status) ? q.StatusId : default(long),
                Used            = filter.Selects.Contains(UnitOfMeasureGroupingSelect.Used) ? q.Used : default(bool),
                UnitOfMeasure   = filter.Selects.Contains(UnitOfMeasureGroupingSelect.UnitOfMeasure) && q.UnitOfMeasure != null ? new UnitOfMeasure
                {
                    Id          = q.UnitOfMeasure.Id,
                    Code        = q.UnitOfMeasure.Code,
                    Name        = q.UnitOfMeasure.Name,
                    Description = q.UnitOfMeasure.Description,
                    StatusId    = q.UnitOfMeasure.StatusId,
                    Used        = q.UnitOfMeasure.Used,
                } : null,
                CreatedAt = q.CreatedAt,
                UpdatedAt = q.UpdatedAt,
                UnitOfMeasureGroupingContents = filter.Selects.Contains(UnitOfMeasureGroupingSelect.UnitOfMeasureGroupingContents) && q.UnitOfMeasureGroupingContents == null ? null :
                                                q.UnitOfMeasureGroupingContents.Select(x => new UnitOfMeasureGroupingContent
                {
                    Id                      = x.Id,
                    Factor                  = x.Factor,
                    UnitOfMeasureId         = x.UnitOfMeasureId,
                    UnitOfMeasureGroupingId = x.UnitOfMeasureGroupingId,
                    UnitOfMeasure           = new UnitOfMeasure
                    {
                        Id   = x.UnitOfMeasure.Id,
                        Name = x.UnitOfMeasure.Name,
                        Code = x.UnitOfMeasure.Code,
                    }
                }).ToList(),
            }).ToListAsync();

            return(UnitOfMeasureGroupings);
        }
        private IQueryable <UnitOfMeasureGroupingDAO> DynamicOrder(IQueryable <UnitOfMeasureGroupingDAO> query, UnitOfMeasureGroupingFilter filter)
        {
            switch (filter.OrderType)
            {
            case OrderType.ASC:
                switch (filter.OrderBy)
                {
                case UnitOfMeasureGroupingOrder.Id:
                    query = query.OrderBy(q => q.Id);
                    break;

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

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

                case UnitOfMeasureGroupingOrder.Description:
                    query = query.OrderBy(q => q.Description);
                    break;

                case UnitOfMeasureGroupingOrder.UnitOfMeasure:
                    query = query.OrderBy(q => q.UnitOfMeasureId);
                    break;

                case UnitOfMeasureGroupingOrder.Status:
                    query = query.OrderBy(q => q.StatusId);
                    break;

                case UnitOfMeasureGroupingOrder.Used:
                    query = query.OrderBy(q => q.Used);
                    break;
                }
                break;

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

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

                case UnitOfMeasureGroupingOrder.Name:
                    query = query.OrderByDescending(q => q.Name);
                    break;

                case UnitOfMeasureGroupingOrder.Description:
                    query = query.OrderByDescending(q => q.Description);
                    break;

                case UnitOfMeasureGroupingOrder.UnitOfMeasure:
                    query = query.OrderByDescending(q => q.UnitOfMeasureId);
                    break;

                case UnitOfMeasureGroupingOrder.Status:
                    query = query.OrderByDescending(q => q.StatusId);
                    break;

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