Example #1
0
 public Article GetArticle(int id)
 {
     using (DBContextDataContext context = new DBContextDataContext(_connectionString))
     {
         return(context.Articles.FirstOrDefault(A => A.Id == id));
     }
 }
 public User GetUserByEmail(string email)
 {
     using (DBContextDataContext context = new DBContextDataContext(_connectionString))
     {
         return(context.Users.FirstOrDefault(U => U.Email == email));
     }
 }
Example #3
0
 public void AddComment(Comment comment)
 {
     using (DBContextDataContext context = new DBContextDataContext(_connectionString))
     {
         context.Comments.InsertOnSubmit(comment);
         context.SubmitChanges();
     }
 }
Example #4
0
 public void InsertLike(Like like)
 {
     using (DBContextDataContext context = new DBContextDataContext(_connectionString))
     {
         context.Likes.InsertOnSubmit(like);
         context.SubmitChanges();
     }
 }
Example #5
0
 public void AddArticle(Article article)
 {
     using (DBContextDataContext context = new DBContextDataContext(_connectionString))
     {
         context.Articles.InsertOnSubmit(article);
         context.SubmitChanges();
     }
 }
Example #6
0
 public List <Comment> Comments(int id)
 {
     using (DBContextDataContext context = new DBContextDataContext(_connectionString))
     {
         var LoadOptions = new DataLoadOptions();
         LoadOptions.LoadWith <Comment>(C => C.User);
         LoadOptions.LoadWith <Comment>(C => C.Article);
         context.LoadOptions = LoadOptions;
         return(context.Comments.Where(C => C.ArticleId == id).ToList());
     }
 }
Example #7
0
        public List <ArticlePlus> GetAllArticls()
        {
            using (DBContextDataContext context = new DBContextDataContext(_connectionString))
            {
                var LoadOptions = new DataLoadOptions();
                LoadOptions.LoadWith <Article>(A => A.User);
                LoadOptions.LoadWith <Article>(A => A.Likes);
                LoadOptions.LoadWith <Article>(A => A.Comments);
                context.LoadOptions = LoadOptions;

                IEnumerable <Article> articles = context.Articles;

                List <ArticlePlus> ArticleWithVoteCount = GetArticlesWithVoteCount(context.Articles.ToList());
                return(ArticleWithVoteCount);
            }
        }
 public string AddUser(User user)
 {
     if (GetUserByEmail(user.Email) != null)
     {
         return(null);
     }
     //this was done in controller
     //user.PasswordSalt = PasswordHelper.GenerateSalt();
     //user.PasswordHash = PasswordHelper.HashPassword(password, user.PasswordSalt);
     using (DBContextDataContext context = new DBContextDataContext(_connectionString))
     {
         context.Users.InsertOnSubmit(user);
         context.SubmitChanges();
         return("User Added");
     }
 }