Example #1
0
        public ActionResult Index(string sortOrder)
        {
            ViewBag.NameSortParm  = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
            ViewBag.PriceSortParm = sortOrder == "Price" ? "Price_desc" : "Price";
            var service = new CatService();
            var cats    = service.GetCats();

            switch (sortOrder)
            {
            case "name_desc":
                cats = cats.OrderByDescending(s => s.CatName);
                break;

            case "Price":
                cats = cats.OrderBy(s => s.CatPrice);
                break;

            case "Price_desc":
                cats = cats.OrderByDescending(s => s.CatPrice);
                break;

            default:
                cats = cats.OrderBy(s => s.CatName);
                break;
            }
            return(View(cats.ToList()));
        }
Example #2
0
 public ActionResult <IEnumerable <Cat> > Get()
 {
     try
     {
         return(Ok(_cs.GetCats()));
     }
     catch (System.Exception err)
     {
         return(BadRequest(err.Message));
     }
 }