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; }
/// <summary> /// Updates the relationship for video and content. /// </summary> /// <param name="content">Content which has to be updated.</param> /// <param name="contentDetails">Details of the content.</param> private static void CreateVideo(Content content, ContentDetails contentDetails) { if (contentDetails.Video != null) { var videoContent = new Content(); videoContent.SetValuesFrom(contentDetails, contentDetails.Video); // Note that Modifying user is the one who is creating the video. videoContent.CreatedByID = content.ModifiedByID.Value; var contentRelation = new ContentRelation() { Content = content, Content1 = videoContent, ContentRelationshipTypeID = (int)AssociatedContentRelationshipType.Video }; content.ContentRelation.Add(contentRelation); } }
/// <summary> /// Creates the relationship for associated contents. /// </summary> /// <param name="content">Content which has to be updated.</param> /// <param name="contentDetails">Details of the content.</param> private static void CreateAssociateContents(Content content, ContentDetails contentDetails) { if (contentDetails.AssociatedFiles != null && contentDetails.AssociatedFiles.Count() > 0) { foreach (var dataDetails in contentDetails.AssociatedFiles) { // Create new associated file only if contentId is not set if (!dataDetails.ContentID.HasValue || dataDetails.ContentID.Value <= 0) { var associatedContent = new Content(); associatedContent.SetValuesFrom(contentDetails, dataDetails); // Note that Modifying user is the one who is creating the associated contents. associatedContent.CreatedByID = content.ModifiedByID.Value; var associatedRelation = new ContentRelation() { Content = content, Content1 = associatedContent, ContentRelationshipTypeID = (int)AssociatedContentRelationshipType.Associated }; content.ContentRelation.Add(associatedRelation); } } } }
/// <summary> /// Updates the content in Layerscape with the given details passed in contentDetails instance. /// </summary> /// <param name="contentDetails">Details of the content</param> /// <param name="userId">User identification</param> /// <returns>True if content is updated; otherwise false.</returns> public bool UpdateContent(ContentDetails contentDetails, long userId) { // Make sure content is not null this.CheckNotNull(() => new { contentDetails }); // Get the current content from DB. var content = _contentRepository.GetContent(contentDetails.ID); if (content != null) { var userRole = GetContentUserRole(content, userId); if (!CanEditDeleteContent(content, userId, userRole)) { // In case if user is reader or visitor, he should not be allowed to edit the content. // TODO: Throw item not exists or no permissions exception which will be shown to user in error page. contentDetails = null; this.CheckNotNull(() => new { contentDetails }); } // Upload edited/removed content data, thumbnail, video and associated file to azure. if (UploadFilesToAzure(contentDetails, content)) { if (MoveAssociatedFiles(contentDetails)) { try { // Do not let the user to change the Content as public in case if it is offensive. // This scenario might happen when the edit page is left open or cached and meantime content is marked as offensive // by the Site Admin. if (content.IsOffensive.HasValue && (bool)content.IsOffensive && contentDetails.AccessTypeID == (int)AccessType.Public) { contentDetails.AccessTypeID = (int)AccessType.Private; } // Set values from content details. content.SetValuesFrom(contentDetails); // Set the thumbnail ID. if (contentDetails.Thumbnail.AzureID != content.ThumbnailID) { // Move Thumbnail. content.ThumbnailID = MoveThumbnail(contentDetails.Thumbnail); } // Update Modified by and date time. content.ModifiedByID = userId; content.ModifiedDatetime = DateTime.UtcNow; // Updated Parent child relationship UpdateParent(contentDetails, content); // Update video file details in database. UpdateVideo(content, contentDetails); // Update associated files details in database. UpdateAssociateContents(contentDetails, content); //// TODO: Update Consumed size of the user. If the size is more than allowed throw error. // Update Tags. SetContentTags(contentDetails.Tags, content); _contentRepository.Update(content); // Save changes to the database _contentRepository.SaveChanges(); return true; } catch (Exception) { // Delete Uploaded Content/Video/Thumbnail // Note:- Deleting associated files as will be handled by a worker role // which will delete temporary file from container. DeleteUploadedFiles(contentDetails); throw; } } else { // Delete Uploaded Content/Video/Thumbnail // Note:- Deleting associated files as will be handled by a worker role // which will delete temporary file from container. DeleteUploadedFiles(contentDetails); } } } return false; }
/// <summary> /// Updates the relationship for parent and content. /// </summary> /// <param name="contentDetails">Details of the content.</param> /// <param name="content">Content which has to be updated.</param> private static void UpdateParent(ContentDetails contentDetails, Content content) { // Few things to be noted: // a) Obviously the count to be 1 always. // b) A content can be child of only once parent community or folder if (Enumerable.ElementAt(content.CommunityContents, 0).CommunityID != contentDetails.ParentID) { if (content.CommunityContents.Count > 0) { content.CommunityContents.Clear(); } var comCont = new CommunityContents() { CommunityID = contentDetails.ParentID, Content = content }; // Add the relationship content.CommunityContents.Add(comCont); } }
private void DeleteTemporaryThumbnail(ContentDetails contentDetails) { var thumbnailBlob = new BlobDetails() { BlobID = contentDetails.Thumbnail.AzureID.ToString() }; // Delete thumbnail from azure. _blobDataRepository.DeleteThumbnail(thumbnailBlob); }
/// <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> /// 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; }
/// <summary> /// Gets the top categories from the Layerscape database based on the number of contents which belongs to the category. /// </summary> /// <returns>List of top 6 categories</returns> public async Task<IEnumerable<EntityDetails>> GetTopCategories() { IList<EntityDetails> topCategories = new List<EntityDetails>(); var topCategoryItems = _topCategoryEntities.GetAll(t => t.CategoryID); var contents = topCategoryItems.Where(t => t.EntityType == EntityType.Content.ToString()); var communities = topCategoryItems.Where(t => t.EntityType == EntityType.Community.ToString()); for (var i = 0; i < contents.Count(); i++) { var content = contents.ElementAt(i); var contentDetails = new ContentDetails(); Mapper.Map(content, contentDetails); if (content.ThumbnailID.HasValue) { // TODO: Auto-mapper cannot set this nested object, need to see if there is any better approach. contentDetails.Thumbnail = new FileDetail(); contentDetails.Thumbnail.AzureID = content.ThumbnailID.Value; } // Insert the content to the top categories collection. topCategories.Insert(i * 3, contentDetails); // Get the communities of the content which got inserted. var contentCommunities = communities.Where((TopCategoryEntities t) => t.CategoryID == content.CategoryID); // Get the first community for the current content. TopCategoryEntities firstCommunity = contentCommunities.ElementAtOrDefault(0); var communityDetails = new EntityDetails(); Mapper.Map(firstCommunity, communityDetails); if (firstCommunity != null) { // TODO: Auto-mapper is not setting the nested Thumbnail, need to initialize and set it. // Need to see if there is any better approach. communityDetails.Thumbnail = new FileDetail(); communityDetails.Thumbnail.AzureID = firstCommunity.ThumbnailID ?? Guid.Empty; topCategories.Insert(i * 3 + 1, communityDetails); } else { // Incase if there are no communities for the current content, insert null so that the sequence is maintained. topCategories.Insert(i * 3 + 1, null); } // Get the second community for the current content. TopCategoryEntities secondCommunity = contentCommunities.ElementAtOrDefault(1); communityDetails = new EntityDetails(); Mapper.Map(secondCommunity, communityDetails); if (secondCommunity != null) { // TODO: Auto-mapper is not setting the nested Thumbnail, need to initialize and set it. // Need to see if there is any better approach. communityDetails.Thumbnail = new FileDetail(); communityDetails.Thumbnail.AzureID = firstCommunity.ThumbnailID ?? Guid.Empty; topCategories.Insert(i * 3 + 2, communityDetails); } else { // Incase if there are no communities for the current content, insert null so that the sequence is maintained. topCategories.Insert(i * 3 + 2, null); } } return topCategories.AsEnumerable(); }
private IEnumerable<ContentDetails> GetAllContents(EntityHighlightFilter entityHighlightFilter) { Func<ContentsView, object> orderBy = c => c.LastUpdatedDatetime; var accessType = AccessType.Public.ToString(); Expression<Func<ContentsView, bool>> condition = c => c.AccessType == accessType; if (entityHighlightFilter.CategoryType != CategoryType.All) { condition = c => c.CategoryID == (int)entityHighlightFilter.CategoryType && c.AccessType == accessType; } var contents = _contentsViewRepository.GetItems(condition, orderBy, true); var contentDetails = new List<ContentDetails>(); if (contents != null) { foreach (var content in contents) { var contentDetail = new ContentDetails(); // Some of the values which comes from complex objects need to be set through this method. Mapper.Map(content, contentDetail); contentDetails.Add(contentDetail); } } return contentDetails; }
/// <summary> /// Gets all the contents from the Layerscape database including the deleted items. /// </summary> /// <param name="userId">Id of the user who is accessing</param> /// <param name="categoryId">Category ID for which contents to be fetched</param> /// <returns>List of all Contents</returns> public async Task<IEnumerable<ContentDetails>> GetAllContents(long userId, int? categoryId) { Func<AllContentsView, object> orderBy = c => c.LastUpdatedDatetime; Expression<Func<AllContentsView, bool>> condition = null; var contentDetails = new List<ContentDetails>(); if (_userRepository.IsSiteAdmin(userId)) { if (categoryId != null) { condition = content => content.CategoryID == categoryId; } foreach (var content in _allContentsViewRepository.GetItems(condition, orderBy, true)) { var contentDetail = new ContentDetails(); Mapper.Map(content, contentDetail); contentDetails.Add(contentDetail); } } return contentDetails; }
private IEnumerable<ContentDetails> GetAllFeaturedContents(EntityHighlightFilter entityHighlightFilter) { Func<FeaturedContentsView, object> orderBy = c => c.SortOrder; Expression<Func<FeaturedContentsView, bool>> condition = c => c.FeaturedCategoryID == (int)entityHighlightFilter.CategoryType; var contents = _featuredContentsViewRepository.GetItems(condition, orderBy, false); var contentDetails = new List<ContentDetails>(); if (contents != null) { foreach (var content in contents) { var contentDetail = new ContentDetails(); // Some of the values which comes from complex objects need to be set through this method. Mapper.Map(content, contentDetail); contentDetails.Add(contentDetail); } } return contentDetails; }
/// <summary> /// Gets the Related Content details for the given content. /// </summary> /// <param name="entityHighlightFilter">Filters needed while retrieving collection of entities</param> /// <param name="pageDetails">Details about the pagination</param> /// <returns>Collection of related contents</returns> private IEnumerable<ContentDetails> GetRelatedContentDetails(EntityHighlightFilter entityHighlightFilter, PageDetails pageDetails) { var userId = entityHighlightFilter.EntityId.HasValue ? entityHighlightFilter.EntityId.Value : 0; var relatedContentIds = _contentTagsRepository.GetRelatedContentIDs(userId, entityHighlightFilter.UserID); var condition = GetRelatedContentsCondition(relatedContentIds); // Gets the total items satisfying the var totalItemsForCondition = _contentsViewRepository.GetItemsCount(condition); // If TotalCount is already specified in pageDetails, need to consider that. Ignore even if there are more items in the DB. if (pageDetails.TotalCount > 0 && totalItemsForCondition > pageDetails.TotalCount) { totalItemsForCondition = pageDetails.TotalCount; } pageDetails.TotalPages = (totalItemsForCondition / pageDetails.ItemsPerPage) + ((totalItemsForCondition % pageDetails.ItemsPerPage == 0) ? 0 : 1); IEnumerable<ContentsView> contents = null; relatedContentIds = relatedContentIds.Skip((pageDetails.CurrentPage - 1) * pageDetails.ItemsPerPage).Take(pageDetails.ItemsPerPage); condition = GetRelatedContentsCondition(relatedContentIds); contents = _contentsViewRepository.GetItems(condition, null, false); var contentDetails = new List<ContentDetails>(); if (contents != null) { foreach (var contentId in relatedContentIds) { var contentDetail = new ContentDetails(); var content = contents.Where(c => c.ContentID == contentId).FirstOrDefault(); // Some of the values which comes from complex objects need to be set through this method. Mapper.Map(content, contentDetail); contentDetails.Add(contentDetail); } } return contentDetails; }
private IEnumerable<ContentDetails> GetFeaturedContentDetails(EntityHighlightFilter entityHighlightFilter, PageDetails pageDetails) { Func<FeaturedContentsView, object> orderBy = c => c.SortOrder; var condition = GetFeaturedContentCondition(entityHighlightFilter); // Gets the total items satisfying the var totalItemsForCondition = _featuredContentsViewRepository.GetItemsCount(condition); // If TotalCount is already specified in pageDetails, need to consider that. Ignore even if there are more items in the DB. if (pageDetails.TotalCount > 0 && totalItemsForCondition > pageDetails.TotalCount) { totalItemsForCondition = pageDetails.TotalCount; } pageDetails.TotalPages = (totalItemsForCondition / pageDetails.ItemsPerPage) + ((totalItemsForCondition % pageDetails.ItemsPerPage == 0) ? 0 : 1); // TODO: Passing the condition in a variable doesn't add the WHERE clause in SQL server. Need to work on this later. IEnumerable<FeaturedContentsView> contents = null; // Only for Popular/Top Rated, there is multiple order by which needs to added here. contents = _featuredContentsViewRepository.GetItems(condition, orderBy, false, (pageDetails.CurrentPage - 1) * pageDetails.ItemsPerPage, pageDetails.ItemsPerPage); var contentDetails = new List<ContentDetails>(); if (contents != null) { foreach (var content in contents) { var contentDetail = new ContentDetails(); // Some of the values which comes from complex objects need to be set through this method. Mapper.Map(content, contentDetail); contentDetails.Add(contentDetail); } } return contentDetails; }
/// <summary> /// Uploads associated files to azure. /// </summary> /// <param name="contentDetails">Details of the content.</param> private bool MoveAssociatedFiles(ContentDetails contentDetails) { var status = true; if (contentDetails.AssociatedFiles != null && contentDetails.AssociatedFiles.Count() > 0) { foreach (var dataDetails in contentDetails.AssociatedFiles) { var fileDetails = dataDetails as FileDetail; if (fileDetails != null && (!fileDetails.ContentID.HasValue || fileDetails.ContentID.Value <= 0)) { // Move files from temporary container to file container. if (!MoveFile(fileDetails)) { status = false; break; } } } } return status; }
private IEnumerable<ContentDetails> GetContentDetails(EntityHighlightFilter entityHighlightFilter, PageDetails pageDetails) { var orderBy = GetContentOrderByClause(entityHighlightFilter); var condition = GetContentConditionClause(entityHighlightFilter); // Gets the total items satisfying the var totalItemsForCondition = _contentsViewRepository.GetItemsCount(condition); // If TotalCount is already specified in pageDetails, need to consider that. Ignore even if there are more items in the DB. if (pageDetails.TotalCount > 0 && totalItemsForCondition > pageDetails.TotalCount) { totalItemsForCondition = pageDetails.TotalCount; } pageDetails.TotalPages = (totalItemsForCondition / pageDetails.ItemsPerPage) + ((totalItemsForCondition % pageDetails.ItemsPerPage == 0) ? 0 : 1); // TODO: Passing the condition in a variable doesn't add the WHERE clause in SQL server. Need to work on this later. IEnumerable<ContentsView> contents = null; // Only for Popular/Top Rated, there is multiple order by which needs to added here. if (entityHighlightFilter.HighlightType == HighlightType.Popular) { // TODO: This is a temporary fix, since multiple order by cannot be passed. // Need to do this in a better way, instead of getting all the items. contents = _contentsViewRepository.GetItems(condition, null, true); contents = contents .OrderByDescending((ContentsView c) => c.AverageRating) .ThenByDescending<ContentsView, int?>((ContentsView c) => c.RatedPeople) .Skip((pageDetails.CurrentPage - 1) * pageDetails.ItemsPerPage) .Take(pageDetails.ItemsPerPage) .ToList(); } else { contents = _contentsViewRepository.GetItems(condition, orderBy, true, (pageDetails.CurrentPage - 1) * pageDetails.ItemsPerPage, pageDetails.ItemsPerPage); } var contentDetails = new List<ContentDetails>(); if (contents != null) { foreach (var content in contents) { var contentDetail = new ContentDetails(); // Some of the values which comes from complex objects need to be set through this method. Mapper.Map(content, contentDetail); contentDetails.Add(contentDetail); } } return contentDetails; }
/// <summary> /// Deletes already uploaded contents from azure. /// </summary> /// <param name="contentDetails">Details of the content.</param> private void DeleteUploadedFiles(ContentDetails contentDetails) { // Delete content data. var fileDetail = contentDetails.ContentData as FileDetail; if (fileDetail != null) { DeleteFile(fileDetail); } // Delete video. var videoDetail = contentDetails.Video as FileDetail; if (contentDetails.Video != null) { DeleteFile(videoDetail); } }
/// <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; }
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; }
//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; }
/// <summary> /// Creates the new content in Layerscape with the given details passed in ContentsView instance. /// </summary> /// <param name="contentDetails">Details of the content</param> /// <returns>Id of the content created. Returns -1 is creation is failed.</returns> public long CreateContent(ContentDetails contentDetails) { // Make sure content is not null this.CheckNotNull(() => new { contentDetails }); long contentId = -1; var userRole = GetCommunityUserRole(contentDetails.ParentID, contentDetails.CreatedByID); if (!CanCreateContent(userRole)) { // TODO: Throw custom permissions exception which will be shown to user in error page. throw new HttpException(401, Resources.NoPermissionCreateContentMessage); } // Upload content data, thumbnail, video and associated file to azure. // Since the associated files are already stored in the Temporary container. // We need to move the files to actual container. if (UploadFilesToAzure(contentDetails)) { if (MoveAssociatedFiles(contentDetails)) { try { // Create a new instance of content details var content = new Content(); // Set values from content details. content.SetValuesFrom(contentDetails); // Set the thumbnail ID. content.ThumbnailID = MoveThumbnail(contentDetails.Thumbnail); // Set Created and modified time. content.CreatedDatetime = content.ModifiedDatetime = DateTime.UtcNow; // Set Created and modified IDs. content.ModifiedByID = contentDetails.CreatedByID; content.CreatedByID = contentDetails.CreatedByID; // Set Default Values. content.IsDeleted = false; content.IsSearchable = true; content.IsOffensive = false; content.DownloadCount = 0; var parentCommunity = _communityRepository.GetItem(c => c.CommunityID == contentDetails.ParentID); if (parentCommunity != null) { parentCommunity.ModifiedByID = contentDetails.CreatedByID; parentCommunity.ModifiedDatetime = DateTime.UtcNow; // Updated Parent child relationship var comCont = new CommunityContents() { Community = parentCommunity, Content = content }; // Add the relationship content.CommunityContents.Add(comCont); } // Update video file details in database. CreateVideo(content, contentDetails); // Update associated files details in database. CreateAssociateContents(content, contentDetails); // Update Tags. SetContentTags(contentDetails.Tags, content); //// TODO: Update Permissions Details. //// TODO: Update Consumed size of the user. If the size is more than allowed throw error. _contentRepository.Add(content); // Save changes to the database _contentRepository.SaveChanges(); // Get the content ID from database. We need to retrieve it from the database as it is a identity column. contentId = content.ContentID; } catch (Exception) { // Delete Uploaded Content/Video/Thumbnail // Note:- Deleting associated files as will be handled by a worker role // which will delete temporary file from container. DeleteUploadedFiles(contentDetails); throw; } } else { // Delete Uploaded Content/Video/Thumbnail // Note:- Deleting associated files as will be handled by a worker role // which will delete temporary file from container. DeleteUploadedFiles(contentDetails); } } return contentId; }
public async Task<List<ContentDetails>> GetCommunityContents(long communityId, long userId) { var userRole = GetCommunityUserRole(communityId, userId); var userPermission = userRole.GetPermission(); var contents = await _communityRepository.GetContents(communityId, userId); var contentDetailsList = new List<ContentDetails>(); foreach (var content in contents) { ContentDetails contentDetails = null; contentDetails = new ContentDetails(userPermission); Mapper.Map(content, contentDetails); contentDetailsList.Add(contentDetails); } //var contentDetailsList = GetContentDetailsFromContent(contents, userPermission); return contentDetailsList; }
/// <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 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> /// Updates the relationship for video and content. /// </summary> /// <param name="content">Content which has to be updated.</param> /// <param name="contentDetails">Details of the content.</param> private static void UpdateVideo(Content content, ContentDetails contentDetails) { var videoDetail = contentDetails.Video as FileDetail; if (videoDetail != null) { var deletedById = content.ModifiedByID.Value; var existingVideo = Enumerable.Where(content.ContentRelation, cr => cr.ContentRelationshipTypeID == (int)AssociatedContentRelationshipType.Video && cr.Content1.IsDeleted == false).FirstOrDefault(); if (existingVideo != null) { // Remove the previous videos from azure. existingVideo.Content1.IsDeleted = true; existingVideo.Content1.DeletedByID = deletedById; existingVideo.Content1.DeletedDatetime = DateTime.UtcNow; content.ContentRelation.Remove(existingVideo); } CreateVideo(content, contentDetails); } }
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> /// Updates the relationship for associated contents. /// </summary> /// <param name="contentDetails">Details of the content.</param> /// <param name="content">Content which has to be updated.</param> private static void UpdateAssociateContents(ContentDetails contentDetails, Content content) { var deletedById = content.ModifiedByID.Value; // Get all Existing files list. var newFilesIDs = contentDetails.AssociatedFiles .Where(af => (af.ContentID.HasValue) && (af.ContentID.Value > 0)) .Select(af => af.ContentID.Value); // Delete all existing associated files which are not part of the new associated file list. var removeAssociatedFiles = from cr in content.ContentRelation where cr.ContentRelationshipTypeID == (int)AssociatedContentRelationshipType.Associated && !newFilesIDs.Contains(cr.Content1.ContentID) select cr; foreach (var item in Enumerable.ToList(removeAssociatedFiles)) { item.Content1.IsDeleted = true; item.Content1.DeletedByID = deletedById; item.Content1.DeletedDatetime = DateTime.UtcNow; content.ContentRelation.Remove(item); } // Create new associated files. CreateAssociateContents(content, 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; }
/// <summary> /// Uploads all files to azure. /// </summary> /// <param name="contentDetails">Details of the content.</param> private bool UploadFilesToAzure(ContentDetails contentDetails, Content content) { var uploadStatus = true; // Upload content data. var fileDetail = contentDetails.ContentData as FileDetail; if (fileDetail != null && content.ContentAzureID != fileDetail.AzureID) { // Move the content file from temporary container to file container. uploadStatus = MoveFile(fileDetail); } // Upload video. if (contentDetails.Video != null && uploadStatus) { var videoDetail = contentDetails.Video as FileDetail; if (videoDetail != null) { // Move the video file from temporary container to file container. uploadStatus = MoveFile(videoDetail); } } return uploadStatus; }
/// <summary> /// Updates the associated files from content details model. /// </summary> /// <param name="thisObject">ContentInput ViewModel.</param> /// <param name="content">COntent details model.</param> private static void UpdateAssociatedFiles(ContentInputViewModel thisObject, ContentDetails content) { List<string> postedFileNames = new List<string>(); List<string> postedFileDetails = new List<string>(); if (content.AssociatedFiles != null) { foreach (var item in content.AssociatedFiles) { string postedFileDetail = string.Empty; if (item is LinkDetail) { postedFileDetail = string.Format(CultureInfo.InvariantCulture, "link~0~{1}~link~{0}", item.ContentID, Guid.Empty); } else { var fileDetail = item as FileDetail; if (item != null) { postedFileDetail = string.Format( CultureInfo.InvariantCulture, "{0}~{1}~{2}~{3}~{4}", Path.GetExtension(fileDetail.Name), fileDetail.Size, fileDetail.AzureID.ToString(), fileDetail.MimeType, item.ContentID); } } postedFileNames.Add(item.Name); postedFileDetails.Add(postedFileDetail); } } thisObject.PostedFileName = postedFileNames; thisObject.PostedFileDetail = postedFileDetails; }