Beispiel #1
0
        public IQueryable <Empresa> GetByFilters(EmpresaFilter filters)
        {
            var querybase = this.GetAll();

            var queryFilter = this.SimpleFilters(filters, querybase);

            return(queryFilter);
        }
Beispiel #2
0
 public List <EmpresaQueryResult> GetByFiltro(EmpresaFilter filter)
 {
     return(_mapper.Map <List <EmpresaQueryResult> >(
                _context.Empresas.Where(p => (string.IsNullOrEmpty(filter.Nome) || p.Nome.Contains(filter.Nome)) &&
                                        (string.IsNullOrEmpty(filter.CNPJ) || p.CNPJ == filter.CNPJ) &&
                                        filter.DataFundacaoFim == null && filter.DataFundacaoFim == null ||
                                        p.DataFundacao >= filter.DataFundacaoInicio && p.DataFundacao <= filter.DataFundacaoFim).ToList()));
 }
Beispiel #3
0
        public async Task <IActionResult> Get([FromQuery] EmpresaFilter filters)
        {
            var result = new HttpResult <EmpresaDto>(this._logger, this._service);

            try
            {
                var searchResult = await this._service.GetByFiltersPaging(filters);

                return(result.ReturnCustomResponse(searchResult));
            }
            catch (Exception ex)
            {
                return(result.ReturnCustomException(ex, "Empresa", filters));
            }
        }
Beispiel #4
0
        public async Task <IActionResult> DataItems([FromQuery] EmpresaFilter filters)
        {
            var result = new HttpResult <dynamic>(this._logger, this._service);

            try
            {
                var items = await this._service.GetDataItems(filters);

                return(result.ReturnCustomResponse(items));
            }
            catch (Exception ex)
            {
                return(result.ReturnCustomException(ex, "Assinatura", filters));
            }
        }
Beispiel #5
0
        protected IQueryable <Empresa> SimpleFilters(EmpresaFilter filters, IQueryable <Empresa> queryBase)
        {
            var queryFilter = queryBase;

            if (filters.EmpresaId.IsSent())
            {
                queryFilter = queryFilter.Where(_ => _.EmpresaId == filters.EmpresaId);
            }
            if (filters.AssinaturaId.IsSent())
            {
                queryFilter = queryFilter.Where(_ => _.AssinaturaId != null && _.AssinaturaId.Value == filters.AssinaturaId);
            }
            if (filters.Nome.IsSent())
            {
                queryFilter = queryFilter.Where(_ => _.Nome.Contains(filters.Nome));
            }
            if (filters.ProprietarioId.IsSent())
            {
                queryFilter = queryFilter.Where(_ => _.ProprietarioId != null && _.ProprietarioId.Value == filters.ProprietarioId);
            }
            if (filters.DataCriacaoStart.IsSent())
            {
                queryFilter = queryFilter.Where(_ => _.DataCriacao >= filters.DataCriacaoStart);
            }
            if (filters.DataCriacaoEnd.IsSent())
            {
                filters.DataCriacaoEnd = filters.DataCriacaoEnd.AddDays(1).AddMilliseconds(-1);
                queryFilter            = queryFilter.Where(_ => _.DataCriacao <= filters.DataCriacaoEnd);
            }

            if (filters.DataAtualizacaoStart.IsSent())
            {
                queryFilter = queryFilter.Where(_ => _.DataAtualizacao != null && _.DataAtualizacao.Value >= filters.DataAtualizacaoStart.Value);
            }
            if (filters.DataAtualizacaoEnd.IsSent())
            {
                filters.DataAtualizacaoEnd = filters.DataAtualizacaoEnd.Value.AddDays(1).AddMilliseconds(-1);
                queryFilter = queryFilter.Where(_ => _.DataAtualizacao != null && _.DataAtualizacao.Value <= filters.DataAtualizacaoEnd);
            }

            if (filters.VisibilidadeId.IsSent())
            {
                queryFilter = queryFilter.Where(_ => _.VisibilidadeId == filters.VisibilidadeId);
            }


            return(queryFilter);
        }
Beispiel #6
0
        public async Task <IActionResult> Get(int id, [FromQuery] EmpresaFilter filters)
        {
            var result = new HttpResult <EmpresaDto>(this._logger, this._service);

            try
            {
                filters.EmpresaId = id;
                var returnModel = await this._service.GetById(filters);

                return(result.ReturnCustomResponse(returnModel));
            }
            catch (Exception ex)
            {
                return(result.ReturnCustomException(ex, "Empresa", id));
            }
        }
Beispiel #7
0
        public IActionResult Get([FromQuery] EmpresaFilter filter)
        {
            if (filter == null)
            {
                return(Response(_repository.Get()));
            }

            if (filter.DateTimeValidate())
            {
                return(Response(_repository.GetByFiltro(filter)));
            }
            else
            {
                _notification.Adicionar("Data para filtro inválida.");
                return(BadRequest());
            }
        }
Beispiel #8
0
        public Empresa GetById(EmpresaFilter filters)
        {
            var querybase = this.GetByFilters(filters);

            return(querybase.SingleOrDefault());
        }
Beispiel #9
0
        public virtual IEnumerable <dynamic> GetDataItems(EmpresaFilter filters)
        {
            var querybase = this.GetAll();

            return(this.GetAll().Select(_ => new { Id = _.EmpresaId, Name = _.Nome }));
        }