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.
            }
        }
        public static EmailRequest UpdateFrom(this EmailRequest thisObject, object request)
        {
            //// TODO: Need to Get the Email request from the content of the message.
            //// TODO: Also we need to write a static methods for converting from the input request to the Email Request.

            if (thisObject == null)
            {
                thisObject = new EmailRequest();
            }

            JoinCommunityRequest joinRequest = request as JoinCommunityRequest;

            if (joinRequest != null)
            {
                return(thisObject.UpdateFrom(joinRequest));
            }

            FlaggedRequest flaggedRequest = request as FlaggedRequest;

            if (flaggedRequest != null)
            {
                return(thisObject.UpdateFrom(flaggedRequest));
            }

            EntityCommentRequest entityCommentRequest = request as EntityCommentRequest;

            if (entityCommentRequest != null)
            {
                return(thisObject.UpdateFrom(entityCommentRequest));
            }

            ModeratorPermissionStatusRequest moderatorPermissionStatusRequest = request as ModeratorPermissionStatusRequest;

            if (moderatorPermissionStatusRequest != null)
            {
                return(thisObject.UpdateFrom(moderatorPermissionStatusRequest));
            }

            UserPermissionStatusRequest userPermissionStatusRequest = request as UserPermissionStatusRequest;

            if (userPermissionStatusRequest != null)
            {
                return(thisObject.UpdateFrom(userPermissionStatusRequest));
            }

            RemoveUserRequest removeUserRequest = request as RemoveUserRequest;

            if (removeUserRequest != null)
            {
                return(thisObject.UpdateFrom(removeUserRequest));
            }

            UserPermissionChangedRequest userPermissionChangedRequest = request as UserPermissionChangedRequest;

            if (userPermissionChangedRequest != null)
            {
                return(thisObject.UpdateFrom(userPermissionChangedRequest));
            }

            NotifyInviteRequest notifyInviteRequest = request as NotifyInviteRequest;

            if (notifyInviteRequest != null)
            {
                return(thisObject.UpdateFrom(notifyInviteRequest));
            }

            EntityAdminActionRequest entityAdminDeleteRequest = request as EntityAdminActionRequest;

            if (entityAdminDeleteRequest != null)
            {
                return(thisObject.UpdateFrom(entityAdminDeleteRequest));
            }

            NewEntityRequest newEntityRequest = request as NewEntityRequest;

            if (newEntityRequest != null)
            {
                return(thisObject.UpdateFrom(newEntityRequest));
            }

            return(null);
        }
        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);
        }
 /// <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);
 }