Esempio n. 1
0
        public ActionResult Index()
        {
            var userId = ReturnUserId();

            ViewBag.userID = HttpContext.User.Identity.GetUserId();

            var items    = db.Items.Include(i => i.Donation_Categories).Include(i => i.Donation_Location).Include(i => i.User).ToList();
            var requests = db.Requests.Where(r => r.RequesterID == userId).ToList();

            var tuple = new Tuple <List <Item>, List <Request> >(items, requests); // combines the item and request into one object.

            var categories = db.Donation_Categories.ToList();
            var locations  = db.Donation_Location.ToList();

            var emptyCat = new Donation_Categories()
            {
                Categories = " "
            };

            var emptyLoc = new Donation_Location()
            {
                BusinessName = " "
            };

            categories.Insert(0, emptyCat);
            locations.Insert(0, emptyLoc);

            ViewBag.CategoryID = new SelectList(categories, "CategoryID", "Categories");
            ViewBag.LocationID = new SelectList(locations, "LocationID", "BusinessName");
            return(View(tuple));
        }
        // GET: Donation_Location/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Donation_Location donation_Location = db.Donation_Location.Find(id);

            if (donation_Location == null)
            {
                return(HttpNotFound());
            }
            return(View(donation_Location));
        }
Esempio n. 3
0
        public ActionResult SortBy([Optional] string LocationID, [Optional] string CategoryID)
        {
            var userId = ReturnUserId();

            ViewBag.userID = HttpContext.User.Identity.GetUserId();

            var requests = db.Requests.Where(r => r.RequesterID == userId).ToList();
            var items    = db.Items.Include(i => i.Donation_Categories).Include(i => i.Donation_Location).Include(i => i.User).Select(i => i);

            if (CategoryID != 0.ToString())
            {
                int catInt;
                int.TryParse(CategoryID, out catInt);
                items = items.Where(i => i.Donation_Categories.CategoryID == catInt);
            }

            if (LocationID != 0.ToString())
            {
                int locInt;
                int.TryParse(LocationID, out locInt);
                items = items.Where(i => i.Donation_Location.LocationID == locInt);
            }
            var search = items.ToList();

            var tuple = new Tuple <List <Item>, List <Request> >(search, requests); // combines the item and request into one object.

            var emptyCat = new Donation_Categories()
            {
                Categories = " "
            };

            var emptyLoc = new Donation_Location()
            {
                BusinessName = " "
            };

            var categories = db.Donation_Categories.ToList();
            var locations  = db.Donation_Location.ToList();

            categories.Insert(0, emptyCat);
            locations.Insert(0, emptyLoc);

            ViewBag.CategoryID = new SelectList(categories, "CategoryID", "Categories");
            ViewBag.LocationID = new SelectList(locations, "LocationID", "BusinessName");
            return(View("Index", tuple));
        }