async Task notifyAllInvolvedAthletes(int myAthleteID, NewsfeedItemTypeEnum objectType, int objectID, int commentID, string commentText) { try { var myAthlete = db.Athletes.Where(i => i.AthleteID == myAthleteID).Single(); // list of athletes involved var item = this.GetNewsfeedItem(myAthleteID, objectType, objectID); if (item == null) { return; } var comments = this.GetComments(objectType, objectID); List <int> athleteIDs = new List <int>(); athleteIDs.Add(item.AthleteID); if (athleteIDs.Contains(item.Athlete2ID) == false) { athleteIDs.Add(item.Athlete2ID); } foreach (var comment in comments) { if (athleteIDs.Contains(comment.AthleteID) == false) { athleteIDs.Add(comment.AthleteID); } } athleteIDs.Remove(0); athleteIDs.Remove(myAthleteID); foreach (int athleteID in athleteIDs) { try { var athlete = db.Athletes.Where(i => i.AthleteID == athleteID).Single(); // send push notification new PushNotificationsLogic(db).SendNotification(athleteID, PushNotificationMessage.BuildComment(myAthlete, commentText, commentID)); // email string subject = "'Byb' - " + athlete.Name + " commented on a tracked conversation"; string link1 = new DeepLinkHelper().BuildOpenBybLink_Comment(commentID); string link2 = new DeepLinkHelper().BuildLinkToComment(commentID); string html = string.Format(htmlMessage_Post, myAthlete.NameOrUserName, commentText, link1, link2); await new EmailService().SendEmailToAthlete(athlete, subject, html); } catch (Exception) { } } PushNotificationProcessor.TheProcessor.PushAllPendingNotifications(); } catch (Exception) { } }
public void SetLike(int athleteID, NewsfeedItemTypeEnum objectType, int objectID, bool like) { var athlete = db.Athletes.Where(i => i.AthleteID == athleteID).Single(); var comment = new Comment() { AthleteID = athleteID, ObjectType = (int)objectType, CommentText = null, CommentType = (int)CommentTypeEnum.Like, Time = DateTime.UtcNow, }; switch (objectType) { case NewsfeedItemTypeEnum.Post: comment.PostID = objectID; break; case NewsfeedItemTypeEnum.Result: comment.ResultID = objectID; break; case NewsfeedItemTypeEnum.Score: comment.ScoreID = objectID; break; case NewsfeedItemTypeEnum.GameHost: comment.GameHostID = objectID; break; case NewsfeedItemTypeEnum.NewUser: comment.NewUserID = objectID; break; default: throw new NotImplementedException("unknown objectType"); } var existingComment = (from c in db.Comments where c.ObjectType == comment.ObjectType where c.AthleteID == comment.AthleteID where c.PostID == comment.PostID where c.ResultID == comment.ResultID where c.ScoreID == comment.ScoreID where c.GameHostID == comment.GameHostID where c.NewUserID == comment.NewUserID where c.CommentType == comment.CommentType select c).FirstOrDefault(); if (existingComment != null) { db.Comments.Remove(existingComment); } if (like) { db.Comments.Add(comment); } db.SaveChanges(); }
public async Task <int> MakeComment(int athleteID, NewsfeedItemTypeEnum objectType, int objectID, string text, bool notifyAll) { var athlete = db.Athletes.Where(i => i.AthleteID == athleteID).Single(); // save the comment var comment = new Comment() { AthleteID = athleteID, ObjectType = (int)objectType, CommentText = text, Time = DateTime.UtcNow, CommentType = (int)CommentTypeEnum.Comment }; switch (objectType) { case NewsfeedItemTypeEnum.Post: comment.PostID = objectID; break; case NewsfeedItemTypeEnum.Result: comment.ResultID = objectID; break; case NewsfeedItemTypeEnum.Score: comment.ScoreID = objectID; break; case NewsfeedItemTypeEnum.GameHost: comment.GameHostID = objectID; break; case NewsfeedItemTypeEnum.NewUser: comment.NewUserID = objectID; break; default: throw new NotImplementedException("unknown objectType"); } db.Comments.Add(comment); db.SaveChanges(); if (notifyAll) { if (objectType == NewsfeedItemTypeEnum.GameHost) { await this.notifyAllAttendees(objectID, athlete, text); } else { await this.notifyAllInvolvedAthletes(athleteID, objectType, objectID, comment.CommentID, text); } } return(comment.CommentID); }
public List <CommentWebModel> GetComments(NewsfeedItemTypeEnum objectType, int objectID) { int?postID = null; int?resultID = null; int?scoreID = null; int?gameHostID = null; int?newUserID = null; switch (objectType) { case NewsfeedItemTypeEnum.Post: postID = objectID; break; case NewsfeedItemTypeEnum.Result: resultID = objectID; break; case NewsfeedItemTypeEnum.Score: scoreID = objectID; break; case NewsfeedItemTypeEnum.GameHost: gameHostID = objectID; break; case NewsfeedItemTypeEnum.NewUser: newUserID = objectID; break; default: throw new NotImplementedException("unknown objectType"); } var comments = (from i in db.Comments where i.CommentType == (int)CommentTypeEnum.Comment where i.ObjectType == (int)objectType where i.PostID == postID where i.ResultID == resultID where i.ScoreID == scoreID where i.GameHostID == gameHostID where i.NewUserID == newUserID orderby i.Time descending select new CommentWebModel() { ID = i.CommentID, AthleteID = i.AthleteID, AthleteName = i.Athlete.Name, AthletePicture = i.Athlete.Picture, Text = i.CommentText, Time = i.Time, }).ToList(); return(comments); }
public async Task <List <CommentWebModel> > GetComments(NewsfeedItemTypeEnum objectType, int objectID) { string url = WebApiUrl + "Newsfeed/Comments?objectType=" + ((int)objectType).ToString() + "&objectID=" + objectID; try { string json = await this.sendGetRequestAndReceiveResponse(url, true); List <CommentWebModel> comments = JsonConvert.DeserializeObject <List <CommentWebModel> >(json); foreach (var item in comments) { item.Time = System.TimeZone.CurrentTimeZone.ToLocalTime(item.Time); } return(comments); } catch (Exception exc) { LastExceptionUrl = url; LastException = exc; return(null); } }
public NewsfeedItemWebModel GetNewsfeedItem(int myAthleteID, NewsfeedItemTypeEnum objectType, int objectID) { List <NewsfeedItemWebModel> items = null; switch (objectType) { case NewsfeedItemTypeEnum.Post: items = this.getPosts(myAthleteID, db.Posts.Where(i => i.PostID == objectID)).ToList(); break; case NewsfeedItemTypeEnum.Result: items = this.getResults(myAthleteID, db.Results.Where(i => i.ResultID == objectID)).ToList(); break; case NewsfeedItemTypeEnum.Score: items = this.getScores(myAthleteID, db.Scores.Where(i => i.ScoreID == objectID)).ToList(); break; case NewsfeedItemTypeEnum.GameHost: items = this.getGameHosts(myAthleteID, db.GameHosts.Where(i => i.GameHostID == objectID)).ToList(); break; case NewsfeedItemTypeEnum.NewUser: items = this.getNewUsers(myAthleteID, db.Athletes.Where(i => i.AthleteID == objectID)).ToList(); break; } if (items == null || items.Count != 1) { return(null); } return(items[0]); }
public async Task <bool> SetLike(NewsfeedItemTypeEnum objectType, int objectID, bool like) { string url = WebApiUrl + "Newsfeed/SetLike"; try { SetLikeWebModel model = new SetLikeWebModel() { ObjectType = objectType, ObjectID = objectID, Like = like }; string json = await this.sendPostRequestAndReceiveResponse(url, model, true); return(true); } catch (Exception exc) { LastExceptionUrl = url; LastException = exc; return(false); } }
public async Task <int?> MakeComment(NewsfeedItemTypeEnum objectType, int objectID, string text) { string url = WebApiUrl + "Newsfeed/MakeComment"; try { NewCommentWebModel model = new NewCommentWebModel() { ObjectType = objectType, ObjectID = objectID, Text = text }; string json = await this.sendPostRequestAndReceiveResponse(url, model, true); int modelResponse = JsonConvert.DeserializeObject <int>(json); return(modelResponse); } catch (Exception exc) { LastExceptionUrl = url; LastException = exc; return(null); } }