Example #1
0
        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)
            {
            }
        }
Example #2
0
        async Task notifyAllAttendees(int gameHostID, Athlete myAthlete, string commentText)
        {
            try
            {
                var gameHost = db.GameHosts.Where(i => i.GameHostID == gameHostID).Single();
                var venue    = db.Venues.Where(i => i.VenueID == gameHost.VenueID).Single();

                // list of attendees and people that commented
                var athleteIDs = gameHost.GameHostInvites.Where(i => i.IsDeniedByInvitee == false).Select(i => i.AthleteID).ToList();
                if (athleteIDs.Contains(gameHost.AthleteID) == false)
                {
                    athleteIDs.Add(gameHost.AthleteID);
                }
                var commentAthleteIDs = gameHost.Comments.Select(i => i.AthleteID).ToList();
                foreach (int id in commentAthleteIDs)
                {
                    if (athleteIDs.Contains(id) == false)
                    {
                        athleteIDs.Add(id);
                    }
                }
                athleteIDs.Remove(0);
                athleteIDs.Remove(myAthlete.AthleteID);

                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.BuildGameCommentMessage(myAthlete, commentText, gameHostID));

                        // send email
                        string when    = gameHost.When_InLocalTimeZone.ToLongDateString() + " - " + gameHost.When_InLocalTimeZone.ToShortTimeString();
                        string subject = "'Byb' - " + myAthlete.Name + " commented on an invite";
                        string link1   = new DeepLinkHelper().BuildOpenBybLink_GameHost(gameHost.GameHostID);
                        string link2   = new DeepLinkHelper().BuildLinkToGameHost(gameHost.GameHostID);
                        string html    = string.Format(htmlComment_GameHost, myAthlete.Name, gameHost.When_InLocalTimeZone, venue.Name, commentText, link1, link2);
                        await new EmailService().SendEmailToAthlete(athlete, subject, html);
                    }
                    catch (Exception)
                    {
                    }
                }

                PushNotificationProcessor.TheProcessor.PushAllPendingNotifications();
            }
            catch (Exception)
            {
            }
        }