/// <summary>
        /// This function retrieves the contents uploaded by the user.
        /// </summary>
        /// <param name="userId">User identity.</param>
        /// <returns>Payload details.</returns>
        public async Task<PayloadDetails> GetUserContents(long userId)
        {
            PayloadDetails payloadDetails = null;

            Expression<Func<Content, bool>> condition = c => c.CreatedByID == userId
                && c.IsDeleted == false
                && Enumerable.FirstOrDefault(c.CommunityContents) != null
                && !(bool)Enumerable.FirstOrDefault(c.CommunityContents).Community.IsDeleted;

            Func<Content, object> orderBy = c => c.ModifiedDatetime;

            var contents =  _contentRepository.GetItems(condition, orderBy, true);

            // Get Content Details object from Contents so that it has permission details
            var contentDetailsList = new List<ContentDetails>();
            foreach (Content content in contents)
            {
                var userRole = GetContentUserRole(content, userId);

                // For private contents, user's who have not assigned explicit permission will not have access.
                if (userRole != UserRole.None)
                {
                    var contentDetails = new ContentDetails(userRole.GetPermission());
                    contentDetails.SetValuesFrom(content);
                    contentDetailsList.Add(contentDetails);
                }
            }

            payloadDetails = PayloadDetailsExtensions.InitializePayload();
            payloadDetails.Name = "My Contents";

            payloadDetails.SetValuesFrom(contentDetailsList);
            return payloadDetails;
        }
        public ContentDetails GetContentDetails(Guid azureId, bool? deleted)
        {
            var deletedCondition = deleted.HasValue ? deleted : false;
            ContentDetails contentDetails = null;
            var content = _contentRepository.GetContent(azureId, deletedCondition);
            if (content != null)
            {
                var userRole = UserRole.SiteAdmin;
                var userPermission = userRole.GetPermission();
                contentDetails = new ContentDetails(userPermission);
                contentDetails.SetValuesFrom(content);
            }

            return contentDetails;
        }
        /// <summary>
        /// Gets the contents from the Layerscape database.
        /// </summary>
        /// <param name="contentId">Content for which details to be fetched</param>
        /// <param name="userId">Id of the user who is accessing</param>
        /// <returns>Details about the content</returns>
        public ContentDetails GetContentDetailsForEdit(long contentId, long userId)
        {
            ContentDetails contentDetails = null;
            var content = _contentRepository.GetContent(contentId);
            if (content != null)
            {
                Permission userPermission;
                var userRole = GetContentUserRole(content, userId);

                // In case of Edit, user should have role assigned for editing the content.
                if (CanEditDeleteContent(content, userId, userRole))
                {
                    userPermission = userRole.GetPermission();

                    contentDetails = new ContentDetails(userPermission);
                    contentDetails.SetValuesFrom(content);
                }
            }

            return contentDetails;
        }
Example #4
0
        public async Task<JsonResult> SaveEdits(string contentInputViewModel)
        {
            if (CurrentUserId == 0)
            {
                await TryAuthenticateFromHttpContext(_communityService, _notificationService);
            }

            //TODO: understand why can't cast the viewmodel directly  the way we do with new content??
            var viewModel = JsonConvert.DeserializeObject<ContentInputViewModel>(contentInputViewModel);

            var isValid = ModelState.IsValid;
            if (isValid)
            {
                if (CurrentUserId != 0 && viewModel.ID.HasValue)
                {
                    var contentDetails = new ContentDetails();
                    contentDetails.SetValuesFrom(viewModel);
                    // Update contents.
                    _contentService.UpdateContent(contentDetails, CurrentUserId);
                    return Json(contentDetails);
                }
                return Json("error: User not logged in");
            }
            return Json("error: Could not save changes to content");
            
        }
        /// <summary>
        /// Gets the contents from the Layerscape database.
        /// </summary>
        /// <param name="contentId">Content for which details to be fetched</param>
        /// <param name="userId">Id of the user who is accessing</param>
        /// <returns>Details about the content</returns>
        public ContentDetails GetContentDetails(long contentId, long userId)
        {
            ContentDetails contentDetails = null;
            var content = _contentRepository.GetContent(contentId);
            if (content != null)
            {
                Permission userPermission;
                var userRole = GetContentUserRole(content, userId);

                // For private contents, user's who have not assigned explicit permission will not have access.
                if (CanReadContent(userRole))
                {
                    userPermission = userRole.GetPermission();

                    contentDetails = new ContentDetails(userPermission);
                    contentDetails.SetValuesFrom(content);
                }
            }

            return contentDetails;
        }
Example #6
0
 public async Task<JsonResult> New(ContentInputViewModel contentInputViewModel, string id)
 {
     if (CurrentUserId == 0)
     {
         await TryAuthenticateFromHttpContext(_communityService, _notificationService);
     }
     if (ModelState.IsValid)
     {
         var contentDetails = new ContentDetails();
         contentDetails.SetValuesFrom(contentInputViewModel);
         contentDetails.CreatedByID = CurrentUserId;
         contentInputViewModel.ID = contentDetails.ID = _contentService.CreateContent(contentDetails);
     }
     return new JsonResult { Data = contentInputViewModel };
 }
Example #7
0
        //Creating overload - may replace as we can assume community permission applies to contents as well.
        private List<ContentDetails> GetContentDetailsFromContent(IEnumerable<Content> contents, Permission userPermission)
        {
            // Set Child Content based on user permissions
            var contentDetailsList = new List<ContentDetails>();
            if (userPermission != Permission.Visitor && userPermission != Permission.PendingApproval)
            {
                foreach (var childContent in contents)
                {

                    var contentDetails = new ContentDetails(userPermission);
                    contentDetails.SetValuesFrom(childContent);
                    contentDetailsList.Add(contentDetails);
                }
            }
            return contentDetailsList;
        }
Example #8
0
        /// <summary>
        /// Get ContentDetails from Content
        /// </summary>
        /// <param name="contents">contents list</param>
        /// <param name="userId">user identity</param>
        /// <returns>Content Details list</returns>
        private List<ContentDetails> GetContentDetailsFromContent(IEnumerable<Content> contents, long? userId)
        {
            // Set Child Content based on user permissions
            var contentDetailsList = new List<ContentDetails>();
            foreach (var childContent in contents)
            {
                var userRole = _contentService.GetContentUserRole(childContent, userId);

                // For private contents, user's who have not assigned explicit permission will not have access.
                if (userRole != UserRole.None)
                {
                    var contentDetails = new ContentDetails(userRole.GetPermission());
                    contentDetails.SetValuesFrom(childContent);
                    contentDetailsList.Add(contentDetails);
                }
            }
            return contentDetailsList;
        }
Example #9
0
        /// <summary>
        /// Retrieves the contents of the given community.
        /// </summary>
        /// <param name="communityId">ID of the community.</param>
        /// <param name="userId">Id of the user who is accessing</param>
        /// <param name="pageDetails">Details about the pagination</param>
        /// <returns>An enumerable which contains the contents of the community</returns>
        public IEnumerable<ContentDetails> GetContents(long communityId, long userId, PageDetails pageDetails)
        {
            this.CheckNotNull(() => new { pageDetails });

            IList<ContentDetails> contents = new List<ContentDetails>();

            var contentIDs = _communityRepository.GetContentIDs(communityId, userId);

            // Gets the total number of contents of the community
            pageDetails.TotalCount = contentIDs.Count();

            pageDetails.TotalPages = (pageDetails.TotalCount / pageDetails.ItemsPerPage) + ((pageDetails.TotalCount % pageDetails.ItemsPerPage == 0) ? 0 : 1);

            if (contentIDs != null && contentIDs.Count() > 0)
            {
                contentIDs = contentIDs.Skip((pageDetails.CurrentPage - 1) * pageDetails.ItemsPerPage).Take(pageDetails.ItemsPerPage);
                foreach (var content in _contentRepository.GetItems(contentIDs))
                {
                    var userRole = UserRole.Visitor;

                    if (content.CreatedByID == userId)
                    {
                        userRole = UserRole.Owner;
                    }
                    else
                    {
                        userRole = _userRepository.GetUserRole(userId, communityId);

                        if (userRole == UserRole.Moderator)
                        {
                            // In case of user is Moderator for the parent community, he should be considered as moderator inherited so 
                            // that he will be having permissions to edit/delete this content.
                            userRole = UserRole.ModeratorInheritted;
                        }
                        else if (userRole == UserRole.Contributor)
                        {
                            // In case of user is Contributor for the parent community, he should be considered as Owner if the content
                            // is created by him. If the content is not created by him, he should be considered as Reader.
                            userRole = UserRole.Reader;
                        }
                    }

                    var contentDetails = new ContentDetails(userRole.GetPermission());

                    // Some of the values which comes from complex objects need to be set through this method.
                    contentDetails.SetValuesFrom(content);

                    contents.Add(contentDetails);
                }
            }

            return contents;
        }
Example #10
0
        public ContentDetails GetContentDetails(Guid azureId)
        {
            ContentDetails contentDetails = null;
            var content = _contentRepository.GetContent(azureId);
            if (content != null)
            {
                var userRole = UserRole.SiteAdmin;
                var userPermission = userRole.GetPermission();
                contentDetails = new ContentDetails(userPermission);
                contentDetails.SetValuesFrom(content);
            }

            return contentDetails;
        }