public IHttpActionResult PostTripComment(TripComment tripComment)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            tripComment.Date = DateTime.UtcNow;

            db.TripComments.Add(tripComment);
            db.SaveChanges();

            var tripUser = db.TripUsers.First(r=> r.Id == tripComment.TripUserId);

            var userIds = db.Trips.Include("Users").FirstOrDefault(r => r.Id == tripUser.TripId).Users.Select(r=>r.Id);

            var notifyIds = db.PushRegistrations.Where(r =>userIds.Contains(r.TripUserId)).Select(r => r.RegistrationId);

            foreach (string notifyId in notifyIds)
            {
                var unused = Common.SendGms(notifyId, tripUser.Id.ToString(), tripUser.TripId.ToString(), tripUser.DisplayName + " posted a comment!", tripComment.Comment,
                    "comments",  tripUser.Trip.Code, tripUser.TripCode, tripUser.DisplayName, tripUser.Trip.Destination);
            }

            foreach (var tu in db.TripUsers.Where(r => r.TripId == tripUser.TripId))
            {
                var message = tripUser.DisplayName + " posted a new ";

                if (tripComment.TripActivityId != null && tripComment.TripActivityId > 0)
                {
                    message += "Activity Comment for your trip to " + tripUser.Trip.Destination + "!";
                    message += "\ntripsieappweb.azurewebsites.net/Trip/ActivityDetails/" + tripComment.TripActivityId + "/?code=" + tu.TripCode;
                }

                else
                {
                    message += "Comment for your trip to " + tripUser.Trip.Destination + "!";
                    message += "\ntripsieappweb.azurewebsites.net/Trip/Comments/" + tu.TripCode;
                }

                // @TODO: check sms setting or if notified via android

                if (tu.Phone != null)
                {
                    Common.SendSms(tu.Phone, message);
                }
            }

            return CreatedAtRoute("DefaultApi", new { id = tripComment.Id }, tripComment);
        }
        public IHttpActionResult UpdateTripUserResponse(string id, bool response, string comment)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            TripUser tripUser = db.TripUsers.Include("Trip").FirstOrDefault(r => r.TripCode == id);

            if (tripUser == null)
            {
                return BadRequest();
            }

            tripUser.TripStatus = response == true ? TripUserStatus.Yes : TripUserStatus.No;

            db.Entry(tripUser).State = EntityState.Modified;

            TripComment tripComment = new TripComment();
            tripComment.Date = DateTime.Now.ToUniversalTime();

            String notificationText = tripUser.DisplayName + " is ";

            if(response)
            {
                tripComment.Comment = "I'm IN!";
                notificationText += "IN for ";
            }

            else
            {
                tripComment.Comment = "I'm OUT.";
                notificationText += "OUT of ";
            }

            TripComment responseComment = null;

            if(!String.IsNullOrEmpty(comment) && comment != "-1111")
            {
                responseComment = new TripComment();

                responseComment.Comment = comment;
                responseComment.Date = DateTime.UtcNow;
            }

            notificationText += "the trip to " + tripUser.Trip.Destination;

            tripUser.TripComments = new List<TripComment>();
            tripUser.TripComments.Add(tripComment);

            if(responseComment != null)
            {
                tripUser.TripComments.Add(responseComment);
            }

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TripUserExists(tripUser.Id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            var tripUsers = tripUser.Trip.Users.Select(r => r.Id);

            var notifyIds = db.PushRegistrations.Where(r => tripUsers.Contains(r.TripUserId)).Select(r => r.RegistrationId);

            foreach (string notifyId in notifyIds)
            {
               var unused = Common.SendGms(notifyId, tripUser.Id.ToString(), tripUser.TripId.ToString(), "Tripsie Update!", notificationText, "details", tripUser.Trip.Code, tripUser.TripCode);
            }

            return StatusCode(HttpStatusCode.OK);
        }
        public IHttpActionResult PutTripComment(int id, TripComment tripComment)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != tripComment.Id)
            {
                return BadRequest();
            }

            db.Entry(tripComment).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TripCommentExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }