/// <summary>
        /// Populates the Tour object's properties from the given content view.
        /// </summary>
        /// <param name="thisObject">Tour object</param>
        /// <param name="contentsView">content view object</param>
        /// <returns>Tour instance</returns>
        public static TourModel SetValuesFrom(this TourModel thisObject, ContentsView contentsView)
        {
            if (contentsView != null)
            {
                if (thisObject == null)
                {
                    thisObject = new TourModel();
                }

                thisObject.Title = contentsView.Title;
                thisObject.TourUrl = contentsView.ContentAzureID.ToString();
                thisObject.ID = contentsView.ContentAzureID.ToString();
                thisObject.MSRComponentId = contentsView.ContentID;
                thisObject.Description = contentsView.Description;
                thisObject.Author = contentsView.DistributedBy;
                thisObject.ThumbnailUrl = (contentsView.ThumbnailID.HasValue && contentsView.ThumbnailID != Guid.Empty) ? contentsView.ThumbnailID.ToString() : null;
                thisObject.LengthInSecs = contentsView.TourRunLength;
                thisObject.AverageRating = contentsView.AverageRating.HasValue ? contentsView.AverageRating.ToString() : "0";

                // Permissions for Content view are hard-coded to Read as it is used for browse
                thisObject.Permission = Permission.Reader;
            }

            return thisObject;
        }
        /// <summary>
        /// Populates the PayloadDetails object's properties from the given Content object's properties.
        /// </summary>
        /// <param name="thisObject">PayloadDetails object</param>
        /// <param name="contentDetail">Content Details object</param>
        /// <returns>PayloadDetails instance</returns>
        public static PayloadDetails SetValuesFrom(this PayloadDetails thisObject, ContentDetails contentDetail)
        {
            if (contentDetail != null)
            {
                if (thisObject == null)
                {
                    thisObject = InitializePayload();
                }

                if (contentDetail.ContentData is FileDetail)
                {
                    var fileDetail = contentDetail.ContentData as FileDetail;
                    if (contentDetail.ContentData.ContentType == ContentTypes.Tours)
                    {
                        var tour = new TourModel();
                        tour.SetValuesFrom(contentDetail);
                        thisObject.Tours.Add(tour);
                    }
                    else if (contentDetail.ContentData.ContentType == ContentTypes.Wtml)
                    {
                        var childCollection = new PayloadDetails();
                        childCollection.Name = contentDetail.Name;
                        childCollection.Id = fileDetail.AzureID.ToString();
                        childCollection.MSRComponentId = contentDetail.ID;
                        childCollection.Group = "Explorer";
                        childCollection.IsCollection = true;
                        childCollection.Thumbnail = (contentDetail.Thumbnail != null && contentDetail.Thumbnail.AzureID != Guid.Empty) ? contentDetail.Thumbnail.AzureID.ToString() : null;
                        childCollection.Permission = contentDetail.UserPermission;
                        thisObject.Children.Add(childCollection);
                    }
                    else
                    {
                        var place = new Place();
                        place.SetValuesFrom(contentDetail);
                        thisObject.Links.Add(place);
                    }
                }
                else
                {
                    var place = new Place();
                    place.SetValuesFrom(contentDetail);
                    thisObject.Links.Add(place);
                }
            }

            return thisObject;
        }
        /// <summary>
        /// Populates the Tour object's properties from the given content.
        /// </summary>
        /// <param name="thisObject">Tour object</param>
        /// <param name="contentDetail">content Detail object</param>
        /// <returns>Tour instance</returns>
        public static TourModel SetValuesFrom(this TourModel thisObject, ContentDetails contentDetail)
        {
            if (contentDetail != null)
            {
                if (thisObject == null)
                {
                    thisObject = new TourModel();
                }

                var fileDetail = contentDetail.ContentData as FileDetail;

                thisObject.Title = contentDetail.Name;
                thisObject.TourUrl = fileDetail.AzureID.ToString();
                thisObject.ID = fileDetail.AzureID.ToString();
                thisObject.MSRComponentId = contentDetail.ID;
                thisObject.Description = HttpUtility.HtmlDecode(contentDetail.Description).GetTextFromHtmlString();

                thisObject.ThumbnailUrl = (contentDetail.Thumbnail != null && contentDetail.Thumbnail.AzureID != Guid.Empty) ? contentDetail.Thumbnail.AzureID.ToString() : null;
                thisObject.LengthInSecs = contentDetail.TourLength;
                thisObject.AverageRating = contentDetail.AverageRating.ToString(CultureInfo.InvariantCulture);
                thisObject.Permission = contentDetail.UserPermission;

                // New fields
                thisObject.Author = HttpUtility.HtmlDecode(contentDetail.DistributedBy).GetTextFromHtmlString();
                thisObject.OrganizationName = string.Empty;
                thisObject.OrganizationUrl = string.Empty;
                thisObject.RelatedTours = string.Empty;
                thisObject.AuthorURL = contentDetail.CreatedByID.ToString(CultureInfo.InvariantCulture);
                thisObject.AuthorImageUrl = thisObject.AuthorURL;

                double tourDuration;
                if (Double.TryParse(contentDetail.TourLength, out tourDuration))
                {
                    var timeSpan = TimeSpan.FromSeconds(tourDuration);
                    thisObject.TourDuration = string.Format(CultureInfo.InvariantCulture, "{0:D2}:{1:D2}:{2:D2}", timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds);
                }
            }

            return thisObject;
        }
        /// <summary>
        /// Populates the PayloadDetails object's properties from the given collection of ContentsView object's properties.
        /// </summary>
        /// <param name="thisObject">PayloadDetails object</param>
        /// <param name="contents">ContentsView objects</param>
        /// <returns>PayloadDetails instance</returns>
        public static PayloadDetails SetValuesFrom(this PayloadDetails thisObject, IEnumerable<ContentsView> contents)
        {
            if (contents != null)
            {
                if (thisObject == null)
                {
                    thisObject = InitializePayload();
                }

                foreach (var content in contents)
                {
                    if (content.Filename.EndsWith(Constants.TourFileExtension, StringComparison.OrdinalIgnoreCase))
                    {
                        var tour = new TourModel();
                        tour.SetValuesFrom(content);
                        thisObject.Tours.Add(tour);
                    }
                    else if (content.Filename.EndsWith(Constants.CollectionFileExtension, StringComparison.OrdinalIgnoreCase))
                    {
                        var childCollection = new PayloadDetails();
                        childCollection.Name = content.Title;
                        childCollection.Id = content.ContentAzureID.ToString();
                        childCollection.MSRComponentId = content.ContentID;
                        childCollection.Group = "Explorer";
                        childCollection.IsCollection = true;
                        childCollection.Thumbnail = (content.ThumbnailID.HasValue && content.ThumbnailID != Guid.Empty) ? content.ThumbnailID.ToString() : null;

                        // Permissions for Content view are hard-coded to Read as it is used for browse
                        childCollection.Permission = Permission.Reader;
                        thisObject.Children.Add(childCollection);
                    }
                    else
                    {
                        var place = new Place();
                        place.SetValuesFrom(content);
                        thisObject.Links.Add(place);
                    }
                }
            }

            return thisObject;
        }