Example #1
0
 /// <summary>
 /// Notify the moderators and owners about the an offensive community/content.
 /// </summary>
 /// <param name="notification">Offensive entity details</param>
 public void NotifyFlagged(FlaggedRequest notification)
 {
     SendMail(notification);
 }
        public static EmailRequest UpdateFrom(this EmailRequest thisObject, FlaggedRequest request)
        {
            if (thisObject == null)
            {
                thisObject = new EmailRequest();
            }

            ICommunityRepository communityRepository = DependencyResolver.Current.GetService(typeof(ICommunityRepository)) as ICommunityRepository;
            IContentRepository contentRepository = DependencyResolver.Current.GetService(typeof(IContentRepository)) as IContentRepository;

            IEnumerable<User> approvers = new List<User>();

            string entityName = string.Empty;
            if (request.EntityType == EntityType.Content)
            {
                Content content = contentRepository.GetItem(c => c.ContentID == request.ID);
                if (content != null)
                {
                    if (content.CommunityContents.Count > 0)
                    {
                        approvers = communityRepository.GetApprovers(Enumerable.ElementAt<CommunityContents>(content.CommunityContents, 0).CommunityID);
                    }

                    approvers.Concat(new[] { content.User });
                    entityName = content.Title;
                }
            }
            else
            {
                approvers = communityRepository.GetApprovers(request.ID);
                Community community = communityRepository.GetItem(c => c.CommunityID == request.ID);
                if (community != null)
                {
                    entityName = community.Name;
                }
            }

            foreach (User user in approvers)
            {
                if (user.IsSubscribed)
                {
                    thisObject.Recipients.Add(new MailAddress(user.Email.FixEmailAddress(), user.FirstName + " " + user.LastName));
                }
            }

            IUserRepository userRepository = DependencyResolver.Current.GetService(typeof(IUserRepository)) as IUserRepository;
            User requestor = userRepository.GetItem(u => u.UserID == request.UserID);

            thisObject.IsHtml = true;

            // Update the body and the subject.
            thisObject.Subject = string.Format(CultureInfo.CurrentUICulture, "The Layerscape {0} \"{1}\" has been flagged by a user", request.EntityType.ToString().ToLower(), entityName);

            var replacements = new Dictionary<string, string>
            {
                { "@@ApproverName@@", string.Empty }, 
                { "@@Type@@", HttpUtility.UrlDecode(request.EntityType.ToString().ToLower()) },
                { "@@Name@@", HttpUtility.UrlDecode(entityName) }, 
                { "@@Link@@", HttpUtility.UrlDecode(request.Link) },
                { "@@UserName@@", HttpUtility.UrlDecode(requestor.GetFullName()) },
                { "@@UserLink@@", HttpUtility.UrlDecode(request.UserLink) },
                { "@@FlaggedOn@@", HttpUtility.UrlDecode(request.FlaggedOn.ToString()) },
                { "@@FlaggedAs@@", HttpUtility.UrlDecode(request.FlaggedAs) },
                { "@@UserComments@@", HttpUtility.UrlDecode(request.UserComments) },
            };
            thisObject.MessageBody = FormatMailBodyUsingTemplate("flaggedrequest.html", replacements);

            return thisObject;
        }
Example #3
0
        private void SendOffensiveEntityMail(ReportEntityDetails details, EntityType entityType)
        {
            //// TODO: Need to send mail asynchronously. 

            try
            {
                // Send Mail.
                var request = new FlaggedRequest()
                {
                    ID = details.ReportEntityID,
                    EntityType = entityType,
                    ParentID = details.ParentID,
                    UserComments = details.Comment,
                    FlaggedOn = DateTime.UtcNow,
                    FlaggedAs = details.ReportEntityType.ToString(),
                    UserID = details.ReportedByID,
                    UserName = details.ReportedBy,
                    UserLink = string.Format(CultureInfo.InvariantCulture, "{0}Profile/Index/{1}", HttpContext.Request.Url.GetServerLink(), details.ReportedByID),
                };

                switch (entityType)
                {
                    case EntityType.Community:
                    case EntityType.Folder:
                        request.Link = string.Format(CultureInfo.InvariantCulture, "{0}Community/Index/{1}", HttpContext.Request.Url.GetServerLink(), details.ReportEntityID);
                        break;
                    default:
                        request.Link = string.Format(CultureInfo.InvariantCulture, "{0}{1}/Index/{2}", HttpContext.Request.Url.GetServerLink(), entityType.ToString(), details.ReportEntityID);
                        break;
                }

                _notificationService.NotifyFlagged(request);
            }
            catch (Exception)
            {
                // Ignore all exceptions.
            }
        }