Esempio n. 1
0
        // GET: ClosedBusiness
        public ActionResult Index(string tag = null, string search = null)
        {
            var allTags = db.Tags.Where(s => s.Type == "Town");
            var tags    = allTags.Select(s => s.Name).Distinct().ToList();
            List <ClosedBusiness> listOfItems;

            if (!string.IsNullOrWhiteSpace(search))
            {
                listOfItems = db.ClosedBusinesses.Where(s => s.Details.ToLower().Contains(search.ToLower()) || s.Name.ToLower().Contains(search.ToLower()) || s.Address.ToLower().Contains(search.ToLower())).ToList();
            }
            else if (tag == null)
            {
                listOfItems = db.ClosedBusinesses.ToList();
            }
            else
            {
                listOfItems = allTags.Where(s => s.Name == tag).Select(s => s.TaggedBusiness).ToList();
            }
            var debtpertown = CalculateTownsAnAmountOwed(allTags);
            var response    = new ClosedBusinessResponse
            {
                Businesses            = listOfItems,
                TownTags              = tags,
                SummaryOfDebtPerTowns = debtpertown
            };

            return(Json(response, JsonRequestBehavior.AllowGet));
        }
 // GET: ClosedBusiness
 public ActionResult Index(string tag = null, string search =null)
 {
     var allTags = db.Tags.Where(s => s.Type == "Town");
     var tags = allTags.Select(s => s.Name).Distinct().ToList();
     List<ClosedBusiness> listOfItems;
     if (!string.IsNullOrWhiteSpace(search))
     {
         listOfItems = db.ClosedBusinesses.Where(s => s.Details.ToLower().Contains(search.ToLower()) || s.Name.ToLower().Contains(search.ToLower())|| s.Address.ToLower().Contains(search.ToLower())).ToList();
     }
     else if (tag == null)
     {
         listOfItems = db.ClosedBusinesses.ToList();
     }
     else
     {
         listOfItems = allTags.Where(s => s.Name == tag).Select(s => s.TaggedBusiness).ToList();
     }
     var response = new ClosedBusinessResponse
     {
         Businesses = listOfItems,
         TownTags = tags
     };
     return Json(response, JsonRequestBehavior.AllowGet);
 }