Example #1
0
        public async Task <ActionResult> Categories(int?id, string searchString, string msg = "")
        {
            var contestants = from m in db.Contestants
                              select m;

            var category = await db.Categories.FindAsync(id);

            if (category == null)
            {
                return(RedirectToAction("Index"));
            }

            var c = new VoteCategoryViewModel
            {
                Category    = category,
                Contestants = db.Contestants.Where
                                  (a => a.Category.Id == category.Id).ToList()
            };

            if (!string.IsNullOrEmpty(searchString))
            {
                c = new VoteCategoryViewModel
                {
                    Category    = category,
                    Contestants = db.Contestants.Where(
                        x => x.Name.ToUpper().Contains(searchString.ToUpper()) &&
                        x.Category.Id == category.Id).ToList()
                }
            }
            ;


            return(View(c));
        }
Example #2
0
        public ActionResult AllCategories(int?id, string contCategory, string searchString, string sortOrder,
                                          string msg = "")
        {
            ViewBag.NameSortParm = string.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
            ViewBag.CatSortParm  = sortOrder == "Categoty" ? "cat_desc" : "Category";

            var conts = from g in db.Contestants
                        select g;

            var catLst = new List <string>();

            var catQuery = from d in db.Contestants
                           orderby d.Category.Title
                           select d.Category.Title;

            catLst.AddRange(catQuery.Distinct());
            ViewBag.contCategory = new SelectList(catLst, 0);

            var contestants = from m in db.Contestants
                              select m;
            var c = new VoteCategoryViewModel
            {
                Contestants = db.Contestants.ToList()
            };

            if (!string.IsNullOrEmpty(searchString))
            {
                c = new VoteCategoryViewModel
                {
                    Contestants = db.Contestants.Where(x => x.Name.ToUpper().Contains(searchString.ToUpper())).ToList()
                }
            }
            ;

            if (!string.IsNullOrEmpty(contCategory))
            {
                c = new VoteCategoryViewModel
                {
                    Contestants = db.Contestants.Where(x => x.Category.Title == contCategory).ToList()
                }
            }
            ;

            if (!string.IsNullOrEmpty(searchString) && !string.IsNullOrEmpty(contCategory))
            {
                c = new VoteCategoryViewModel
                {
                    Contestants = db.Contestants
                                  .Where(x => x.Name.ToUpper().Contains(searchString.ToUpper()) &&
                                         x.Category.Title == contCategory).ToList()
                }
            }
            ;

            return(View(c));
        }