public async Task <IList <Entity.Log> > GetByFilterLog(FilterLogDTO filter)
        {
            var filters  = new List <FilterDefinition <Entity.Log> >();
            var fBuilder = Builders <Entity.Log> .Filter;

            if (filter.DateStart.HasValue && filter.DateStart.Value != DateTime.MinValue)
            {
                filters.Add(fBuilder.Where(x => x.Date >= filter.DateStart.Value.Date));
            }

            if (filter.DateEnd.HasValue && filter.DateEnd.Value != DateTime.MinValue)
            {
                filters.Add(fBuilder.Where(x => x.Date <= filter.DateEnd.Value.Date));
            }

            if (!string.IsNullOrEmpty(filter.Text))
            {
                filters.Add(fBuilder.Text(filter.Text, new TextSearchOptions()
                {
                    CaseSensitive      = false,
                    DiacriticSensitive = false
                }));
            }

            if (filters.Count == 0)
            {
                filters.Add(fBuilder.Empty);
            }


            return(await _repository.GetByFilter(fBuilder.And(filters), Builders <Entity.Log> .Sort.Descending(x => x.Date)));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Index(FilterLogDTO filter)
        {
            var logs = await _repLog.GetByFilterLog(filter);

            return(View(new LogViewModel
            {
                Logs = logs,
                DateEnd = filter.DateEnd,
                DateStart = filter.DateStart,
                Text = filter.Text
            }));
        }