/// <summary> /// Connects the stops with routes. /// </summary> /// <param name="stopGeo"> /// The stop's geo. /// </param> /// <returns> /// List of viewModelsWithStops. /// </returns> private IEnumerable<TmpAddRouteStopViewModel> ConnectStopsWithRoutes(AddStopViewModel stopGeo) { var connectList = new List<TmpAddRouteStopViewModel>(); var routes = this.routeRepository.All(); foreach (var route in routes) { var stop = stopGeo.StopGeography; var sqlGeography = Functions.MakeValidGeographyFromText(stop, 4326); if ((bool)route.RouteGeography.STIntersects(sqlGeography) && route.RouteType == int.Parse(stopGeo.Selected)) { connectList.Add( new TmpAddRouteStopViewModel { Route = route, StopPoint = route.RouteGeography.STIntersection(sqlGeography).STPointN(1) // первое пересечение с точкой. Не magick-number. }); } } return connectList; }
public ActionResult AddStop(AddStopViewModel addStop) { if (!this.ModelState.IsValid) { return View("AddStop", addStop); } string name = addStop.Name; IEnumerable<TmpAddRouteStopViewModel> routesList = this.ConnectStopsWithRoutes(addStop); foreach (TmpAddRouteStopViewModel intersectObect in routesList) { var intermediateToFineIntersects = new List<Route> { intersectObect.Route }; var intermidStop = new Stop { Name = name, StopGeography = intersectObect.StopPoint, StopType = int.Parse(addStop.Selected), Routes = intermediateToFineIntersects }; this.stopRepository.Add(intermidStop); } this.stopRepository.Save(); return this.RedirectToAction("AddStop"); }
public void AddStop_Action_Adds_New_Stop_When_The_AddStopViewModel_Model_Is_Valid() { // Arrange var stopViewModel = new AddStopViewModel { Name = "Test4", StopGeography = "POLYGON((10 10, 40 10, 40 40, 10 40, 10 10))", Selected = "2" }; // Act this.addRouteController.AddStop(stopViewModel); // Assert Assert.AreEqual(14, FakeRepository<Stop>.Mock(fakeDbContext.Stops).All().Count()); }
/// <summary> /// Adds the stop. /// </summary> /// <returns> /// View result. /// </returns> public ViewResult AddStop() { var addStopViewModel = new AddStopViewModel { Type = this.itemsForDropDown, Selected = ((int)Transport.Bus).ToString() }; return View("AddStop", addStopViewModel); }
public void AddStop_Action_Returns_ViewResult__When_The_AddStopViewModel_Model_Is_Invalid() { // Arrange const string ExpectedViewName = "AddStop"; var stopViewModel = new AddStopViewModel { Name = string.Empty, StopGeography = string.Empty }; this.addRouteController.ModelState.AddModelError("ModelError", "Error!"); // Act var result = this.addRouteController.AddStop(stopViewModel) as ViewResult; // Assert Assert.IsNotNull(result, "Should have returned a ViewResult"); Assert.AreEqual(ExpectedViewName, result.ViewName, "View name should have been {0}", ExpectedViewName); }