public int GetSubscriberCount(Channel channel)
 {
     using (var context = new PhotoChannelContext())
     {
         return(context.Subscribers.Count(subscriber => subscriber.ChannelId == channel.Id));
     }
 }
 public int GetSubscriptionsCount(User user)
 {
     using (var context = new PhotoChannelContext())
     {
         return(context.Subscribers.Count(subscriber => subscriber.UserId == user.Id));
     }
 }
 public int GetPhotoCommentCount(Photo photo)
 {
     using (var context = new PhotoChannelContext())
     {
         return(context.Comments.Count(comment => comment.PhotoId == photo.Id));
     }
 }
 public int GetPhotoLikeCount(Photo photo)
 {
     using (var context = new PhotoChannelContext())
     {
         return(context.Likes.Count(like => like.PhotoId == photo.Id));
     }
 }
Beispiel #5
0
        public List <Channel> SearchByMultiCategory(int[] categoryIds)
        {
            using (var context = new PhotoChannelContext())
            {
                var result = context.ChannelCategories.Include(c => c.Channel).Include(category => category.Channel.User).Where(c => categoryIds.Contains(c.CategoryId)).Select(c => c.Channel).Distinct();

                return(result.ToList());
            }
        }
Beispiel #6
0
        public List <Channel> SearchByCategory(int categoryId)
        {
            using (var context = new PhotoChannelContext())
            {
                var result = context.ChannelCategories.Include(c => c.Channel).Include(category => category.Channel.User).Where(c => c.CategoryId == categoryId).Select(c => c.Channel);

                return(result.ToList());
            }
        }
Beispiel #7
0
 public Tuple <List <User>, List <Channel> > SearchByText(string text)
 {
     using (var context = new PhotoChannelContext())
     {
         Tuple <List <User>, List <Channel> > tuple = new Tuple <List <User>, List <Channel> >(
             context.Users.Where(u => u.FirstName.Contains(text) || u.LastName.Contains(text) || u.UserName.Contains(text)).Take(5).ToList(),
             context.Channels.Where(c => c.Name.Contains(text)).Take(5).ToList()
             );
         return(tuple);
     }
 }
Beispiel #8
0
 public List <Photo> GetFeed(int userId)
 {
     using (var context = new PhotoChannelContext())
     {
         List <Photo> photos = new List <Photo>();
         context.Subscribers.Where(subscriber => subscriber.UserId == userId).ToList().ForEach(subscriber =>
         {
             photos.AddRange(context.Photos.Include(photo => photo.Channel).Include(photo => photo.User).Where(photo => photo.ChannelId == subscriber.ChannelId).ToList());
         });
         return(photos.OrderByDescending(photo => photo.ShareDate).ToList());
     }
 }
Beispiel #9
0
 public List <Photo> GetMostPhotos()
 {
     using (var context = new PhotoChannelContext())
     {
         Dictionary <Photo, int> dictionary = new Dictionary <Photo, int>();
         context.Photos.Include(photo => photo.Channel).Include(photo => photo.User).ToList().ForEach(photo =>
         {
             dictionary.Add(photo,
                            context.Likes.Count(like => like.PhotoId == photo.Id));
         });
         return(dictionary.OrderByDescending(pair => pair.Value).Take(10).Select(pair => pair.Key).ToList());
     }
 }
Beispiel #10
0
 public List <Channel> GetMostChannels()
 {
     using (var context = new PhotoChannelContext())
     {
         Dictionary <Channel, int> dictionary = new Dictionary <Channel, int>();
         context.Channels.ToList().ForEach(channel =>
         {
             dictionary.Add(channel,
                            context.Subscribers.Count(subscriber => subscriber.ChannelId == channel.Id));
         });
         return(dictionary.OrderByDescending(pair => pair.Value).Take(5).Select(pair => pair.Key).ToList());
     }
 }