コード例 #1
0
        public static PortfolioItemViewModel ToViewModel(this PortfolioItem portfolioItem, ICollection <Tag> allDbTags)
        {
            var userProfileViewModel = new PortfolioItemViewModel
            {
                Title       = portfolioItem.Title,
                ID          = portfolioItem.ID,
                Description = portfolioItem.Description,
                ProjcetUrl  = portfolioItem.ProjcetUrl,
                Image       = portfolioItem.Image
            };

            // Collection for full list of tags with portfolioItems's already assigned tags included
            ICollection <AssignedTags> allTags = new List <AssignedTags>();

            foreach (var t in allDbTags)
            {
                // Create new AssignedTag for each tagrse and set Assigned = true if portfolioItem already has tag
                var assignedTags = new AssignedTags
                {
                    ID       = t.ID,
                    Name     = t.Name,
                    Assigned = portfolioItem.Tags.FirstOrDefault(x => x.ID == t.ID) != null
                };

                allTags.Add(assignedTags);
            }

            userProfileViewModel.Tags = allTags;

            return(userProfileViewModel);
        }
コード例 #2
0
        public static PortfolioItemViewModel ToViewModel(this PortfolioItem portfolioItem, ICollection<Tag> allDbTags)
        {
            var userProfileViewModel = new PortfolioItemViewModel
            {
                Title = portfolioItem.Title,
                ID = portfolioItem.ID,
                Description = portfolioItem.Description,
                ProjcetUrl = portfolioItem.ProjcetUrl,
                Image = portfolioItem.Image
            };

            // Collection for full list of tags with portfolioItems's already assigned tags included
            ICollection<AssignedTags> allTags = new List<AssignedTags>();

            foreach (var t in allDbTags)
            {
                // Create new AssignedTag for each tagrse and set Assigned = true if portfolioItem already has tag
                var assignedTags = new AssignedTags
                {
                    ID = t.ID,
                    Name = t.Name,
                    Assigned = portfolioItem.Tags.FirstOrDefault(x => x.ID == t.ID) != null
                };

                allTags.Add(assignedTags);
            }

            userProfileViewModel.Tags = allTags;

            return userProfileViewModel;
        }