public RouteViewModel AddRoute(UpdateRouteModel route) { var dataRoute = CreateRoute(route); _db.Routes.Add(dataRoute); _db.SaveChanges(); return(Map <RouteViewModel>(dataRoute)); }
public RouteViewModel UpdateRoute(int id, UpdateRouteModel route) { var dataRoute = CreateRoute(route); dataRoute.Id = id; var originRoute = _db.Routes.Single(r => r.Id == id); originRoute.Price = dataRoute.Price; originRoute.Cities.Clear(); originRoute.Cities = dataRoute.Cities; _db.SaveChanges(); return(Map <RouteViewModel>(dataRoute)); }
private RouteDataModel CreateRoute(UpdateRouteModel route) { var dataRoute = Map <RouteDataModel>(route); var cityIdA = Convert.ToInt32(route.PointA); var cityIdB = Convert.ToInt32(route.PointB); var pointA = _db.Cities.Single(c => c.Id == cityIdA); var pointB = _db.Cities.Single(c => c.Id == cityIdB); dataRoute.Cities.Add(pointA); dataRoute.Cities.Add(pointB); return(dataRoute); }
public IHttpActionResult UpdateRoute(int id, UpdateRouteModel route) { return(Ok(_service.UpdateRoute(id, route))); }
public IHttpActionResult AddRoute(UpdateRouteModel route) { return(Ok(_service.AddRoute(route))); }