Esempio n. 1
0
        //добавление маршрута пользователю
        public ActionResult Create(int id)
        {
            Users_Trips user_trip = new Users_Trips();

            user_trip.Trip = db.Trips.Find(id);
            string userId = User.Identity.GetUserId();

            user_trip.AspNetUser = db.AspNetUsers.Where(u => u.Id == userId).FirstOrDefault();
            user_trip.Author     = false;

            if (ModelState.IsValid)
            {
                db.Users_Trips.Add(user_trip);
                db.SaveChanges();
            }

            return(RedirectToAction("Details", "Route", new { id = id }));
        }
Esempio n. 2
0
        public ActionResult Create(RequestTrip req)
        {
            int numOfNodes = 0;

            Trip trip = new Trip();

            trip.Name         = req.Name;
            trip.Duration     = Convert.ToInt32(req.Duration);
            trip.PhotoUrl     = req.PhotoUrl;
            trip.CreationDate = DateTime.Now;
            foreach (StringPoint[] route in req.Routes)
            {
                numOfNodes += route.Length;
            }
            trip.NumOfNodes = numOfNodes;

            if (ModelState.IsValid)
            {
                db.Trips.Add(trip);
                db.SaveChanges();

                Users_Trips ut     = new Users_Trips();
                string      userId = User.Identity.GetUserId();
                ut.AspNetUser = db.AspNetUsers.Where(u => u.Id == userId).FirstOrDefault();
                ut.Trip       = trip;
                ut.Author     = true;
                if (ModelState.IsValid)
                {
                    db.Users_Trips.Add(ut);
                    db.SaveChanges();
                }

                CreateRoutesAndNodes(req, trip);
            }

            return(Json(trip.TripId, JsonRequestBehavior.AllowGet));
        }
Esempio n. 3
0
 public void Save()
 {
     db.SaveChanges();
 }