Exemplo n.º 1
0
        public ActionResult Index(string description, string url, string ranking, string sortOrder, string pendingFlag, string subtitleFlag,
                                  string oldFlag, string topFlag, string seriesFlag, int?languageId, int?linkCategoryId, int?page = null)
        {
            ViewBag.LanguageId             = new SelectList(CombosHelper.GetLanguages(), "LanguageId", "Name");
            ViewBag.LinkCategoryId         = new SelectList(CombosHelper.GetLinkCategory(), "LinkCategoryId", "Name");
            ViewBag.LinkCategorySelectedId = linkCategoryId;
            ViewBag.LanguageSelectedId     = languageId;
            ViewBag.SeriesSelectedFlag     = seriesFlag;
            ViewBag.TopSelectedFlag        = topFlag;
            ViewBag.OldSelectedFlag        = oldFlag;
            ViewBag.SubtitleSelectedFlag   = subtitleFlag;
            ViewBag.PendingSelectedFlag    = pendingFlag;
            ViewBag.RankingSelected        = ranking;
            ViewBag.UrlSelected            = url;
            ViewBag.DescriptionSelected    = description;

            if (ranking == string.Empty)
            {
                ranking = null;
            }
            if (Convert.ToBoolean(pendingFlag) == false)
            {
                pendingFlag = null;
            }
            if (Convert.ToBoolean(subtitleFlag) == false)
            {
                subtitleFlag = null;
            }
            if (Convert.ToBoolean(oldFlag) == false)
            {
                oldFlag = null;
            }
            if (Convert.ToBoolean(topFlag) == false)
            {
                topFlag = null;
            }
            if (Convert.ToBoolean(seriesFlag) == false)
            {
                seriesFlag = null;
            }

            if (Convert.ToInt32(languageId) == 0)
            {
                languageId = null;
            }
            if (Convert.ToInt32(linkCategoryId) == 0)
            {
                linkCategoryId = null;
            }

            var rankingParameter  = Convert.ToInt32(ranking);
            var pendingParameter  = Convert.ToBoolean(pendingFlag);
            var subtitleParameter = Convert.ToBoolean(subtitleFlag);
            var oldParameter      = Convert.ToBoolean(oldFlag);
            var topParameter      = Convert.ToBoolean(topFlag);
            var seriesParameter   = Convert.ToBoolean(seriesFlag);

            page = (page ?? 1);
            var links = db.Links.Include(l => l.Language).Include(l => l.LinkCategory);

            links = db.Links.Where(c => (c.Description.Contains(description) || description == null) &&
                                   (c.Url.Contains(url) || url == null) &&
                                   (c.Ranking.Equals(rankingParameter) || ranking == null) &&
                                   (c.Pending.Equals(pendingParameter) || pendingFlag == null) &&
                                   (c.Subtitle.Equals(subtitleParameter) || subtitleFlag == null) &&
                                   (c.Old.Equals(oldParameter) || oldFlag == null) &&
                                   (c.Top.Equals(topParameter) || topFlag == null) &&
                                   (c.Series.Equals(seriesParameter) || seriesFlag == null) &&
                                   (c.LanguageId == languageId || languageId == null) &&
                                   (c.LinkCategoryId == linkCategoryId || linkCategoryId == null)
                                   );

            ViewBag.RecordCount = links.ToList().Count;

            ViewBag.CurrentSort  = sortOrder;
            ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "description" : "";
            ViewBag.DateSortParm = sortOrder == "Date" ? "date_desc" : "Date";
            switch (sortOrder)
            {
            case "description":
                links = links.OrderByDescending(s => s.Description);
                break;

            case "Date":
                links = links.OrderBy(s => s.CreationDate);
                break;

            case "date_desc":
                links = links.OrderByDescending(s => s.CreationDate);
                break;

            default:
                links = links.OrderBy(s => s.Description);
                break;
            }


            return(View(links.ToPagedList((int)page, 10)));
        }