Esempio n. 1
0
 public ActionResult MarkCommentHelpful(int commentId, string returnUrl)
 {
     try
     {
         int count = Db.HelpfulMarkGivenEvents
                     .Where(c => c.EventLog.SenderId == CurrentUser.Id)
                     .Where(c => c.LogCommentEventId == commentId)
                     .Count();
         if (count == 0)
         {
             LogCommentEvent comment = Db.LogCommentEvents.Where(c => c.Id == commentId).FirstOrDefault();
             if (commentId != 0)
             {
                 HelpfulMarkGivenEvent help = new HelpfulMarkGivenEvent()
                 {
                     LogCommentEventId = commentId
                 };
                 OsbideWebService client = new OsbideWebService();
                 Authentication   auth   = new Authentication();
                 string           key    = auth.GetAuthenticationKey();
                 EventLog         log    = new EventLog(help, CurrentUser);
                 client.SubmitLog(log, CurrentUser);
             }
         }
     }
     catch (Exception ex)
     {
         LogErrorMessage(ex);
     }
     Response.Redirect(returnUrl);
     return(View());
 }
Esempio n. 2
0
        public ActionResult PostFeedComment(FormCollection formCollection)
        {
            try
            {
                var comment = formCollection["comment"];
                if (string.IsNullOrWhiteSpace(comment))
                {
                    return(RedirectToAction("Index"));
                }

                comment = comment.TrimStart(',');
                OsbideWebService client = new OsbideWebService();
                Authentication   auth   = new Authentication();
                string           key    = auth.GetAuthenticationKey();
                if (string.IsNullOrEmpty(comment) == false)
                {
                    EventLog log = new EventLog();
                    log.SenderId = CurrentUser.Id;
                    log.LogType  = FeedPostEvent.Name;
                    FeedPostEvent commentEvent = new FeedPostEvent();
                    commentEvent.Comment = comment;
                    log.Data.BinaryData  = EventFactory.ToZippedBinary(commentEvent);
                    log = client.SubmitLog(log, CurrentUser);

                    //find all of this user's subscribers and send them an email
                    List <OsbideUser> observers = new List <OsbideUser>();

                    observers = (from subscription in Db.UserSubscriptions
                                 join user in Db.Users on
                                 new { InstitutionId = subscription.ObserverInstitutionId, SchoolId = subscription.ObserverSchoolId }
                                 equals new { InstitutionId = user.InstitutionId, SchoolId = user.SchoolId }
                                 where subscription.SubjectSchoolId == CurrentUser.SchoolId &&
                                 subscription.SubjectInstitutionId == CurrentUser.InstitutionId &&
                                 user.ReceiveEmailOnNewFeedPost == true
                                 select user).ToList();
                    if (observers.Count > 0)
                    {
                        string url  = StringConstants.GetActivityFeedDetailsUrl(log.Id);
                        string body = "Greetings,<br />{0} posted a new item to the activity feed:<br />\"{1}\"<br />To view this "
                                      + "conversation online, please visit {2} or visit your OSBIDE user profile.<br /><br />Thanks,\nOSBIDE<br /><br />"
                                      + "These automated messages can be turned off by editing your user profile.";
                        body = string.Format(body, CurrentUser.FirstAndLastName, comment, url);
                        List <MailAddress> to = new List <MailAddress>();
                        foreach (OsbideUser user in observers)
                        {
                            to.Add(new MailAddress(user.Email));
                        }
                        Email.Send("[OSBIDE] New Activity Post", body, to);
                    }
                }
            }
            catch (Exception ex)
            {
                LogErrorMessage(ex);
            }

            return(RedirectToAction("Index"));
        }
Esempio n. 3
0
        /// <summary>
        /// Helper method for posting a comment.  Will return true if everything went OK, false otherwise
        /// </summary>
        /// <param name="logId"></param>
        /// <param name="comment"></param>
        /// <returns></returns>
        protected bool PostComment(string logId, string comment)
        {
            int id = -1;

            if (Int32.TryParse(logId, out id) == true)
            {
                //comments made on comments or mark helpful events need to be routed back to the original source
                IOsbideEvent checkEvent = Db.LogCommentEvents.Where(l => l.EventLogId == id).FirstOrDefault();
                if (checkEvent != null)
                {
                    id = (checkEvent as LogCommentEvent).SourceEventLogId;
                }
                else
                {
                    checkEvent = Db.HelpfulMarkGivenEvents.Where(l => l.EventLogId == id).FirstOrDefault();
                    if (checkEvent != null)
                    {
                        id = (checkEvent as HelpfulMarkGivenEvent).LogCommentEvent.SourceEventLogId;
                    }
                }

                LogCommentEvent logComment = new LogCommentEvent()
                {
                    Content          = comment,
                    SourceEventLogId = id,
                    SolutionName     = "OSBIDE"
                };
                OsbideWebService client = new OsbideWebService();
                Authentication   auth   = new Authentication();
                string           key    = auth.GetAuthenticationKey();
                EventLog         log    = null;
                if (string.IsNullOrEmpty(comment) == false)
                {
                    log = new EventLog(logComment, CurrentUser);
                    log = client.SubmitLog(log, CurrentUser);
                }
                else
                {
                    return(false);
                }
                logComment = Db.LogCommentEvents.Where(l => l.EventLogId == log.Id).FirstOrDefault();

                //the code below performs two functions:
                // 1. Send interested parties email notifications
                // 2. Log the comment in the social activity log (displayed on an individual's profile page)

                //find others that have posted on this same thread
                List <OsbideUser> interestedParties = Db.LogCommentEvents
                                                      .Where(l => l.SourceEventLogId == id)
                                                      .Where(l => l.EventLog.SenderId != CurrentUser.Id)
                                                      .Select(l => l.EventLog.Sender)
                                                      .ToList();

                //(email only) find those that are subscribed to this thread
                List <OsbideUser> subscribers = (from logSub in Db.EventLogSubscriptions
                                                 join user in Db.Users on logSub.UserId equals user.Id
                                                 where logSub.LogId == id &&
                                                 logSub.UserId != CurrentUser.Id &&
                                                 user.ReceiveNotificationEmails == true
                                                 select user).ToList();

                //check to see if the author wants to be notified of posts
                OsbideUser eventAuthor = Db.EventLogs.Where(l => l.Id == id).Select(l => l.Sender).FirstOrDefault();

                //master list shared between email and social activity log
                Dictionary <int, OsbideUser> masterList = new Dictionary <int, OsbideUser>();
                if (eventAuthor != null)
                {
                    masterList.Add(eventAuthor.Id, eventAuthor);
                }
                foreach (OsbideUser user in interestedParties)
                {
                    if (masterList.ContainsKey(user.Id) == false)
                    {
                        masterList.Add(user.Id, user);
                    }
                }

                //add the current user for activity log tracking, but not for emails
                OsbideUser creator = new OsbideUser(CurrentUser);
                creator.ReceiveNotificationEmails = false;  //force no email send on the current user
                if (masterList.ContainsKey(creator.Id) == true)
                {
                    masterList.Remove(creator.Id);
                }
                masterList.Add(creator.Id, creator);

                //update social activity
                foreach (OsbideUser user in masterList.Values)
                {
                    CommentActivityLog social = new CommentActivityLog()
                    {
                        TargetUserId      = user.Id,
                        LogCommentEventId = logComment.Id
                    };
                    Db.CommentActivityLogs.Add(social);
                }
                Db.SaveChanges();

                //form the email list
                SortedDictionary <int, OsbideUser> emailList = new SortedDictionary <int, OsbideUser>();

                //add in interested parties from our master list
                foreach (OsbideUser user in masterList.Values)
                {
                    if (user.ReceiveNotificationEmails == true)
                    {
                        if (emailList.ContainsKey(user.Id) == false)
                        {
                            emailList.Add(user.Id, user);
                        }
                    }
                }

                //add in subscribers to email list
                foreach (OsbideUser user in subscribers)
                {
                    if (emailList.ContainsKey(user.Id) == false)
                    {
                        emailList.Add(user.Id, user);
                    }
                }

                //send emails
                if (emailList.Count > 0)
                {
                    //send email
                    string url  = StringConstants.GetActivityFeedDetailsUrl(id);
                    string body = "Greetings,<br />{0} has commented on a post that you have previously been involved with:<br />\"{1}\"<br />To view this "
                                  + "conversation online, please visit {2} or visit your OSBIDE user profile.<br /><br />Thanks,<br />OSBIDE<br /><br />"
                                  + "These automated messages can be turned off by editing your user profile.";
                    body = string.Format(body, logComment.EventLog.Sender.FirstAndLastName, logComment.Content, url);
                    List <MailAddress> to = new List <MailAddress>();
                    foreach (OsbideUser user in emailList.Values)
                    {
                        to.Add(new MailAddress(user.Email));
                    }
                    Email.Send("[OSBIDE] Activity Notification", body, to);
                }
            }
            return(true);
        }