/// <summary> /// Populates the ContentDetails object's properties from the given Content's object's properties. /// </summary> /// <param name="thisObject">Current content details model on which the extension method is called</param> /// <param name="content">ContentsView model from which values to be read</param> public static void SetValuesFrom(this ContentDetails thisObject, Content content) { if (thisObject != null && content != null) { var start = DateTime.Now; // Populate the base values using the EntityViewModel's SetValuesFrom method. (thisObject as EntityDetails).SetValuesFrom(content); var contentData = new DataDetail(); thisObject.ContentData = contentData.SetValuesFrom(content); thisObject.Citation = content.Citation; thisObject.DownloadCount = content.DownloadCount ?? 0; // Get the distributed by user. thisObject.DistributedBy = content.DistributedBy; // Produced by is equivalent to created by. thisObject.ProducedBy = content.User.FirstName + " " + content.User.LastName; thisObject.TourLength = content.TourRunLength; // Set Thumbnail properties. var thumbnailDetail = new FileDetail { AzureID = content.ThumbnailID ?? Guid.Empty }; thisObject.Thumbnail = thumbnailDetail; // Set video properties. var video = content.ContentRelation.FirstOrDefault(cr => cr.ContentRelationshipTypeID == (int)AssociatedContentRelationshipType.Video); if (video != null) { var videoDetails = new DataDetail(); thisObject.Video = videoDetails.SetValuesFrom(video.Content1); } // Set associated file details. thisObject.AssociatedFiles = GetAssociatedFiles(content); } }
/// <summary> /// Gets the associated files from content input view model. /// </summary> /// <param name="content">Input view model.</param> /// <returns>Associated files.</returns> private static IEnumerable <DataDetail> GetAssociatedFiles(Content content) { var associatedFiles = new List <DataDetail>(); if (content.ContentRelation.Count > 0) { for (int i = 0; i < content.ContentRelation.Count; i++) { var contentRelation = content.ContentRelation.ElementAt(i); if (contentRelation.ContentRelationshipTypeID == (int)AssociatedContentRelationshipType.Associated) { // If the posted file details does not have the following details // then do not process the file. var fileDetail = new DataDetail(); associatedFiles.Add(fileDetail.SetValuesFrom(content.ContentRelation.ElementAt(i).Content1)); } } } return(associatedFiles); }