public ActionResult MyTickets(TicketSearchViewModel vm) { Func <IQueryable <Ticket>, IQueryable <Ticket> > ticketFilter = q => { q = q.Include("TicketCategory").Include("TicketSubCategory").Include("CreatedByUser.Person").Include("AssignedToUser.Person"); if (vm.HideCompleted) { q = q.Where(r => r.Status != TicketStatus.Closed && r.Status != TicketStatus.Cancelled); } if (vm.TicketStatus.HasValue) { q = q.Where(r => r.Status == vm.TicketStatus.Value); } if (!string.IsNullOrEmpty(vm.Title)) { q = q.Where(r => r.Title.Contains(vm.Title)); } if (vm.StartDate.HasValue) { q = q.Where(r => r.CreatedOn >= vm.StartDate); } if (vm.EndDate.HasValue) { q = q.Where(r => r.CreatedOn <= vm.EndDate); } q = q.Where(t => t.CreatedByUserId == WebUser.Id); return(q); }; ViewBag.CanManage = false; vm.Tickets = _ticketRepository.SearchPage(ticketFilter, o => o.OrderByDescending(t => t.CreatedOn), vm.GetPageNo(), vm.PageSize); return(View(vm)); }
public ActionResult Index(TicketSearchViewModel vm) { var apiResult = TryExecute(() => { Func <IQueryable <Ticket>, IQueryable <Ticket> > ticketFilter = q => { q = q.Include("AssignedToUser.Person").Include("CreatedByUser.Person"); if (vm.Mine.HasValue) { q = q.Where(r => r.CreatedByUserId == WebUser.Id); } q = q.OrderByDescending(t => t.DueDate); return(q); }; var tickets = _ticketRepository.Search(ticketFilter).Select(t => new TicketModel(t)).ToList(); return(tickets); }, "Tickets fetched sucessfully"); return(Json(apiResult, JsonRequestBehavior.AllowGet)); }