Beispiel #1
0
 public ActionResult Create()
 {
     using (OnixEntities1 ctx = new OnixEntities1())
     {
         String jsonData = new StreamReader(this.Request.InputStream).ReadToEnd();
         var trip = Newtonsoft.Json.JsonConvert.DeserializeObject<Trip>(jsonData);
         ctx.TripSet.Add(trip);
         var c = User.Identity.GetUserId();
         trip.User_Id = c;
         ctx.SaveChanges();
     }
     return Content("");
 }
Beispiel #2
0
 // GET: Trip
 public ActionResult Index()
 {
     using (OnixEntities1 ctx = new OnixEntities1())
     {
         var userId = User.Identity.GetUserId();
         var trips = from t in ctx.TripSet
                     where t.User_Id == userId
                     select t;
         var t3 = new List<Trip>();
         foreach(Trip t2 in trips)
         {
             t3.Add(t2);
         }
         string JsonData = Newtonsoft.Json.JsonConvert.SerializeObject(t3, Newtonsoft.Json.Formatting.Indented, new Newtonsoft.Json.JsonSerializerSettings
         {
             ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
         });
         return Content(JsonData);
     }
 }