Beispiel #1
0
        public string Search([FromBody] TodoSearch todoSearch)
        {
            List <Todo> todoList = new List <Todo>();

            try
            {
                if (todoSearch != null)
                {
                    todoList = (from todoes in _context.Todo
                                where
                                (todoes.Name.Contains(todoSearch.Name) || todoSearch.Name.Equals("")) &&
                                (todoes.State.Equals(todoSearch.State) || todoSearch.State.Equals("")) &&
                                (todoes.Startdate >= todoSearch.Startdate || todoSearch.Startdate.Equals(DateTime.MinValue)) &&
                                (todoes.Ownerid.Equals(todoSearch.Ownerid) || todoSearch.Ownerid.Equals(""))
                                select todoes).ToList();

                    foreach (Todo item in todoList)
                    {
                        item.State   = _context.OptionMasterDetail.Where(x => x.Optionid == item.State && x.Isused == true).Single().Name;
                        item.Ownerid = _context.User.Where(x => x.Id == item.Ownerid).Single().Name;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(JsonConvert.SerializeObject(todoList));
        }
Beispiel #2
0
        public PagedResponse<TodoDto> Execute(TodoSearch search)
        {
            var query = _context.Todos.AsQueryable();

            if (!string.IsNullOrEmpty(search.Name) || !string.IsNullOrWhiteSpace(search.Name))
                query = query.Where(x => x.Name.ToLower().Contains(search.Name));

            var skipCount = search.PerPage * (search.Page - 1);

            query = search.OrderBy.ToLower() == "desc" ? query.OrderByDescending(x => x.Name) : query.OrderBy(x => x.Name);

            var response = new PagedResponse<TodoDto>
            {
                CurrentPage = search.Page,
                ItemsPerPage = search.PerPage,
                TotalCount = query.Count(),
                Items = query.Skip(skipCount).Take(search.PerPage).Select(x =>
                    new TodoDto
                    {
                        Id = x.Id,
                        Name = x.Name,
                        Description = x.Description,
                        IsFinished = x.IsFinished,
                        Status = x.Status
                    }).ToList()
            };

            return response;
        }
Beispiel #3
0
 public IActionResult Get(
     [FromQuery] TodoSearch search,
     [FromServices] IGetTodosQuery query)
 {
     return(Ok(_executor.ExecuteQuery(query, search)));
 }