/// <summary>
        /// Populates the EntityViewModel object's properties from the given EntityDetail object's properties.
        /// </summary>
        /// <param name="thisObject">Current entity view model on which the extension method is called</param>
        /// <param name="entityDetails">EntityDetails model from which values to be read</param>
        /// <returns>Values populated EntityViewModel instance</returns>
        public static EntityViewModel SetValuesFrom(this EntityViewModel thisObject, EntityDetails entityDetails)
        {
            if (entityDetails != null)
            {
                if (thisObject == null)
                {
                    thisObject = new EntityViewModel();
                }

                thisObject.Id = entityDetails.ID;
                thisObject.Name = entityDetails.Name;

                // Parse the category string
                thisObject.Category = entityDetails.CategoryID.ToEnum<int, CategoryType>(CategoryType.All);
                thisObject.AccessType = (AccessType)entityDetails.AccessTypeID;

                thisObject.ParentId = entityDetails.ParentID;
                thisObject.ParentName = entityDetails.ParentName;
                thisObject.ParentType = entityDetails.ParentType;
                thisObject.UserPermission = entityDetails.UserPermission;

                if (entityDetails.Tags != null)
                {
                    thisObject.Tags = entityDetails.Tags;
                }

                thisObject.Rating = (double)entityDetails.AverageRating;
                thisObject.RatedPeople = entityDetails.RatedPeople;
                if (entityDetails.Thumbnail != null)
                {
                    thisObject.ThumbnailID = entityDetails.Thumbnail.AzureID;
                }

                thisObject.Producer = entityDetails.ProducedBy;
                thisObject.ProducerId = entityDetails.CreatedByID;
            }

            return thisObject;
        }
Пример #2
0
        /// <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();
        }