public static bool ValidateData()
 {
     using (var context = new NewsFeedDBEntities())
     {
         return(context.NewsFeed.Any());
     }
 }
Esempio n. 2
0
 public static Users Login(Users user)
 {
     using (var context = new NewsFeedDBEntities())
     {
         return(context.Users.Where(x => x.UserName == user.UserName && user.Password == user.Password).FirstOrDefault());
     }
 }
Esempio n. 3
0
 public static List <Feed> RetrieveFeedByUser(int userId)
 {
     using (var context = new NewsFeedDBEntities())
     {
         return(context.Feed.Where(x => x.CreatedBy == userId).ToList());
     }
 }
Esempio n. 4
0
 public static List <Feed> RetrieveFeed()
 {
     using (var context = new NewsFeedDBEntities())
     {
         return(context.Feed.Where(x => x.Active == true).ToList());
     }
 }
 public static List <NewsFeed> RetrieveNewsFeedById(int id)
 {
     using (var context = new NewsFeedDBEntities())
     {
         return(context.NewsFeed.Where(x => x.Active == true && x.FeedId == id).Include(x => x.Users).Include(a => a.Feed).ToList());
     }
 }
        public static void InsertDefaultData()
        {
            using (var context = new NewsFeedDBEntities())
            {
                var user = new Users {
                    Name = "Default", Password = "******"
                };
                context.Users.Add(user);
                context.SaveChanges();

                var feed = new Feed {
                    Name = "Sports", CreateDate = DateTime.Now, CreatedBy = user.Id, Active = true
                };
                context.Feed.Add(feed);
                context.SaveChanges();
                context.NewsFeed.Add(new NewsFeed {
                    Title = "Football", Description = "World Cup Qatar 2022 is comming.", CreateDate = DateTime.Now, CreatedBy = user.Id, Active = true, FeedId = feed.Id
                });
                context.NewsFeed.Add(new NewsFeed {
                    Title = "Baseball", Description = "The official news source of Major League Baseball.", CreateDate = DateTime.Now, CreatedBy = user.Id, Active = true, FeedId = feed.Id
                });
                context.NewsFeed.Add(new NewsFeed {
                    Title = "Voleyball", Description = "Volleyball news, interviews, transfers, videos and more.", CreateDate = DateTime.Now, CreatedBy = user.Id, Active = true, FeedId = feed.Id
                });
                context.SaveChanges();

                feed = new Feed {
                    Name = "Food", CreateDate = DateTime.Now, CreatedBy = user.Id, Active = true
                };
                context.Feed.Add(feed);
                context.SaveChanges();
                context.NewsFeed.Add(new NewsFeed {
                    Title = "Chinese", Description = "Find out what Chinese dishes to try in China, soon!", CreateDate = DateTime.Now, CreatedBy = user.Id, Active = true, FeedId = feed.Id
                });
                context.NewsFeed.Add(new NewsFeed {
                    Title = "Mexican", Description = "All the latest breaking news on Mexican Food.", CreateDate = DateTime.Now, CreatedBy = user.Id, Active = true, FeedId = feed.Id
                });
                context.NewsFeed.Add(new NewsFeed {
                    Title = "Fast food", Description = "KFC hints at plan for plant-based chicken alternative.", CreateDate = DateTime.Now, CreatedBy = user.Id, Active = true, FeedId = feed.Id
                });
                context.SaveChanges();

                feed = new Feed {
                    Name = "Vacations", CreateDate = DateTime.Now, CreatedBy = user.Id, Active = true
                };
                context.Feed.Add(feed);
                context.SaveChanges();
                context.NewsFeed.Add(new NewsFeed {
                    Title = "Costa Rica", Description = "All the latest breaking news on Costa Rica travel.", CreateDate = DateTime.Now, CreatedBy = user.Id, Active = true, FeedId = feed.Id
                });
                context.NewsFeed.Add(new NewsFeed {
                    Title = "Grand Canyon", Description = "If you want to really explore the Grand Canyon, you need to plan a day trip on your next vacation in Vegas.", CreateDate = DateTime.Now, CreatedBy = user.Id, Active = true, FeedId = feed.Id
                });
                context.NewsFeed.Add(new NewsFeed {
                    Title = "Mexico", Description = "Cancun ranks as the top international destination this holiday season for U.S. travelers.", CreateDate = DateTime.Now, CreatedBy = user.Id, Active = true, FeedId = feed.Id
                });
                context.SaveChanges();
            }
        }
Esempio n. 7
0
 public static void AddSubscription(Subscription model)
 {
     using (var context = new NewsFeedDBEntities())
     {
         context.Subscription.Add(model);
         context.SaveChanges();
     }
 }
Esempio n. 8
0
 public static void AddFeed(Feed model)
 {
     using (var context = new NewsFeedDBEntities())
     {
         context.Feed.Add(model);
         context.SaveChanges();
     }
 }
 public static void AddNewsFeed(NewsFeed newsFeed)
 {
     using (var context = new NewsFeedDBEntities())
     {
         context.NewsFeed.Add(newsFeed);
         context.SaveChanges();
     }
 }
Esempio n. 10
0
 public static Users Register(Users user)
 {
     using (var context = new NewsFeedDBEntities())
     {
         context.Users.Add(user);
         context.SaveChanges();
         return(user);
     }
 }
Esempio n. 11
0
 public static void RemoveSubscription(Subscription model)
 {
     using (var context = new NewsFeedDBEntities())
     {
         var sub = context.Subscription.Where(x => x.UserId == model.UserId && x.FeedId == model.FeedId).FirstOrDefault();
         context.Subscription.Remove(sub);
         context.SaveChanges();
     }
 }
Esempio n. 12
0
 public static List <Feed> RetrieveFeedSubscriptions(int userId)
 {
     using (var context = new NewsFeedDBEntities())
     {
         var subscriptions = (from feed in context.Feed
                              join subs in context.Subscription on feed.Id equals subs.FeedId
                              where feed.Id == subs.FeedId && subs.UserId == userId
                              select feed).ToList();
         return(subscriptions);
     }
 }
        public static List <NewsFeed> SearchNewsFeed(string searchText)
        {
            using (var context = new NewsFeedDBEntities())
            {
                var news = context.NewsFeed.Where(x => x.Active == true).Include(x => x.Users).Include(a => a.Feed).ToList();

                return(news.Where(x => x.Title.ToLower().Contains(searchText.ToLower()) ||
                                  x.Description.ToLower().Contains(searchText.ToLower()) ||
                                  x.Users.Name.ToLower().Contains(searchText.ToLower()) ||
                                  x.Feed.Name.ToLower().Contains(searchText.ToLower())
                                  ).ToList());
            }
        }