Beispiel #1
0
        public void StatusPostComment(string currentUserUserName, long streamId, string statusCommentMessage)
        {
            // Below we
            // 1. Notify the stream creator of the comment
            // 2. Notify those that have commented already on the stream (exclude the current comment submitter)

            //Grab the UserId of the stream creator
            var stream = new StreamRepository().GetStream(streamId);

            // Get the stream owner firstname & email address
            string statusOwnerFirstName    = UserHelpers.GetFirstName(stream.StreamCreatorUserId);
            string statusOwnerEmailAddress = UserHelpers.GetUserEmailAddress(stream.StreamCreatorUserId);

            // Get a list of users who have commented on this status
            var commentatorsAdresses = new StreamCommentRepository().GetStatusCommentatorsEmailAddresses(streamId);

            // remove the current user from the list of commentatos since notifiying him would be redundant
            commentatorsAdresses.Remove(currentUserUserName); //FYI: EmailAddress is reused as the username in this app.

            string commenterFirstName = UserHelpers.GetFirstName(currentUserUserName);

            // Compose email
            string applicationUrl = GetCustomApplicationUrl(true, true, true, "");

            string emailMsg = ReadTemplateFile("~/Content/Templates/StatusPostComment.htm");

            emailMsg = emailMsg.Replace("{StatusCommenterFirstName}", commenterFirstName);
            emailMsg = emailMsg.Replace("{StatusMessage}", statusCommentMessage);
            emailMsg = emailMsg.Replace("{StreamId}", streamId.ToString());
            emailMsg = emailMsg.Replace("{ApplicationUrl}", applicationUrl);

            MailMessage message = new MailMessage();

            message.From = new MailAddress(NotificationEmailAddressFrom, "Make progress every day");

            foreach (string emailAddress in commentatorsAdresses)
            {
                message.To.Add(emailAddress);
            }

            message.Subject      = commenterFirstName + "- commented on status";
            message.Body         = emailMsg;
            message.BodyEncoding = Encoding.UTF8;
            message.IsBodyHtml   = true;

            SendEmail(message);
        }