private DodgingBranches.Models.Route MapViewModelToDomain(Models.EditRouteViewModel routeViewModel) { var returnRoute = new DodgingBranches.Models.Route(); returnRoute.Name = routeViewModel.Name; returnRoute.RouteId = routeViewModel.Id; returnRoute.StartPoint = new MapPoint { Latitude = routeViewModel.StartPoint.Latitude, Longitude = routeViewModel.StartPoint.Longitude }; returnRoute.EndPoint = new MapPoint { Latitude = routeViewModel.EndPoint.Latitude, Longitude = routeViewModel.EndPoint.Longitude }; returnRoute.UserId = routeViewModel.EnteredBy; returnRoute.Comments = routeViewModel.Comments.Select(x => new DodgingBranches.Models.Comment { CommentId = x.Id, CommentText = x.CommentText, DateEntered = x.DateEntered, ParentCommentId = x.ParentCommentId, RouteId = x.RouteId, UserId = x.UserId }).ToList(); returnRoute.DateEntered = routeViewModel.DateEntered; returnRoute.Description = routeViewModel.Description; returnRoute.StartLocation = new DodgingBranches.Models.Address { Address1 = routeViewModel.Addr.Addr, City = routeViewModel.Addr.City, AddressId = routeViewModel.Addr.AddressId, State = routeViewModel.Addr.SelectedState, ZipCode = routeViewModel.Addr.Zip }; returnRoute.EndLocation = new DodgingBranches.Models.Address { Address1 = routeViewModel.EndAddr.Addr, City = routeViewModel.EndAddr.City, AddressId = routeViewModel.EndAddr.AddressId, State = routeViewModel.EndAddr.SelectedState, ZipCode = routeViewModel.EndAddr.Zip }; returnRoute.Tags = routeViewModel.Tags.Select(x => new DodgingBranches.Models.Tag { TagId = x.Id, TagText = x.TagName }).ToList(); return(returnRoute); }
public ActionResult Edit(int routeId) { var model = new Models.EditRouteViewModel(); var context = new Context(); var route = context.Routes.FirstOrDefault(x => x.Id == routeId); if (route == null) return new HttpStatusCodeResult(404); model.RouteId = route.Id; model.RouteName = route.Name; return View(model); }