/// <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);
        }
Example #2
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"));
        }
Example #3
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);
        }
        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);
        }
Example #5
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
     });
 }
        /// <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);
        }
        /// <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);
        }