コード例 #1
0
        public RouteViewModel AddRoute(UpdateRouteModel route)
        {
            var dataRoute = CreateRoute(route);

            _db.Routes.Add(dataRoute);
            _db.SaveChanges();

            return(Map <RouteViewModel>(dataRoute));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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);
        }
コード例 #4
0
 public IHttpActionResult UpdateRoute(int id, UpdateRouteModel route)
 {
     return(Ok(_service.UpdateRoute(id, route)));
 }
コード例 #5
0
 public IHttpActionResult AddRoute(UpdateRouteModel route)
 {
     return(Ok(_service.AddRoute(route)));
 }