/// <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>
        /// 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;
        }
        /// <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);
            }
        }
Example #4
0
        public ActionResult GetTourAuthorThumb(Guid tourId)
        {
            var tour = _contentService.GetContentDetails(tourId);
            var thumb = tour.AssociatedFiles.FirstOrDefault();
            var thumbContent = new Content();
            thumbContent.SetValuesFrom(tour, thumb);

            var blobDetails = _blobService.GetFile(thumbContent.ContentAzureID);
            if (blobDetails != null && blobDetails.Data != null)
            {
                blobDetails.MimeType = Constants.DefaultThumbnailMimeType;

                // Update the response header.
                Response.AddHeader("Content-Encoding", blobDetails.MimeType);

                // Set the position to Begin.
                blobDetails.Data.Seek(0, SeekOrigin.Begin);
                return new FileStreamResult(blobDetails.Data, blobDetails.MimeType);
            }
            return new EmptyResult();

        }