public EditRouteVM GetRoute(int id) { var route = _context.Routes.Find(id); EditRouteVM data = new EditRouteVM(); data.city = route.City; data.state = route.State; data.name = route.Name; data.description = route.Description; data.totalDistance = route.TotalDistance; data.totalElevationGain = route.TotalElevationGain; data.totalElevationLoss = route.TotalElevationLoss; data.ownerName = GetOwnerName(route); data.coordinates = GetRouteCoordinates(id); List <PointComment> pointComments = getPointComments(id); data.pointCommentAuthors = pointComments.Select(a => a.Writer).ToList(); data.pointComments = pointComments.Select(a => a.Note).ToList(); data.pointCoordinates = GetCoordinatesOfPointComments(pointComments); List <PathComment> pathComments = _context.PathComments.Where(a => a.RouteId == id).ToList(); data.pathCommentAuthors = pathComments.Select(a => a.Writer).ToList(); data.pathComments = pathComments.Select(a => a.Note).ToList(); data.pathCoordinates = GetPathCommentsCoordinates(pathComments); return(data); }
public EditRouteVM GetEventRoute(int id) { var route = _context.Routes.Find(id); EditRouteVM data = new EditRouteVM(); data.city = route.City; data.state = route.State; data.name = route.Name; data.description = route.Description; data.totalDistance = route.TotalDistance; data.totalElevationGain = route.TotalElevationGain; data.totalElevationLoss = route.TotalElevationLoss; var owner = _context.Users.Find(route.UserId); data.ownerName = $"{owner.FirstName} {owner.LastName}"; var points = _context.RouteCoordinates.Where(a => a.RouteId == id).OrderBy(a => a.SortOrder).ToList(); data.coordinates = CreateRouteCoordsArrayForClient(points); List <PointComment> pointComments = getPointComments(id); data.pointCommentAuthors = pointComments.Select(a => a.Writer).ToList(); data.pointComments = pointComments.Select(a => a.Note).ToList(); data.pointCoordinates = CreateRouteCoordsArrayForClient(pointComments); List <PathComment> pathComments = _context.PathComments.Where(a => a.RouteId == id).ToList(); data.pathCommentAuthors = pathComments.Select(a => a.Writer).ToList(); data.pathComments = pathComments.Select(a => a.Note).ToList(); data.pathCoordinates = CreateRouteCoordsArrayForClient(pathComments); return(data); }
public IActionResult Update(EditRouteVM editRouteVM) { if (ModelState.IsValid) { _unitOfWork.OperatingDays.Update(editRouteVM.OperatingDays); _unitOfWork.TicketPrice.Update(editRouteVM.TicketPrice); _unitOfWork.Save(); return(RedirectToAction(nameof(Index))); } else { return(View(editRouteVM)); } }
public IActionResult Update(int id) { Timetable timetable = _unitOfWork.Timetable.GetFirstOrDefault(t => t.Id == id); if (timetable == null) { return(NotFound()); } EditRouteVM editRouteVM = new EditRouteVM() { OperatingDays = _unitOfWork.OperatingDays.GetFirstOrDefault(op => op.Id == timetable.OperatingDaysId), TicketPrice = _unitOfWork.TicketPrice.GetFirstOrDefault(tp => tp.Id == timetable.TicketPriceId) }; return(View(editRouteVM)); }