public ActionResult Delete(busStop stop) { if (repository.Delete(stop)) { TempData["Success"] = "Запись удалена"; } return(RedirectToAction("Delete")); }
//---------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- #region adminMethods public void AddStop(busStop stop) { if (stop != null) { context.Stops.Add(stop); context.SaveChanges(); } }
public ActionResult DeleteConfirmed(int id) { busStop busStop = db.busStops.Find(id); db.busStops.Remove(busStop); db.SaveChanges(); return(RedirectToAction("Index")); }
public void AddStop(busStop stop) { if (stop != null) { context.Stops.Add(stop); context.SaveChanges(); } }
/// <summary> /// Combine routeCode and busStop to return schedule /// </summary> /// <param name="form"></param> /// <returns>selected busStop and selected busRoute schedule</returns> public ActionResult RouteStopSchedule(FormCollection form) { string busRouteCode = ""; //RouteSelector ActionResult of SPBusStopController may set this Session variable if (Session["routeCodeFromBusStop"] == null) { //RouteSelector View of SPBusStopController may select one of dropDownList if (form["routeNames"] == null) { TempData["message"] = "No Bus Route selected!"; return(RedirectToAction("index", "SPBusStop")); } else { busRouteCode = form["routeNames"]; } } else { busRouteCode = Session["routeCodeFromBusStop"].ToString(); Session["routeCodeFromBusStop"] = null; } int busStopNumber = (int)Session["busStopNumber"]; int offsetMinutes = 0; busRoute busRoute = db.busRoutes.Find(busRouteCode); ViewBag.selectedRouteName = busRouteCode + " - " + busRoute.routeName; busStop busStop = db.busStops.Find(busStopNumber); ViewBag.selectedLocation = busStopNumber + " - " + busStop.location; //Finds out offsetMunutes of selected busRoute and selected busStop //If there are more than one record found accidently, it abends!! var routeStop = db.routeStops.Where(a => a.busRouteCode == busRouteCode && a.busStopNumber == busStopNumber).Single(); offsetMinutes = (int)routeStop.offsetMinutes; //Composes all startTimes within the schedule var selectedSchedule = from r in db.routeSchedules where (r.busRouteCode == busRouteCode) orderby r.startTime select r; //Callculates busStop arrival times and returns model foreach (var item in selectedSchedule) { item.startTime = item.startTime.Add(TimeSpan.FromMinutes(offsetMinutes)); } return(View(selectedSchedule)); }
public ActionResult Edit(busStop stop) { if (repository.Update(stop)) { TempData["Success"] = "Запись обновлена"; } else { TempData["Erors"] = "Запись не обновлена"; } return(RedirectToAction("Edit")); }
// GET: SPBusStop/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } busStop busStop = db.busStops.Find(id); if (busStop == null) { return(HttpNotFound()); } return(View(busStop)); }
public bool Contain(busStop stop) { bool result; IEnumerable<busStop> list = Filter(stop); if (list.Count() != 0) { result = true; } else { result = false; } return result; }
public bool Contain(busStop stop) { bool result; IEnumerable <busStop> list = Filter(stop); if (list.Count() != 0) { result = true; } else { result = false; } return(result); }
public bool Delete(busStop stop) { bool result; busStop item = Filter(stop).FirstOrDefault(); if (item != null) { context.Stops.Remove(item); context.SaveChanges(); result = true; } else { result = false; } return result; }
public bool Update(busStop stop) { bool result; busStop item = Filter(stop).FirstOrDefault(); if (item != null) { item.stops = stop.stops; context.SaveChanges(); result = true; } else { result = false; } return(result); }
public bool Delete(busStop stop) { bool result; busStop item = Filter(stop).FirstOrDefault(); if (item != null) { context.Stops.Remove(item); context.SaveChanges(); result = true; } else { result = false; } return(result); }
private Hashtable parser(String stopID, String html) { Hashtable busStops = new Hashtable(); char[] delimiter = { '\n' }; System.Diagnostics.Debug.WriteLine("Parsing " + stopID + ": " + html); //MatchCollection matches = Regex.Matches(html, ";;\\s\">(.*?)</span>"); if (html.Length > 0) { //MatchCollection matches = Regex.Matches(html, "</em>\\sat\\s(.*?)[am|pm]<br/>"); MatchCollection matches = Regex.Matches(html, "Time\":\"\\s(.*?)[AM|PM]\",\""); if (matches.Count > 0) { busStop busStoptemp = new busStop(); String busTimestemp = ""; busStoptemp.id = stopID; foreach (Match match in matches) { busTimestemp += match.Groups[1].Value.Trim() + " "; System.Diagnostics.Debug.WriteLine("time is" + match.Groups[1].Value.Trim()); } System.Diagnostics.Debug.WriteLine("time is" + busTimestemp); busStoptemp.times = busTimestemp.Trim().Split(new char[] { ' ' }); busStops.Add(stopID, busStoptemp); } //String[] htmlArray = html.Split(delimiter); //if (htmlArray.Length > 10) //{ // busStop busStopTemp = new busStop(); // busStopTemp.id = stopID; // String stopNameTemp = htmlArray[10].Remove(0, 43); // busStopTemp.stopName = stopNameTemp.Substring(0, stopNameTemp.IndexOf("<")); // busStopTemp.times = htmlArray[11].Trim().Split(new char[] { ' ' }); // busStops.Add(stopID, busStopTemp); //} } return(busStops); }
public ActionResult Create([Bind(Include = "busStopNumber,location,locationHash,goingDowntown")] busStop busStop) { if (ModelState.IsValid) { // Calculating byte sum of a String and it's going to be a locationHash int byteSum = 0; for (int i = 0; i < busStop.location.Length; i++) { byteSum += (byte)busStop.location[i]; } busStop.locationHash = byteSum; db.busStops.Add(busStop); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(busStop)); }
public ActionResult AddStop(busStop stop) { if (!ModelState.IsValid) { var model = CreateViewModel(); model.Stop = stop; return(View(model)); } Regex reg = new Regex(@"\d{1,2}:\d{1,2}"); MatchCollection matches = reg.Matches(stop.stops); if (matches.Count == 0) { ModelState.AddModelError("", "Неправильно заполнено расписание"); var model = CreateViewModel(); model.Stop = stop; return(View(model)); } else if (repository.Contain(stop)) { ModelState.AddModelError("", "Запись уже существует"); var model = CreateViewModel(); model.Stop = stop; return(View(model)); } else { StringBuilder stops = new StringBuilder(); foreach (Match match in matches) { string time = match.Value; stops.Append(time + " "); } stop.stops = stops.ToString(); repository.AddStop(stop); TempData["Success"] = "Запись добавлена"; } return(RedirectToAction("AddStop")); }
//----------------------------------------------------------------------------------- private IEnumerable <busStop> Filter(busStop stop) { return(context.Stops.Where(x => x.busNumber == stop.busNumber && x.stopName == stop.stopName && x.finalStop == stop.finalStop && x.days == stop.days)); }
public ActionResult Delete(busStop stop) { if (repository.Delete(stop)) { TempData["Success"] = "Запись удалена"; } return RedirectToAction("Delete"); }
public ActionResult Edit(busStop stop) { if (repository.Update(stop)) { TempData["Success"] = "Запись обновлена"; } else { TempData["Erors"] = "Запись не обновлена"; } return RedirectToAction("Edit"); }
public ActionResult AddStop(busStop stop) { if (!ModelState.IsValid) { var model = CreateViewModel(); model.Stop = stop; return View(model); } Regex reg = new Regex(@"\d{1,2}:\d{1,2}"); MatchCollection matches = reg.Matches(stop.stops); if (matches.Count == 0) { ModelState.AddModelError("", "Неправильно заполнено расписание"); var model = CreateViewModel(); model.Stop = stop; return View(model); } else if (repository.Contain(stop)) { ModelState.AddModelError("", "Запись уже существует"); var model = CreateViewModel(); model.Stop = stop; return View(model); } else { StringBuilder stops = new StringBuilder(); foreach (Match match in matches) { string time = match.Value; stops.Append(time + " "); } stop.stops = stops.ToString(); repository.AddStop(stop); TempData["Success"] = "Запись добавлена"; } return RedirectToAction("AddStop"); }
//----------------------------------------------------------------------------------- private IEnumerable<busStop> Filter(busStop stop) { return context.Stops.Where(x => x.busNumber == stop.busNumber && x.stopName == stop.stopName && x.finalStop == stop.finalStop && x.days == stop.days); }
private Hashtable parser(String stopID, String html) { Hashtable busStops = new Hashtable(); char[] delimiter = { '\n' }; System.Diagnostics.Debug.WriteLine("Parsing " + stopID + ": " + html); //MatchCollection matches = Regex.Matches(html, ";;\\s\">(.*?)</span>"); if (html.Length > 0) { //MatchCollection matches = Regex.Matches(html, "</em>\\sat\\s(.*?)[am|pm]<br/>"); MatchCollection matches = Regex.Matches(html, "Time\":\"\\s(.*?)[AM|PM]\",\""); if (matches.Count > 0) { busStop busStoptemp = new busStop(); String busTimestemp = ""; busStoptemp.id = stopID; foreach (Match match in matches) { busTimestemp += match.Groups[1].Value.Trim() + " "; System.Diagnostics.Debug.WriteLine("time is" + match.Groups[1].Value.Trim()); } System.Diagnostics.Debug.WriteLine("time is" + busTimestemp); busStoptemp.times = busTimestemp.Trim().Split(new char[] {' '}); busStops.Add(stopID, busStoptemp); } //String[] htmlArray = html.Split(delimiter); //if (htmlArray.Length > 10) //{ // busStop busStopTemp = new busStop(); // busStopTemp.id = stopID; // String stopNameTemp = htmlArray[10].Remove(0, 43); // busStopTemp.stopName = stopNameTemp.Substring(0, stopNameTemp.IndexOf("<")); // busStopTemp.times = htmlArray[11].Trim().Split(new char[] { ' ' }); // busStops.Add(stopID, busStopTemp); //} } return busStops; }
public bool Update(busStop stop) { bool result; busStop item = Filter(stop).FirstOrDefault(); if (item != null) { item.stops = stop.stops; context.SaveChanges(); result = true; } else { result = false; } return result; }