示例#1
0
        public ViewResult FilterList(EnterpriseListViewModel model, int page = 1)
        {
            // hack againts bug "Filter info is lost when we switch pages"
            // don't know how to pass here actual model, so we will use previous one
            if (model == null)
            {
                var cachedModel = Session["FilterModel"];
                if (cachedModel == null)
                {
                    return(View("Index", Index(null, page).Model));
                }
                else
                {
                    model = (EnterpriseListViewModel)cachedModel;
                }
            }

            if (ModelState.IsValid)
            {
                IList <EnterpriceType> types = new List <EnterpriceType>();
                foreach (var checkBox in model.TypeCategories)
                {
                    if (checkBox.Selected)
                    {
                        types.Add(this.GetEntType(checkBox.Value));
                    }
                }

                IList <int> ratings = new List <int>();
                foreach (var checkBox in model.RatingCategories)
                {
                    if (checkBox.Selected)
                    {
                        ratings.Add(int.Parse(checkBox.Value));
                    }
                }

                string name = model.SearchString;
                IEnumerable <Enterprise> query = ratings.Count == 0 && types.Count == 0 ?
                                                 entRepository.GetByName(name) : entRepository.GetFiltratedByName(ratings, types, name);
                if (model.SelectedSortingCategory == "Name")
                {
                    query = query.OrderBy(ent => ent.Name);
                }
                else
                {
                    query = query.OrderBy(ent => ent.Rating);
                }

                model.Enterprises = new List <Enterprise>(query);
            }

            EnterpriseListViewModel newModel = UpdateModel(model, page);

            model.PagingInfo       = new PagingInfo(newModel.PagingInfo);
            Session["FilterModel"] = new EnterpriseListViewModel(model);

            return(View("Index", newModel));
        }
示例#2
0
        public ViewResult Index(EnterpriseListViewModel model, int page = 1)
        {
            if (model == null)
            {
                model = new EnterpriseListViewModel();
            }

            this.SaveRole();

            if (string.IsNullOrEmpty(model.SearchString))
            {
                model.Enterprises = entRepository.Enterprises;
            }

            EnterpriseListViewModel newModel = UpdateModel(model, page);

            return(View(newModel));
        }
示例#3
0
 private EnterpriseListViewModel UpdateModel(EnterpriseListViewModel model, int page)
 {
     return(new EnterpriseListViewModel
     {
         Enterprises = this.SelectEnterprisesForPage(model.Enterprises.AsQueryable(), page),
         PagingInfo = new PagingInfo
         {
             CurrentPage = model.Enterprises.Count(),
             ItemsPerPage = this.PageSize,
             TotalItems = model.Enterprises.Count()
         },
         SearchString = model.SearchString,
         RatingCategories = model.RatingCategories.Count != 0 ?
                            model.RatingCategories : this.GetRatingItems(),
         TypeCategories = model.TypeCategories.Count != 0 ?
                          model.TypeCategories : this.GetTypeItems(),
         SortingCategories = model.SortingCategories.Count != 0 ?
                             model.SortingCategories : this.GetSortingItems()
     });
 }