/// <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;
        }
Exemplo n.º 2
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;
        }