Exemplo n.º 1
0
        public OperationResultList <SimpleTask> SearchTasks(SimpleTaskQuery request = null)
        {
            var executionStart = DateTime.Now;

            request            = request ?? new SimpleTaskQuery();
            request.MaxRecords = request.MaxRecords > 0 ? request.MaxRecords : 50;
            if (request.Order == null || request.Order.Count == 0)
            {
                request.Order = new List <DataOrderItem>()
                {
                    new DataOrderItem("RegistrationDateTime", true)
                };
            }

            var options = new FeedOptions()
            {
                MaxItemCount = request.MaxRecords
            };

            using (var client = _db.NewClient())
            {
                var query = _db.QueryTask(client, options).Where(t => t.Id != null);

                if (!string.IsNullOrEmpty(request.Text))
                {
                    query = query.Where(t =>
                                        t.Title.ToLower().Contains(request.Text.ToLower()) ||
                                        t.Description.ToLower().Contains(request.Text.ToLower())
                                        );
                }

                var dataLength = query.Count();
                var results    = query.OrderBy(request.Order).Take(request.MaxRecords).ToList();
                return(new OperationResultList <SimpleTask>(results)
                {
                    DataLength = dataLength, ExecutionTime = Convert.ToInt32(DateTime.Now.Subtract(executionStart).TotalMilliseconds)
                });
            }
        }
Exemplo n.º 2
0
        public IActionResult Get([FromQuery] SimpleTaskQuery query)
        {
            var result = _taskRepository.SearchTasks(query);

            return(Ok(result));
        }