Ejemplo n.º 1
0
        public async Task <int> Count(FoodGroupingFilter filter)
        {
            IQueryable <FoodGroupingDAO> FoodGroupings = DataContext.FoodGrouping;

            FoodGroupings = DynamicFilter(FoodGroupings, filter);
            return(await FoodGroupings.CountAsync());
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <int> > Count([FromBody] FoodGrouping_FoodGroupingFilterDTO FoodGrouping_FoodGroupingFilterDTO)
        {
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            FoodGroupingFilter FoodGroupingFilter = ConvertFilterDTOToFilterEntity(FoodGrouping_FoodGroupingFilterDTO);
            int count = await FoodGroupingService.Count(FoodGroupingFilter);

            return(count);
        }
Ejemplo n.º 3
0
        public async Task <List <FoodGrouping> > List(FoodGroupingFilter filter)
        {
            if (filter == null)
            {
                return(new List <FoodGrouping>());
            }
            IQueryable <FoodGroupingDAO> FoodGroupingDAOs = DataContext.FoodGrouping;

            FoodGroupingDAOs = DynamicFilter(FoodGroupingDAOs, filter);
            FoodGroupingDAOs = DynamicOrder(FoodGroupingDAOs, filter);
            List <FoodGrouping> FoodGroupings = await DynamicSelect(FoodGroupingDAOs, filter);

            return(FoodGroupings);
        }
Ejemplo n.º 4
0
        public async Task <ActionResult <List <FoodGrouping_FoodGroupingDTO> > > List([FromBody] FoodGrouping_FoodGroupingFilterDTO FoodGrouping_FoodGroupingFilterDTO)
        {
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            FoodGroupingFilter  FoodGroupingFilter = ConvertFilterDTOToFilterEntity(FoodGrouping_FoodGroupingFilterDTO);
            List <FoodGrouping> FoodGroupings      = await FoodGroupingService.List(FoodGroupingFilter);

            List <FoodGrouping_FoodGroupingDTO> FoodGrouping_FoodGroupingDTOs = FoodGroupings
                                                                                .Select(c => new FoodGrouping_FoodGroupingDTO(c)).ToList();

            return(FoodGrouping_FoodGroupingDTOs);
        }
Ejemplo n.º 5
0
        private FoodGroupingFilter ConvertFilterDTOToFilterEntity(FoodGrouping_FoodGroupingFilterDTO FoodGrouping_FoodGroupingFilterDTO)
        {
            FoodGroupingFilter FoodGroupingFilter = new FoodGroupingFilter();

            FoodGroupingFilter.Selects   = FoodGroupingSelect.ALL;
            FoodGroupingFilter.Skip      = FoodGrouping_FoodGroupingFilterDTO.Skip;
            FoodGroupingFilter.Take      = FoodGrouping_FoodGroupingFilterDTO.Take;
            FoodGroupingFilter.OrderBy   = FoodGrouping_FoodGroupingFilterDTO.OrderBy;
            FoodGroupingFilter.OrderType = FoodGrouping_FoodGroupingFilterDTO.OrderType;

            FoodGroupingFilter.Id       = FoodGrouping_FoodGroupingFilterDTO.Id;
            FoodGroupingFilter.Name     = FoodGrouping_FoodGroupingFilterDTO.Name;
            FoodGroupingFilter.StatusId = FoodGrouping_FoodGroupingFilterDTO.StatusId;
            return(FoodGroupingFilter);
        }
Ejemplo n.º 6
0
        public async Task <bool> ValidateId(FoodGrouping FoodGrouping)
        {
            FoodGroupingFilter FoodGroupingFilter = new FoodGroupingFilter
            {
                Skip = 0,
                Take = 10,
                Id   = new IdFilter {
                    Equal = FoodGrouping.Id
                },
                Selects = FoodGroupingSelect.Id
            };

            int count = await UOW.FoodGroupingRepository.Count(FoodGroupingFilter);

            if (count == 0)
            {
                FoodGrouping.AddError(nameof(FoodGroupingValidator), nameof(FoodGrouping.Id), ErrorCode.IdNotExisted);
            }
            return(count == 1);
        }
Ejemplo n.º 7
0
        public async Task <List <FoodGrouping> > List(FoodGroupingFilter FoodGroupingFilter)
        {
            try
            {
                List <FoodGrouping> FoodGroupings = await UOW.FoodGroupingRepository.List(FoodGroupingFilter);

                return(FoodGroupings);
            }
            catch (Exception ex)
            {
                await Logging.CreateSystemLog(ex.InnerException, nameof(FoodGroupingService));

                if (ex.InnerException == null)
                {
                    throw new MessageException(ex);
                }
                else
                {
                    throw new MessageException(ex.InnerException);
                }
            }
        }
Ejemplo n.º 8
0
        public async Task <int> Count(FoodGroupingFilter FoodGroupingFilter)
        {
            try
            {
                int result = await UOW.FoodGroupingRepository.Count(FoodGroupingFilter);

                return(result);
            }
            catch (Exception ex)
            {
                await Logging.CreateSystemLog(ex.InnerException, nameof(FoodGroupingService));

                if (ex.InnerException == null)
                {
                    throw new MessageException(ex);
                }
                else
                {
                    throw new MessageException(ex.InnerException);
                }
            }
        }
Ejemplo n.º 9
0
        private IQueryable <FoodGroupingDAO> DynamicOrder(IQueryable <FoodGroupingDAO> query, FoodGroupingFilter filter)
        {
            switch (filter.OrderType)
            {
            case OrderType.ASC:
                switch (filter.OrderBy)
                {
                case FoodGroupingOrder.Id:
                    query = query.OrderBy(q => q.Id);
                    break;

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

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

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

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

                case FoodGroupingOrder.Status:
                    query = query.OrderByDescending(q => q.StatusId);
                    break;
                }
                break;
            }
            query = query.Skip(filter.Skip).Take(filter.Take);
            return(query);
        }
Ejemplo n.º 10
0
        private IQueryable <FoodGroupingDAO> OrFilter(IQueryable <FoodGroupingDAO> query, FoodGroupingFilter filter)
        {
            if (filter.OrFilter == null || filter.OrFilter.Count == 0)
            {
                return(query);
            }
            IQueryable <FoodGroupingDAO> initQuery = query.Where(q => false);

            foreach (FoodGroupingFilter FoodGroupingFilter in filter.OrFilter)
            {
                IQueryable <FoodGroupingDAO> queryable = query;
                if (filter.Id != null)
                {
                    queryable = queryable.Where(q => q.Id, filter.Id);
                }
                if (filter.Name != null)
                {
                    queryable = queryable.Where(q => q.Name, filter.Name);
                }
                if (filter.StatusId != null)
                {
                    queryable = queryable.Where(q => q.StatusId, filter.StatusId);
                }
                initQuery = initQuery.Union(queryable);
            }
            return(initQuery);
        }
Ejemplo n.º 11
0
 private IQueryable <FoodGroupingDAO> DynamicFilter(IQueryable <FoodGroupingDAO> query, FoodGroupingFilter filter)
 {
     if (filter == null)
     {
         return(query.Where(q => false));
     }
     if (filter.Id != null)
     {
         query = query.Where(q => q.Id, filter.Id);
     }
     if (filter.Name != null)
     {
         query = query.Where(q => q.Name, filter.Name);
     }
     if (filter.StatusId != null)
     {
         query = query.Where(q => q.StatusId, filter.StatusId);
     }
     query = OrFilter(query, filter);
     return(query);
 }
Ejemplo n.º 12
0
        private async Task <List <FoodGrouping> > DynamicSelect(IQueryable <FoodGroupingDAO> query, FoodGroupingFilter filter)
        {
            List <FoodGrouping> FoodGroupings = await query.Select(q => new FoodGrouping()
            {
                Id       = filter.Selects.Contains(FoodGroupingSelect.Id) ? q.Id : default(long),
                Name     = filter.Selects.Contains(FoodGroupingSelect.Name) ? q.Name : default(string),
                StatusId = filter.Selects.Contains(FoodGroupingSelect.Status) ? q.StatusId : default(long),
            }).AsNoTracking().ToListAsync();

            return(FoodGroupings);
        }