public bool DeleteOffensiveContent(string id)
        {
            bool status = false;

            ProfileDetails profileDetails;

            if (ValidateAuthentication(true, out profileDetails))
            {
                IProfileService profileService = DependencyResolver.Current.GetService(typeof(IProfileService)) as IProfileService;
                profileDetails = profileService.GetProfile(profileDetails.PUID);
                if (profileDetails != null)
                {
                    var details = new OffensiveEntry()
                    {
                        EntityID   = long.Parse(id, CultureInfo.InvariantCulture),
                        ReviewerID = profileDetails.ID,
                        Status     = OffensiveStatusType.Offensive
                    };

                    IContentService contentService = DependencyResolver.Current.GetService(typeof(IContentService)) as IContentService;
                    status = contentService.DeleteContent(long.Parse(id, CultureInfo.InvariantCulture), profileDetails.ID, true, details).Succeeded;

                    // Notify the Moderators and Owners about the Deleted Content.
                    INotificationService     notificationService = DependencyResolver.Current.GetService(typeof(INotificationService)) as INotificationService;
                    EntityAdminActionRequest notification        = new EntityAdminActionRequest()
                    {
                        AdminID    = profileDetails.ID,
                        EntityID   = long.Parse(id, CultureInfo.InvariantCulture),
                        EntityType = EntityType.Content,
                        EntityLink = string.Format(CultureInfo.InvariantCulture, "{0}/Content/Index/{1}", HttpContext.Current.Request.UrlReferrer.GetApplicationPath(), id),
                        Action     = AdminActions.Delete
                    };

                    notificationService.NotifyEntityDeleteRequest(notification);
                }
                else
                {
                    throw new WebFaultException <string>(Resources.UserNotRegisteredMessage, HttpStatusCode.Unauthorized);
                }
            }

            return(status);
        }
        public bool MarkAsPrivateCommunity(string id)
        {
            bool status = false;

            ProfileDetails profileDetails;

            if (ValidateAuthentication(true, out profileDetails))
            {
                IProfileService profileService = DependencyResolver.Current.GetService(typeof(IProfileService)) as IProfileService;
                profileDetails = profileService.GetProfile(profileDetails.PUID);
                if (profileDetails != null)
                {
                    ICommunityService communityService = DependencyResolver.Current.GetService(typeof(ICommunityService)) as ICommunityService;
                    status = communityService.SetCommunityAccessType(long.Parse(id, CultureInfo.InvariantCulture), profileDetails.ID, AccessType.Private).Succeeded;

                    // Notify the Moderators and Owners about the Community which has been marked as private.
                    INotificationService     notificationService = DependencyResolver.Current.GetService(typeof(INotificationService)) as INotificationService;
                    EntityAdminActionRequest notification        = new EntityAdminActionRequest()
                    {
                        AdminID    = profileDetails.ID,
                        EntityID   = long.Parse(id, CultureInfo.InvariantCulture),
                        EntityType = EntityType.Community,
                        EntityLink = string.Format(CultureInfo.InvariantCulture, "{0}/Community/Index/{1}", HttpContext.Current.Request.UrlReferrer.GetApplicationPath(), id),
                        Action     = AdminActions.MarkAsPrivate
                    };

                    notificationService.NotifyEntityDeleteRequest(notification);
                }
                else
                {
                    throw new WebFaultException <string>(Resources.UserNotRegisteredMessage, HttpStatusCode.Unauthorized);
                }
            }

            return(status);
        }
        public static EmailRequest UpdateFrom(this EmailRequest thisObject, EntityAdminActionRequest 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.EntityID);
                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.EntityID);
                Community community = communityRepository.GetItem(c => c.CommunityID == request.EntityID);
                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));
                }
            }

            thisObject.IsHtml = true;

            // Update the body and the subject.
            switch (request.Action)
            {
            case AdminActions.Delete:
                thisObject.Subject = string.Format(CultureInfo.CurrentUICulture, "The Layerscape {0} \"{1}\" has been deleted by the site admin", request.EntityType.ToString().ToLower(), entityName);
                break;

            case AdminActions.MarkAsPrivate:
                thisObject.Subject = string.Format(CultureInfo.CurrentUICulture, "The Layerscape {0} \"{1}\" has been marked as Private by the site admin", request.EntityType.ToString().ToLower(), entityName);
                break;
            }

            var replacements = new Dictionary <string, string>
            {
                { "@@UserName@@", string.Empty },
                { "@@EntityType@@", HttpUtility.UrlDecode(request.EntityType.ToString().ToLower()) },
                { "@@EntityName@@", HttpUtility.UrlDecode(entityName) },
                { "@@EntityLink@@", HttpUtility.UrlDecode(request.EntityLink) },
                { "@@ContactUsLink@@", string.Format(CultureInfo.CurrentUICulture, "mailto:{0}", Constants.MicrosoftEmail) }
            };

            thisObject.MessageBody = FormatMailBodyUsingTemplate(string.Format(CultureInfo.InvariantCulture, "entityadmin{0}request.html", request.Action.ToString().ToLower()), 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);
        }
        public bool MarkAsPrivateContent(string id)
        {
            bool status = false;

            ProfileDetails profileDetails;
            if (ValidateAuthentication(true, out profileDetails))
            {
                IProfileService profileService = DependencyResolver.Current.GetService(typeof(IProfileService)) as IProfileService;
                profileDetails = profileService.GetProfile(profileDetails.PUID);
                if (profileDetails != null)
                {
                    IContentService contentService = DependencyResolver.Current.GetService(typeof(IContentService)) as IContentService;
                    status = contentService.SetContentAccessType(long.Parse(id, CultureInfo.InvariantCulture), profileDetails.ID, AccessType.Private).Succeeded;

                    // Notify the Moderators and Owners about the Content which has been marked as private.
                    INotificationService notificationService = DependencyResolver.Current.GetService(typeof(INotificationService)) as INotificationService;
                    EntityAdminActionRequest notification = new EntityAdminActionRequest()
                    {
                        AdminID = profileDetails.ID,
                        EntityID = long.Parse(id, CultureInfo.InvariantCulture),
                        EntityType = EntityType.Content,
                        EntityLink = string.Format(CultureInfo.InvariantCulture, "{0}/Content/Index/{1}", HttpContext.Current.Request.UrlReferrer.GetApplicationPath(), id),
                        Action = AdminActions.MarkAsPrivate
                    };

                    notificationService.NotifyEntityDeleteRequest(notification);
                }
                else
                {
                    throw new WebFaultException<string>(Resources.UserNotRegisteredMessage, HttpStatusCode.Unauthorized);
                }
            }

            return status;
        }
        public bool DeleteOffensiveCommunity(string id)
        {
            bool status = false;

            ProfileDetails profileDetails;
            if (ValidateAuthentication(true, out profileDetails))
            {
                IProfileService profileService = DependencyResolver.Current.GetService(typeof(IProfileService)) as IProfileService;
                profileDetails = profileService.GetProfile(profileDetails.PUID);
                if (profileDetails != null)
                {
                    var details = new OffensiveEntry()
                    {
                        EntityID = long.Parse(id, CultureInfo.InvariantCulture),
                        ReviewerID = profileDetails.ID,
                        Status = OffensiveStatusType.Offensive
                    };

                    ICommunityService communityService = DependencyResolver.Current.GetService(typeof(ICommunityService)) as ICommunityService;
                    status = communityService.DeleteCommunity(long.Parse(id, CultureInfo.InvariantCulture), profileDetails.ID, true, details).Succeeded;

                    // Notify the Moderators and Owners about the Deleted Community.
                    INotificationService notificationService = DependencyResolver.Current.GetService(typeof(INotificationService)) as INotificationService;
                    EntityAdminActionRequest notification = new EntityAdminActionRequest()
                    {
                        AdminID = profileDetails.ID,
                        EntityID = long.Parse(id, CultureInfo.InvariantCulture),
                        EntityType = EntityType.Community,
                        EntityLink = string.Format(CultureInfo.InvariantCulture, "{0}/Community/Index/{1}", HttpContext.Current.Request.UrlReferrer.GetApplicationPath(), id),
                        Action = AdminActions.Delete
                    };

                    notificationService.NotifyEntityDeleteRequest(notification);
                }
                else
                {
                    throw new WebFaultException<string>(Resources.UserNotRegisteredMessage, HttpStatusCode.Unauthorized);
                }
            }

            return status;
        }
예제 #7
0
        public static EmailRequest UpdateFrom(this EmailRequest thisObject, EntityAdminActionRequest 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.EntityID);
                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.EntityID);
                Community community = communityRepository.GetItem(c => c.CommunityID == request.EntityID);
                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));
                }
            }

            thisObject.IsHtml = true;

            // Update the body and the subject.
            switch (request.Action)
            {
                case AdminActions.Delete:
                    thisObject.Subject = string.Format(CultureInfo.CurrentUICulture, "The Layerscape {0} \"{1}\" has been deleted by the site admin", request.EntityType.ToString().ToLower(), entityName);
                    break;
                case AdminActions.MarkAsPrivate:
                    thisObject.Subject = string.Format(CultureInfo.CurrentUICulture, "The Layerscape {0} \"{1}\" has been marked as Private by the site admin", request.EntityType.ToString().ToLower(), entityName);
                    break;
            }

            var replacements = new Dictionary<string, string>
            {
                { "@@UserName@@", string.Empty }, 
                { "@@EntityType@@", HttpUtility.UrlDecode(request.EntityType.ToString().ToLower()) },
                { "@@EntityName@@", HttpUtility.UrlDecode(entityName) }, 
                { "@@EntityLink@@", HttpUtility.UrlDecode(request.EntityLink) },
                { "@@ContactUsLink@@", string.Format(CultureInfo.CurrentUICulture, "mailto:{0}", Constants.MicrosoftEmail) }
            };
            thisObject.MessageBody = FormatMailBodyUsingTemplate(string.Format(CultureInfo.InvariantCulture, "entityadmin{0}request.html", request.Action.ToString().ToLower()), replacements);

            return thisObject;
        }
 /// <summary>
 /// Notify the user about the entity has been deleted by the Admin.
 /// </summary>
 /// <param name="notification">Entity Admin Delete Request details</param>
 public void NotifyEntityDeleteRequest(EntityAdminActionRequest notification)
 {
     SendMail(notification);
 }
예제 #9
0
 /// <summary>
 /// Notify the user about the entity has been deleted by the Admin.
 /// </summary>
 /// <param name="notification">Entity Admin Delete Request details</param>
 public void NotifyEntityDeleteRequest(EntityAdminActionRequest notification)
 {
     SendMail(notification);
 }