public IHttpActionResult PostTrip(Trip trip) { if (!ModelState.IsValid) { return BadRequest(ModelState); } trip.Users = new List<TripUser>(); trip.Status = TripStatus.Open; trip.Code = GetCode(8); TripUser userCreator = new TripUser(); userCreator.IsCreator = true; userCreator.TripId = trip.Id; userCreator.DisplayName = trip.MyName; userCreator.TripCode = GetCode(5); userCreator.TripStatus = TripUserStatus.Yes; trip.Users.Add(userCreator); var userJson = JsonConvert.DeserializeObject<Users>(trip.UserJson); foreach(TripUser user in userJson.users) { user.TripStatus = TripUserStatus.Pending; user.TripCode = GetCode(5); user.IsCreator = false; trip.Users.Add(user); } db.Trips.Add(trip); db.SaveChanges(); var website = "teambitewolf.azurewebsites.net/Detail/"; // send out text invite var smsMessage1 = String.Format("Let's Tripsie! {0} send you an invite for a Trip to {1}", trip.MyName, trip.Destination); var smsMessage2 = "Visit " + Common.WebsiteDomain + "/Detail/{0} or download the Tripsie app for Android to get started!"; foreach (var tu in trip.Users) { if (tu.Phone != null) { // @TODO don't send second message until first one complete Common.SendSms(tu.Phone, smsMessage1); Common.SendSms(tu.Phone, string.Format(smsMessage2, tu.TripCode)); } } return CreatedAtRoute("DefaultApi", new { id = trip.Id }, trip); }
public IHttpActionResult PutTrip(int id, Trip trip) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != trip.Id) { return BadRequest(); } db.Entry(trip).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!TripExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }