public async Task <TodoPaginationDTO> GetByFilters(TodoPaginationDTO parameters) { try { var data = await this.iTodoDomainObject.GetByFilters(parameters); return(data); } catch (Exception ex) { throw new Exception(ex.Message); } }
public async Task <TodoPaginationDTO> GetByFilters(TodoPaginationDTO parameters) { List <TodoDTO> listTodo = new List <TodoDTO>(); int limitForPage = int.Parse(this.config.GetSection("MongoConnection:LimitForPage").Value); long countDocument = 0; int skip = (parameters.page - 1) * limitForPage; try { var filters = this.SetFilterQuery(parameters.filters); if (filters.Count == 0) { countDocument = this._context.TodoCollection().CountDocuments(new BsonDocument()); var getAll = await _context.TodoCollection().Find(Builders <TodoDTO> .Filter.Empty).Skip(skip).Limit(limitForPage).ToListAsync(); return(new TodoPaginationDTO { count = countDocument, data = getAll.ToArray(), page = parameters.page }); } var complexFilter = Builders <TodoDTO> .Filter.And(filters); countDocument = this._context.TodoCollection().CountDocuments(complexFilter); var data = await _context.TodoCollection().Find(complexFilter).Skip(skip).Limit(limitForPage).ToListAsync(); return(new TodoPaginationDTO { count = countDocument, data = data.ToArray(), page = parameters.page }); } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } }