Exemple #1
0
        // GET: /Map_Boards/
        public ActionResult Index(string searchString, string boardType, string dmas, string vendors, int mapId)
        {
            // Save the MapID in the Viewbag for redirecting back
            ViewBag.MapID = mapId;


            // Create a list of Boards to filter against
            var boards = from a in db.Boards
                         select a;

            // Create a list of Map_Boards to see if the Board is already associated with this Map
            var map_boards = from a in db.Map_Boards
                             where a.MapID == mapId
                             select a;

            ViewBag.MapBoards = map_boards;


            // Check for a previous search for this user
            UserSearch userSearch = db.UserSearches.SingleOrDefault(s => s.Username == User.Identity.Name);


            // Create search dropdowns
            // BoardTypes
            if (userSearch != null && !String.IsNullOrEmpty(userSearch.BoardType))
            {
                ViewBag.BoardType = new SelectList(db.BoardTypes.OrderBy(s => s.BoardType1), "BoardType1", "BoardType1", userSearch.BoardType);
            }
            else
            {
                ViewBag.BoardType = new SelectList(db.BoardTypes.OrderBy(s => s.BoardType1), "BoardType1", "BoardType1");
            }


            // DMAs
            if (userSearch != null && !String.IsNullOrEmpty(userSearch.DMA))
            {
                ViewBag.DMAs = new SelectList(db.DMAs.OrderBy(s => s.DMA1), "DMA1", "DMA1", userSearch.DMA);
            }
            else
            {
                ViewBag.DMAs = new SelectList(db.DMAs.OrderBy(s => s.DMA1), "DMA1", "DMA1");
            }


            // Board Vendors
            if (userSearch != null && !String.IsNullOrEmpty(userSearch.Vendor))
            {
                ViewBag.Vendors = new SelectList(db.BoardVendors.OrderBy(s => s.Vendor), "Vendor", "Vendor", userSearch.Vendor);
            }
            else
            {
                ViewBag.Vendors = new SelectList(db.BoardVendors.OrderBy(s => s.Vendor), "Vendor", "Vendor");
            }



            // Save the current search in the database
            // If an existing search record exists, then update it with the new search text
            if ((!String.IsNullOrEmpty(searchString) || !String.IsNullOrEmpty(boardType) || !String.IsNullOrEmpty(dmas) || !String.IsNullOrEmpty(vendors)) && userSearch != null)
            {
                userSearch.BoardsSearchString = searchString;
                userSearch.BoardType          = boardType;
                userSearch.DMA    = dmas;
                userSearch.Vendor = vendors;

                db.Entry(userSearch).State = EntityState.Modified;
                db.SaveChanges();
            }

            // If the user has no existing searches, then add a new record with the search text
            if ((!String.IsNullOrEmpty(searchString) || !String.IsNullOrEmpty(boardType) || !String.IsNullOrEmpty(dmas) || !String.IsNullOrEmpty(vendors)) && userSearch == null)
            {
                var newUserSearch = new Models.UserSearch();
                newUserSearch.Username           = User.Identity.Name;
                newUserSearch.BoardsSearchString = searchString;
                newUserSearch.BoardType          = boardType;
                newUserSearch.DMA    = dmas;
                newUserSearch.Vendor = vendors;

                db.UserSearches.Add(newUserSearch);
                db.SaveChanges();
            }


            // If this is a fresh page load, get the saved search if there is one
            if (userSearch != null && (!String.IsNullOrEmpty(userSearch.BoardsSearchString) || !String.IsNullOrEmpty(userSearch.BoardType) || !String.IsNullOrEmpty(userSearch.DMA) || !String.IsNullOrEmpty(userSearch.Vendor)))
            {
                searchString = userSearch.BoardsSearchString;
                boardType    = userSearch.BoardType;
                dmas         = userSearch.DMA;
                vendors      = userSearch.Vendor;

                ViewBag.BoardsSearchString = searchString;
            }


            // Set the search results to nothing by default
            if (String.IsNullOrEmpty(searchString) && String.IsNullOrEmpty(boardType) && String.IsNullOrEmpty(dmas) && String.IsNullOrEmpty(vendors))
            {
                boards = boards.Where(s => s.BoardNumber.Contains("fkwlenbisengoapengies"));
            }


            // Filter by text, if there is any
            if (!String.IsNullOrEmpty(searchString))
            {
                boards = boards.Where(s => s.BoardNumber.Contains(searchString) || s.Description.Contains(searchString) || s.Tags.Contains(searchString));
            }

            // Filter by BoardType, if one has been selected in the dropdown
            if (!String.IsNullOrEmpty(boardType))
            {
                boards = boards.Where(x => x.BoardType.BoardType1 == boardType);
            }

            // Filter by DMA, if one has been selected in the dropdown
            if (!String.IsNullOrEmpty(dmas))
            {
                boards = boards.Where(x => x.DMA.DMA1 == dmas);
            }

            // Filter by Board Vendor, if one has been selected in the dropdown
            if (!String.IsNullOrEmpty(vendors))
            {
                boards = boards.Where(x => x.BoardVendor.Vendor == vendors);
            }


            // If the user searches for *, show all records
            if (searchString == "*" && String.IsNullOrEmpty(boardType) && String.IsNullOrEmpty(dmas) && String.IsNullOrEmpty(vendors))
            {
                boards = from a in db.Boards
                         select a;
            }


            // Return the filtered list in alphabetical order
            return(View(boards.OrderBy(s => s.BoardNumber)));
        }
Exemple #2
0
        // GET: /Maps/
        public ActionResult Index(string searchString)
        {
            // Send the default map values
            MapDefault mapDefaults = db.MapDefaults.Find(1);

            ViewBag.DefaultWidth                    = mapDefaults.Width;
            ViewBag.DefaultHeight                   = mapDefaults.Height;
            ViewBag.DefaultCenterOnLat              = mapDefaults.CenterOnLat;
            ViewBag.DefaultCenterOnLong             = mapDefaults.CenterOnLong;
            ViewBag.DefaultZoomLevel                = mapDefaults.ZoomLevel;
            ViewBag.DefaultDisplayZoomControl       = mapDefaults.DisplayZoomControl.ToString();
            ViewBag.DefaultDisplayMapTypeControl    = mapDefaults.DisplayMapTypeControl.ToString();
            ViewBag.DefaultDisplayScaleControl      = mapDefaults.DisplayScaleControl.ToString();
            ViewBag.DefaultDisplayStreetViewControl = mapDefaults.DisplayStreetViewControl.ToString();
            ViewBag.DefaultDisplayPanControl        = mapDefaults.DisplayPanControl.ToString();

            // Create a list of Maps to filter against
            var maps = from a in db.Maps
                       select a;

            // Check for a previous search for this user
            UserSearch userSearch = db.UserSearches.SingleOrDefault(s => s.Username == User.Identity.Name);

            // Save the current search in the database
            // If an existing search record exists, then update it with the new search text
            if (!String.IsNullOrEmpty(searchString) && userSearch != null)
            {
                userSearch.MapsSearchString = searchString;
                db.Entry(userSearch).State  = EntityState.Modified;
                db.SaveChanges();
            }

            // If the user has no existing searches, then add a new record with the search text
            if (!String.IsNullOrEmpty(searchString) && userSearch == null)
            {
                var newUserSearch = new Models.UserSearch();
                newUserSearch.Username         = User.Identity.Name;
                newUserSearch.MapsSearchString = searchString;
                db.UserSearches.Add(newUserSearch);
                db.SaveChanges();
            }


            // If this is a fresh page load, get the saved search if there is one
            if (userSearch != null && !String.IsNullOrEmpty(userSearch.MapsSearchString))
            {
                searchString             = userSearch.MapsSearchString;
                ViewBag.MapsSearchString = searchString;
            }


            // Set the search results to nothing by default
            if (String.IsNullOrEmpty(searchString))
            {
                maps = maps.Where(s => s.Title.Contains("fkwlenbisengoapengies"));
            }


            // Filter by text, if there is any
            if (!String.IsNullOrEmpty(searchString))
            {
                maps = maps.Where(s => s.Title.Contains(searchString) || s.Description.Contains(searchString) || s.Tags.Contains(searchString));
            }


            // If the user searches for *, show all records
            if (searchString == "*")
            {
                maps = from a in db.Maps
                       select a;
            }


            // Return the filtered list in alphabetical order
            return(View(maps.OrderBy(s => s.Title)));
        }