private OperationStatus DeleteContentRecursively(long contentId, long profileId, bool isOffensive, OffensiveEntry offensiveDetails)
        {
            OperationStatus status = null;
            try
            {
                // Get the current content from DB.
                var content = _contentRepository.GetItem((c) => c.ContentID == contentId && c.IsDeleted == false);

                if (content != null)
                {
                    var userRole = GetContentUserRole(content, profileId);

                    if (CanEditDeleteContent(content, profileId, userRole))
                    {
                        content.IsDeleted = true;
                        content.IsOffensive = isOffensive;
                        content.DeletedByID = profileId;
                        content.DeletedDatetime = DateTime.UtcNow;

                        // Update all the offensive entity entries if the content is being deleted.
                        UpdateAllOffensiveContentEntry(content.ContentID, offensiveDetails);

                        foreach (var contentRelation in content.ContentRelation)
                        {
                            contentRelation.Content1.IsDeleted = true;
                            contentRelation.Content1.IsOffensive = isOffensive;
                            contentRelation.Content1.DeletedByID = profileId;
                            contentRelation.Content1.DeletedDatetime = DateTime.UtcNow;
                        }

                        _contentRepository.Update(content);

                        // Save changes to the database
                        _contentRepository.SaveChanges();

                        status = OperationStatus.CreateSuccessStatus();
                    }
                    else
                    {
                        // In case if user is reader or visitor, he should not be allowed to delete the content.
                        status = OperationStatus.CreateFailureStatus("User does not have permission for deleting the content.");
                    }
                }
                else
                {
                    status = OperationStatus.CreateFailureStatus(string.Format(CultureInfo.CurrentCulture, "Content with ID '{0}' was not found", contentId));
                }
            }
            catch (Exception exception)
            {
                status = OperationStatus.CreateFailureStatus(exception);
            }

            return status;
        }
 /// <summary>
 /// Deletes the specified content from the Earth database.
 /// </summary>
 /// <param name="contentId">Content Id</param>
 /// <param name="profileId">User Identity</param>
 /// <returns>Status of the operation. Success, if succeeded. Failure message and exception details in case of exception.</returns>
 public OperationStatus DeleteContent(long contentId, long profileId)
 {
     var details = new OffensiveEntry()
     {
         EntityID = contentId,
         ReviewerID = profileId,
         Status = OffensiveStatusType.Deleted,
         Justification = "Deleted while deleting the Content."
     };
     return DeleteContentRecursively(contentId, profileId, false, details);
 }
        /// <summary>
        /// Sets the given access type for the specified Content.
        /// </summary>
        /// <param name="contentId">Content Id</param>
        /// <param name="userId">User Identity</param>
        /// <param name="accessType">Access type of the Content.</param>
        /// <returns>Status of the operation. Success, if succeeded. Failure message and exception details in case of exception.</returns>
        public OperationStatus SetContentAccessType(long contentId, long userId, AccessType accessType)
        {
            OperationStatus status = null;

            try
            {
                if (_userRepository.IsSiteAdmin(userId))
                {
                    // Get the current content from DB.
                    var content = _contentRepository.GetItem((c) => c.ContentID == contentId);

                    // Make sure content exists
                    this.CheckNotNull(() => new { content });

                    content.AccessTypeID = (int)accessType;

                    content.IsOffensive = (accessType == AccessType.Private);

                    var offensiveDetails = new OffensiveEntry()
                    {
                        EntityID = contentId,
                        ReviewerID = userId,
                        Status = OffensiveStatusType.Offensive
                    };

                    UpdateAllOffensiveContentEntry(contentId, offensiveDetails);

                    _contentRepository.Update(content);
                    _contentRepository.SaveChanges();

                    // Create Success message if set access type is successful.
                    status = OperationStatus.CreateSuccessStatus();
                }
            }
            catch (Exception exception)
            {
                status = OperationStatus.CreateFailureStatus(exception);
            }

            return status;
        }
        /// <summary>
        /// Updates the all the entries for the given Content with all the details.
        /// </summary>
        /// <param name="contentId">Content ID.</param>
        /// <param name="details">Details provided.</param>
        /// <returns>True if content was updated; otherwise false.</returns>
        private OperationStatus UpdateAllOffensiveContentEntry(long contentId, OffensiveEntry details)
        {
            OperationStatus status = null;
            try
            {
                var offensiveContents =  _offensiveContentRepository.GetItems(oc => oc.ContentID == contentId && oc.OffensiveStatusID == (int)OffensiveStatusType.Flagged, null, false);
                if (offensiveContents != null && offensiveContents.Any())
                {
                    foreach (var item in offensiveContents)
                    {
                        item.OffensiveStatusID = (int)details.Status;
                        item.Justification = details.Justification;

                        item.ReviewerID = details.ReviewerID;
                        item.ReviewerDatetime = DateTime.UtcNow;

                        _offensiveContentRepository.Update(item);
                    }
                }
            }
            catch (Exception exception)
            {
                status = OperationStatus.CreateFailureStatus(exception);
            }

            // Status will be null if all sub communities and contents have been deleted. 
            // If one them is not deleted then the status will have the exception details.
            status = status ?? OperationStatus.CreateSuccessStatus();

            return status;
        }
 /// <summary>
 /// Deletes the specified content from the Earth database.
 /// </summary>
 /// <param name="contentId">Content Id</param>
 /// <param name="profileId">User Identity</param>
 /// <param name="isOffensive">Whether community is offensive or not.</param>
 /// <param name="offensiveDetails">Offensive Details.</param>
 /// <returns>Status of the operation. Success, if succeeded. Failure message and exception details in case of exception.</returns>
 public OperationStatus DeleteContent(long contentId, long profileId, bool isOffensive, OffensiveEntry offensiveDetails)
 {
     return DeleteContentRecursively(contentId, profileId, isOffensive, offensiveDetails);
 }
        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 DeleteOffensiveCommunityEntry(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)
                {
                    IReportEntityService entityService = DependencyResolver.Current.GetService(typeof(IReportEntityService)) as IReportEntityService;
                    var details = new OffensiveEntry()
                    {
                        EntryID = long.Parse(id, CultureInfo.InvariantCulture),
                        ReviewerID = profileDetails.ID,
                        Status = OffensiveStatusType.Reviewed
                    };
                    status = entityService.UpdateOffensiveCommunityEntry(details).Succeeded;
                }
                else
                {
                    throw new WebFaultException<string>(Resources.UserNotRegisteredMessage, HttpStatusCode.Unauthorized);
                }
            }

            return status;
        }
Esempio n. 8
0
        /// <summary>
        /// Deletes the specified community from the Earth database.
        /// </summary>
        /// <param name="communityId">Community Id</param>
        /// <param name="userId">User Identity</param>
        /// <param name="isOffensive">Community is offensive or not</param>
        /// <param name="offensiveDetails">Offensive Details.</param>
        /// <returns>True of the community is deleted. False otherwise.</returns>
        private OperationStatus DeleteCommunityRecursively(long communityId, long userId, bool isOffensive, OffensiveEntry offensiveDetails)
        {
            OperationStatus status = null;
            try
            {
                var userRole = GetCommunityUserRole(communityId, userId);
                var community = _communityRepository.GetItem((Community c) => c.CommunityID == communityId && c.CommunityTypeID != (int)CommunityTypes.User && c.IsDeleted == false);

                if (community != null)
                {
                    if (CanEditDeleteCommunity(community, userId, userRole))
                    {
                        DeleteCommunityContents(community, userId, isOffensive, offensiveDetails);

                        community.IsOffensive = isOffensive;
                        community.DeletedByID = userId;

                        // Mark the Community as updated
                        _communityRepository.Update(community);

                        // Save all the changes made.
                        _communityRepository.SaveChanges();
                    }
                    else
                    {
                        status = OperationStatus.CreateFailureStatus("User does not have permission for deleting community.");
                    }
                }
                else
                {
                    status = OperationStatus.CreateFailureStatus(string.Format(CultureInfo.CurrentCulture, "Community with ID '{0}' was not found", communityId));
                }
            }
            catch (Exception exception)
            {
                status = OperationStatus.CreateFailureStatus(exception);
            }

            // Status will be null if all sub communities and contents have been deleted. 
            // If one them is not deleted then the status will have the exception details.
            status = status ?? OperationStatus.CreateSuccessStatus();

            return status;
        }
Esempio n. 9
0
        /// <summary>
        /// Deletes all the contents of the community, including its sub communities/folders and contents recursively.
        /// </summary>
        /// <param name="community">Community whose contents to be deleted</param>
        /// <param name="profileId">User Identity</param>
        private void DeleteCommunityContents(Community community, long profileId, bool isOffensive, OffensiveEntry offensiveDetails)
        {
            if (community != null)
            {
                community.DeletedDatetime = DateTime.UtcNow;
                community.IsDeleted = true;
                if (offensiveDetails.EntityID == community.CommunityID)
                {
                    community.IsOffensive = isOffensive;
                }

                // Update all the offensive entity entries if the community is being deleted.
                UpdateAllOffensiveCommunityEntry(community.CommunityID, offensiveDetails);

                // Mark all the contents of the community as deleted and also delete the relation entry from CommunityContents table.
                for (var i = community.CommunityContents.Count - 1; i >= 0; i--)
                {
                    var communityContent = Enumerable.ElementAt(community.CommunityContents, i);

                    if (communityContent.Content.IsDeleted == false)
                    {
                        if (offensiveDetails.EntityID == community.CommunityID)
                        {
                            communityContent.Content.IsOffensive = isOffensive;
                        }

                        communityContent.Content.IsDeleted = true;
                        communityContent.Content.DeletedDatetime = DateTime.UtcNow;

                        // Update all the offensive entity entries if the community is being deleted.
                        UpdateAllOffensiveContentEntry(communityContent.Content.ContentID, offensiveDetails);
                    }
                }

                // Mark all the child communities and folders as deleted. Note that current community is parent and
                // all its relations with children will be there in CommunityRelation. Also deleting the relation entry from CommunityRelation table.
                for (var i = community.CommunityRelation.Count - 1; i >= 0; i--)
                {
                    var communityRelation = Enumerable.ElementAt(community.CommunityRelation, i);

                    // Incase if the same community is marked as its parent/child in DB directly, without this check delete call will go indefinitely.
                    if (communityRelation.Community1.IsDeleted == false && communityRelation.Community1.CommunityID != community.CommunityID)
                    {
                        DeleteCommunityContents(communityRelation.Community1, profileId, isOffensive, offensiveDetails);
                    }
                }
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Sets the given access type for the specified community.
        /// </summary>
        /// <param name="communityId">Community Id</param>
        /// <param name="userId">User Identity</param>
        /// <param name="accessType">Access type of the community.</param>
        /// <returns>Status of the operation. Success, if succeeded. Failure message and exception details in case of exception.</returns>
        public async Task<OperationStatus> SetCommunityAccessType(long communityId, long userId, AccessType accessType)
        {
            OperationStatus status;

            try
            {
                if (_userRepository.IsSiteAdmin(userId))
                {
                    var community =  _communityRepository.GetItem(c => c.CommunityID == communityId);

                    // Make sure community exists
                    this.CheckNotNull(() => new { community });

                    community.AccessTypeID = (int)accessType;

                    community.IsOffensive = (accessType == AccessType.Private);

                    var offensiveDetails = new OffensiveEntry()
                    {
                        EntityID = communityId,
                        ReviewerID = userId,
                        Status = OffensiveStatusType.Offensive
                    };

                    UpdateAllOffensiveCommunityEntry(communityId, offensiveDetails);

                    _communityRepository.Update(community);
                    _communityRepository.SaveChanges();

                    // Create Success message if set access type is successful.
                    status = OperationStatus.CreateSuccessStatus();
                }
                else
                {
                    status = OperationStatus.CreateFailureStatus(Resources.UserNotSiteAdminError);
                }
            }
            catch (Exception exception)
            {
                status = OperationStatus.CreateFailureStatus(exception);
            }

            return status;
        }
Esempio n. 11
0
 /// <summary>
 /// Deletes the specified community from the Earth database.
 /// </summary>
 /// <param name="communityId">Community Id</param>
 /// <param name="userId">User Identity</param>
 /// <returns>Status of the operation. Success, if succeeded. Failure message and exception details in case of exception.</returns>
 public OperationStatus DeleteCommunity(long communityId, long userId)
 {
     var details = new OffensiveEntry()
     {
         EntityID = communityId,
         ReviewerID = userId,
         Status = OffensiveStatusType.Deleted,
         Justification = "Deleted while deleting the Community."
     };
     return DeleteCommunityRecursively(communityId, userId, false, details);
 }
Esempio n. 12
0
 /// <summary>
 /// Deletes the specified community from the Earth database.
 /// </summary>
 /// <param name="communityId">Community Id</param>
 /// <param name="userId">User Identity</param>
 /// <param name="isOffensive">Whether community is offensive or not.</param>
 /// <param name="offensiveDetails">Offensive Details.</param>
 /// <returns>Status of the operation. Success, if succeeded. Failure message and exception details in case of exception.</returns>
 public OperationStatus DeleteCommunity(long communityId, long userId, bool isOffensive, OffensiveEntry offensiveDetails)
 {
     return DeleteCommunityRecursively(communityId, userId, isOffensive, offensiveDetails);
 }
Esempio n. 13
0
        public async Task<OperationStatus> UpdateAllOffensiveContentEntry(OffensiveEntry details)
        {
            this.CheckNotNull(() => new { details = details });

            OperationStatus status = null;
            try
            {
                if (_userRepository.IsSiteAdmin(details.ReviewerID))
                {
                    var offensiveContents =  _offensiveContentRepository.GetItems(oc => oc.ContentID == details.EntityID && oc.OffensiveStatusID == (int)OffensiveStatusType.Flagged, null, false);
                    if (offensiveContents != null && offensiveContents.Any())
                    {
                        foreach (var item in offensiveContents)
                        {
                            item.OffensiveStatusID = (int)details.Status;
                            item.Justification = details.Justification;

                            item.ReviewerID = details.ReviewerID;
                            item.ReviewerDatetime = DateTime.UtcNow;

                            _offensiveContentRepository.Update(item);
                        }

                        _offensiveContentRepository.SaveChanges();
                    }
                }
                else
                {
                    status = OperationStatus.CreateFailureStatus(Resources.UserNotSiteAdminError);
                }
            }
            catch (Exception exception)
            {
                status = OperationStatus.CreateFailureStatus(exception);
            }

            // Status will be null if all sub communities and contents have been deleted. 
            // If one them is not deleted then the status will have the exception details.
            status = status ?? OperationStatus.CreateSuccessStatus();

            return status;
        }
Esempio n. 14
0
        public OperationStatus UpdateOffensiveContentEntry(OffensiveEntry details)
        {
            this.CheckNotNull(() => new { details = details });

            OperationStatus status = null;
            try
            {
                if (_userRepository.IsSiteAdmin(details.ReviewerID))
                {
                    var offensiveContents = _offensiveContentRepository.GetItem(oc => oc.OffensiveContentID == details.EntryID);
                    if (offensiveContents != null)
                    {
                        offensiveContents.OffensiveStatusID = (int)details.Status;
                        offensiveContents.Justification = details.Justification;

                        offensiveContents.ReviewerID = details.ReviewerID;
                        offensiveContents.ReviewerDatetime = DateTime.UtcNow;

                        _offensiveContentRepository.Update(offensiveContents);
                        _offensiveContentRepository.SaveChanges();
                    }
                }
                else
                {
                    status = OperationStatus.CreateFailureStatus(Resources.UserNotSiteAdminError);
                }
            }
            catch (Exception exception)
            {
                status = OperationStatus.CreateFailureStatus(exception);
            }

            // Status will be null if all sub communities and contents have been deleted. 
            // If one them is not deleted then the status will have the exception details.
            status = status ?? OperationStatus.CreateSuccessStatus();

            return status;
        }