Esempio n. 1
0
        public static TagCountViewModel TagsAndCount(int movieID)
        {
            MovieDbContext    db      = new MovieDbContext();
            TagCountViewModel tagView = new TagCountViewModel()
            {
                TagAndCount = new Dictionary <string, int>()
            };

            //find the ids of the tags related to the movie
            var tagsForMovie = from MtT in db.UserToMovieToTags
                               where MtT.movie_ID == movieID
                               select MtT.TagId;

            //find the tag string based on the id of the strings
            var tagStrings = from tag in db.MovieTags
                             from tag_id in tagsForMovie
                             where tag.TagId == tag_id
                             select tag.Name;

            var tagCounts = from tagString in db.MovieTags
                            where tagStrings.Contains(tagString.Name)
                            from MtT in db.UserToMovieToTags
                            where MtT.TagId == tagString.TagId
                            group MtT.TagId by tagString.Name
                            into grouping
                            select grouping;

            foreach (IGrouping <string, int> result in tagCounts)
            {
                tagView.TagAndCount.Add(result.Key, result.Count());
            }


            return(tagView);
        }
Esempio n. 2
0
 public static TagCount ToEntity(this TagCountViewModel obj)
 {
     return(new TagCount()
     {
         Count = obj.Count,
         Tag = obj.Tag.ToEntity()
     });
 }
Esempio n. 3
0
        private TagCountViewModel TagsAndCounts()
        {
            MovieDbContext    db      = new MovieDbContext();
            TagCountViewModel tagView = new TagCountViewModel()
            {
                TagAndCount = new Dictionary <string, int>()
            };

            //find the ids of the tags related to the movie
            //var tagsForMovie = from MtT in db.UserToMovieToTags
            //                   where MtT.movie_ID == movieID
            //                   select MtT.TagId;

            //find the tag string based on the id of the strings
            var tagStrings = from tag in db.MovieTags
                             //from tag_id in tagsForMovie
                             //where tag.TagId == tag_id
                             select tag.Name;

            var tagCounts = from tagString in db.MovieTags
                            where tagStrings.Contains(tagString.Name)
                            from MtT in db.UserToMovieToTags
                            where MtT.TagId == tagString.TagId
                            group MtT.TagId by tagString.Name
                            into grouping
                            select grouping;

            foreach (IGrouping <string, int> result in tagCounts)
            {
                tagView.TagAndCount.Add(result.Key, result.Count());
            }


            return(tagView);

            /*
             * var allTags = (from tagName in db.MovieTags
             *            from tagID in db.UserToMovieToTags
             *            where tagName.TagId == tagID.TagId
             *            group tagID.TagId by tagName.Name into grouping
             *            select grouping).ToDictionary(grp => grp.Key, grp => grp.Key.Count());
             *
             * return allTags; */
        }