예제 #1
0
        private IQueryable<Ticket> ApplyFilter(TicketFilter filter)
        {
            var filteredTicketsList = this.Data.Tickets.All();

            if (filter.Title != null)
            {
                filteredTicketsList = filteredTicketsList.Where(t => t.Title == filter.Title);
            }

            if (filter.CategoryId != null)
            {
                filteredTicketsList = filteredTicketsList.Where(t => t.CategoryId == filter.CategoryId);
            }

            if (filter.AuthorId != null)
            {
                filteredTicketsList = filteredTicketsList.Where(t => t.AuthorId == filter.AuthorId);
            }

            if (filter.Priority != null)
            {
                filteredTicketsList = filteredTicketsList.Where(t => t.Priority == filter.Priority);
            }

            if (filter.Status != null)
            {
                filteredTicketsList = filteredTicketsList.Where(t => t.Status == filter.Status);
            }

            return filteredTicketsList;
        }
예제 #2
0
        public ActionResult Index(TicketFilter filter, int? page)
        {
            var pageIndex = page.GetValueOrDefault(1);
            var filteredTicketsList = this.ApplyFilter(filter)
                                          .AsEnumerable()
                                          .Select(t => new TicketSummaryViewModel
                                                 {
                                                     Id = t.Id,
                                                     Title = t.Title,
                                                     CategoryName = t.Category.Name,
                                                     AuthorName = t.Author.UserName,
                                                     Priority = t.Priority,
                                                     Status = t.Status,
                                                     SearchRelevance = Helpers.Filter.CalcualteFilterTicketRelevance(t, filter.Q)
                                                 })
                                          .Where(t => t.SearchRelevance > 0 && t.Status != TicketStatus.Closed && t.Status != TicketStatus.Duplicate)
                                          .OrderByDescending(t => t.SearchRelevance)
                                          .ThenByDescending(t => t.Id);

            var pagedTicketsList = filteredTicketsList
                                                      .Skip((pageIndex - 1) * Properties.Settings.Default.TicketsPageSize)
                                                      .Take(Properties.Settings.Default.TicketsPageSize);

            var pagesCount = (int)Math.Ceiling((double)filteredTicketsList.Count() / Properties.Settings.Default.TicketsPageSize);
            var categoriesList = this.GetFilterList(t => new SelectListItem { Value = t.CategoryId.ToString(), Text = t.Category.Name });
            var prioritiesList = this.GetFilterList(t => new SelectListItem { Value = t.Priority.ToString(), Text = t.Priority.ToString() });
            var statusesList = this.GetFilterList(t => new SelectListItem { Value = t.Status.ToString(), Text = t.Status.ToString() });
            var authorsList = this.GetFilterList(t => new SelectListItem { Value = t.AuthorId.ToString(), Text = t.Author.UserName.ToString() });
            var titlesList = this.GetFilterList(t => new SelectListItem { Value = t.Title.ToString(), Text = t.Title.ToString() });

            var viewModel = new TicketsFilterableViewModel
            {
                TicketsList = pagedTicketsList,
                Filter = filter,
                PagesCount = pagesCount,
                TotalRecordsCount = filteredTicketsList.Count(),
                MetaData = new TicketsMetaDataViewModel
                {
                    CategoriesList = categoriesList,
                    PrioritiesList = prioritiesList,
                    StatusesList = statusesList,
                    AuthorsList = authorsList,
                    TitlesList = titlesList
                }
            };

            return View(viewModel);
        }