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)); }
public IHttpActionResult GetTripComment(int id) { TripComment tripComment = db.TripComments.Find(id); if (tripComment == null) { return(NotFound()); } return(Ok(tripComment)); }
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 DeleteTripComment(int id) { TripComment tripComment = db.TripComments.Find(id); if (tripComment == null) { return(NotFound()); } db.TripComments.Remove(tripComment); db.SaveChanges(); return(Ok(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 BaseResponseAjaxModel AddComment(int tripId, string userId, string commentText) { var response = new BaseResponseAjaxModel(); if (commentText.Length < ModelConstants.CommentTextMinLength || commentText.Length > ModelConstants.CommentTextMaxLength) { response.ErrorMessage = string.Format("Comment text should be between {0} and {1} symbols long", ModelConstants.CommentTextMinLength, ModelConstants.CommentTextMaxLength); return response; } var dbTrip = this.GetById(tripId); if (dbTrip == null) { response.ErrorMessage = "No such trip"; return response; } TripComment comment = new TripComment() { TripId = tripId, AuthorId = userId, Text = commentText }; dbTrip.Comments.Add(comment); this.tripRepos.Save(); this.tripRepos.Reload(dbTrip); var author = this.userServices.GetById(userId); response.Status = true; response.Data = new CommentResponseModel() { FirstName = author.FirstName, LastName = author.LastName, UserUrl = ServicesDataProvider.GetProfileUrl(author.UserName, author.FirstName, author.LastName), UserImageSrc = ServicesDataProvider.GetUserImageSmallUrl(author.Avatar.FileName), CreatedOnFormatted = comment.CreatedOn.ToString("dd.MM.yyyy HH:mm"), CommentText = comment.Text, CommentTotalCount = dbTrip.Comments.Count }; return response; }