// GET: /Event/ public ActionResult Index(NailVent nv) { return(View()); }
/// <summary> /// Returns a details page if the nailpartialview is clicked. TODO: needs to be more dynamic /// </summary> /// <param name="gEventGUID">Guid of the event</param> /// <returns>Details page of the selected event</returns> public ActionResult EventClicked(Guid gEventGUID) { var eventsQRY = from r in m_db.Event where r.bIsDeleted == false && r.gEventGUID == gEventGUID select r; Random random = new Random(); var returnedQryEventClicked = (IQueryable)null; string strTagToUse = string.Empty; string strCityEventClicked = string.Empty; string strStateEventClicked = string.Empty; string strDateEventClicked = string.Empty; bool tag1 = false; bool tag2 = false; bool tag3 = false; switch (random.Next(1, 4)) // randomly selects which tag will be used to find a similar event { case 1: tag1 = true; break; case 2: tag2 = true; break; case 3: tag3 = true; break; default: tag1 = true; break; } foreach (MVCEventBench.Models.Event vent in eventsQRY) // collects the information so we can use this to find similar events { if (tag1) { strTagToUse = vent.strTag1; } if (tag2) { strTagToUse = vent.strTag2; } if (tag3) { strTagToUse = vent.strTag3; } strCityEventClicked = vent.strEventCity; strStateEventClicked = vent.strEventState; strDateEventClicked = vent.dEventDateStart.ToString(); } // This will return us a query to use to build the nailvents returnedQryEventClicked = GetFilteredQuery(strCityEventClicked, strStateEventClicked, strTagToUse, strDateEventClicked, "25"); int intQryLength = returnedQryEventClicked.Count(); // length of the returned query - need to know if there is less than 4 total including original List <Guid> listSimilarEvents = new List <Guid>(); List <Guid> listFinalSelection = new List <Guid>(); // Goes through the query of similar events and extracts all of them except for the one we started with foreach (MVCEventBench.Models.Event similarEvent in returnedQryEventClicked) { if (!similarEvent.gEventGUID.Equals(gEventGUID)) { listSimilarEvents.Add(similarEvent.gEventGUID); } } NailVent nvSimilar0; NailVent nvSimilar1; NailVent nvSimilar2; /********************************************************************** * This next piece will fill the list of selected events from the entire list of similar events * It goes through the loop and selects a random event from the similar event list and then assigns it to the final selection as long as it hasn't already been assigned to it ***********************************************************************/ if (listSimilarEvents.Count > 3) { while (listFinalSelection.Count < 3) { int i = random.Next(0, listSimilarEvents.Count); if (!listFinalSelection.Contains(listSimilarEvents[i])) { listFinalSelection.Add(listSimilarEvents[i]); } } } else { listFinalSelection = listSimilarEvents; } int countSimilar = 0; if (listFinalSelection.Count == 1) { countSimilar = 1; nvSimilar0 = m_BuildControlsMgr.BuildEventControl(listSimilarEvents[0]); ViewBag.nvSimilar0 = nvSimilar0; nvSimilar1 = m_BuildControlsMgr.BuildEventControl(listSimilarEvents[0]); ViewBag.nvSimilar1 = nvSimilar1; nvSimilar2 = m_BuildControlsMgr.BuildEventControl(listSimilarEvents[0]); ViewBag.nvSimilar2 = nvSimilar2; } else if (listFinalSelection.Count == 2) { countSimilar = 2; nvSimilar0 = m_BuildControlsMgr.BuildEventControl(listSimilarEvents[0]); ViewBag.nvSimilar0 = nvSimilar0; nvSimilar1 = m_BuildControlsMgr.BuildEventControl(listSimilarEvents[1]); ViewBag.nvSimilar1 = nvSimilar1; nvSimilar2 = m_BuildControlsMgr.BuildEventControl(listSimilarEvents[1]); ViewBag.nvSimilar2 = nvSimilar2; } else if (listFinalSelection.Count >= 3) { countSimilar = 3; nvSimilar0 = m_BuildControlsMgr.BuildEventControl(listSimilarEvents[0]); ViewBag.nvSimilar0 = nvSimilar0; nvSimilar1 = m_BuildControlsMgr.BuildEventControl(listSimilarEvents[1]); ViewBag.nvSimilar1 = nvSimilar1; nvSimilar2 = m_BuildControlsMgr.BuildEventControl(listSimilarEvents[2]); ViewBag.nvSimilar2 = nvSimilar2; } else { countSimilar = 0; } NailVent nv = m_BuildControlsMgr.BuildEventControl(gEventGUID); ViewBag.nvDetails = nv; ViewBag.simCount = countSimilar; //Place into a separate method float dMapLat = 0; float dMapLong = 0; Guid gMapState = Guid.Empty; var qryMapStates = from r in m_db.States where r.strName == nv.State select r; foreach (MVCEventBench.Models.States state in qryMapStates) { gMapState = state.gStateGUID; } var qryMapCities = from r in m_db.Cities where r.gState == gMapState && r.strCity == nv.City select r; foreach (MVCEventBench.Models.Cities city in qryMapCities) { dMapLat = city.nLatitude; dMapLong = city.nLongitude; } ViewBag.mapAddress = nv.Address + " " + nv.City + " " + nv.State; ViewBag.mapLat = dMapLat; ViewBag.mapLong = dMapLong; //End region //Might need to add a view here that returns a event not found page if nv is null return(View("/Views/Home/Details.cshtml", nv)); }