示例#1
0
        private void SendProcessingStatusMail(PermissionItem permission)
        {
            try
            {
                // Send Mail for moderators.
                var moderatorPermissionStatusRequest = new ModeratorPermissionStatusRequest();
                moderatorPermissionStatusRequest.CommunityID   = permission.CommunityID;
                moderatorPermissionStatusRequest.CommunityName = permission.CommunityName;
                moderatorPermissionStatusRequest.RequestorID   = permission.UserID;
                moderatorPermissionStatusRequest.RequestorName = permission.Name;
                moderatorPermissionStatusRequest.ApprovedRole  = permission.Role;
                moderatorPermissionStatusRequest.IsApproved    = permission.Approved == true;
                moderatorPermissionStatusRequest.RequestorLink = string.Format(CultureInfo.InvariantCulture, "{0}Profile/Index/{1}", HttpContext.Request.Url.GetServerLink(), permission.UserID);
                moderatorPermissionStatusRequest.CommunityLink = string.Format(CultureInfo.InvariantCulture, "{0}Community/Index/{1}", HttpContext.Request.Url.GetServerLink(), permission.CommunityID);

                _notificationService.NotifyModeratorPermissionStatus(moderatorPermissionStatusRequest);

                // Send Mail for moderators.
                var request = new UserPermissionStatusRequest();
                request.CommunityID   = permission.CommunityID;
                request.CommunityName = permission.CommunityName;
                request.RequestorID   = permission.UserID;
                request.RequestorName = permission.Name;
                request.IsApproved    = permission.Approved == true;
                request.RequestorLink = string.Format(CultureInfo.InvariantCulture, "{0}Profile/Index/{1}", HttpContext.Request.Url.GetServerLink(), permission.UserID);
                request.CommunityLink = string.Format(CultureInfo.InvariantCulture, "{0}Community/Index/{1}", HttpContext.Request.Url.GetServerLink(), permission.CommunityID);

                _notificationService.NotifyUserRequestPermissionStatus(request);
            }
            catch (Exception)
            {
                // Ignore all exceptions.
            }
        }
        public static EmailRequest UpdateFrom(this EmailRequest thisObject, UserPermissionStatusRequest request)
        {
            if (thisObject == null)
            {
                thisObject = new EmailRequest();
            }

            string entityName = string.Empty;
            bool   isFolder   = false;

            ICommunityRepository communityRepository = DependencyResolver.Current.GetService(typeof(ICommunityRepository)) as ICommunityRepository;
            Community            community           = communityRepository.GetItem(c => c.CommunityID == request.CommunityID);

            if (community != null)
            {
                entityName = community.Name;
                isFolder   = community.CommunityTypeID == (int)CommunityTypes.Folder;
            }

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

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

                thisObject.IsHtml = true;

                // Update the body and the subject.
                thisObject.Subject = string.Format(CultureInfo.CurrentUICulture, "Your request to join the Layerscape {0} \"{1}\" has been {2}", isFolder ? "folder" : "community", entityName, request.IsApproved ? "Approved" : "Denied");

                var replacements = new Dictionary <string, string>
                {
                    { "@@CommunityName@@", HttpUtility.UrlDecode(entityName) },
                    { "@@CommunityLink@@", HttpUtility.UrlDecode(request.CommunityLink) },
                    { "@@RequestorName@@", HttpUtility.UrlDecode(user.GetFullName()) },
                    { "@@RequestorID@@", HttpUtility.UrlDecode(request.RequestorID.ToString()) },
                    { "@@RequestorLink@@", HttpUtility.UrlDecode(request.RequestorLink) },
                    { "@@PermissionStatus@@", HttpUtility.UrlDecode(request.IsApproved ? "Approved" : "Denied") },
                    { "@@CommunityType@@", isFolder ? "folder" : "community" },
                    { "@@Greetings@@", HttpUtility.UrlDecode(request.IsApproved ? "Congratulations! Your" : "We regret to inform you that your") },
                };
                thisObject.MessageBody = FormatMailBodyUsingTemplate("requestorapprovedrequest.html", replacements);
            }

            return(thisObject);
        }
        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);
        }
 /// <summary>
 /// Notify the user about his permission approval/denial.
 /// </summary>
 /// <param name="notification">Permission details</param>
 public void NotifyUserRequestPermissionStatus(UserPermissionStatusRequest notification)
 {
     SendMail(notification);
 }