Example #1
0
 public void Create(Models.Article article)
 {
     using (var context = new ArticlesContext())
     {
         context.Articles.Add(article);
         context.SaveChanges();
     }
 }
Example #2
0
 public Question GetQuestion(int id)
 {
     using (var context = new ArticlesContext())
     {
         var question = context.Questions.Single(q => q.QuestionId == id);
         return(question);
     }
 }
Example #3
0
 public Account GetAccount(string username)
 {
     using (var context = new ArticlesContext())
     {
         var account = context.Accounts.Single(a => a.Name == username);
         return(account);
     }
 }
Example #4
0
 public Models.Tag Get(int id)
 {
     using (var context = new ArticlesContext())
     {
         var tag = context.Tags.Single(a => a.TagId == id);
         return(tag);
     }
 }
Example #5
0
 public List <Models.Tag> GetAll()
 {
     using (var context = new ArticlesContext())
     {
         var tags = context.Tags.ToList();
         return(tags);
     }
 }
Example #6
0
 public Models.Article GetArticle(int id)
 {
     using (var context = new ArticlesContext())
     {
         var article = context.Articles.Single(a => a.ArticleId == id);
         return(article);
     }
 }
Example #7
0
 public void Create(Question question)
 {
     using (var context = new ArticlesContext())
     {
         context.Questions.Add(question);
         context.SaveChanges();
     }
 }
Example #8
0
 public List <Question> GetArticleQuestions(int articleId)
 {
     using (var context = new ArticlesContext())
     {
         var questions = context.Questions.Where(q => q.ArticleId == articleId).ToList();
         return(questions);
     }
 }
Example #9
0
 public int GetArticleId(string author)
 {
     using (var context = new ArticlesContext())
     {
         var id = context.Articles.OrderByDescending(p => p.ArticleId).Where(p => p.Author == author).Select(p => p.ArticleId).FirstOrDefault();
         return(id);
     }
 }
Example #10
0
 public Models.ArticleCard GetCard(int id)
 {
     using (var context = new ArticlesContext())
     {
         var card = new Models.ArticleCard(context.Articles.Single(a => a.ArticleId == id));
         return(card);
     }
 }
Example #11
0
 public void Create(Models.Tag tag)
 {
     using (var context = new ArticlesContext())
     {
         context.Tags.Add(tag);
         context.SaveChanges();
     }
 }
Example #12
0
 public List <Models.Article> GetAll()
 {
     using (var context = new ArticlesContext())
     {
         var articles = context.Articles.ToList();
         return(articles);
     }
 }
Example #13
0
 public void CreateAccount(Account account)
 {
     using (var context = new ArticlesContext())
     {
         account.Points = 0;
         context.Accounts.Add(account);
         context.SaveChanges();
     }
 }
Example #14
0
        public void QuestionAnswered(string username, int questionID)
        {
            AnsweredQuestion answeredQuestion = new AnsweredQuestion(username, questionID);

            using (var context = new ArticlesContext())
            {
                context.AnsweredQuestions.Add(answeredQuestion);
                context.SaveChanges();
            }
        }
Example #15
0
        public void AddScore(Account account, int points)
        {
            using (var context = new ArticlesContext())
            {
                var dbUser = context.Accounts.Single(a => a.AccountID == account.AccountID);

                dbUser.Points = dbUser.Points + points;

                context.SaveChanges();
            }
        }
Example #16
0
        public void Update(Models.Article article)
        {
            using (var context = new ArticlesContext())
            {
                var dbArticle = context.Articles.Single(a => a.ArticleId == article.ArticleId);

                dbArticle.Author      = article.Author;
                dbArticle.Summary     = article.Summary;
                dbArticle.Tag         = article.Tag;
                dbArticle.Title       = article.Title;
                dbArticle.HeaderImage = article.HeaderImage;
                dbArticle.Content     = article.Content;

                context.SaveChanges();
            }
        }
Example #17
0
        public List <Models.ArticleCard> GetAllCards()
        {
            using (var context = new ArticlesContext())
            {
                var articles = context.Articles.ToList();

                //articles omzetten naar cards
                List <Models.ArticleCard> cards = new List <Models.ArticleCard>();
                foreach (Models.Article article in articles)
                {
                    Models.ArticleCard card = new Models.ArticleCard(article);
                    cards.Add(card);
                }
                return(cards);
            }
        }
Example #18
0
 public void Delete(int id)
 {
     using (var context = new ArticlesContext())
     {
         try {
             var tag = context.Tags.Single(a => a.TagId == id);
             context.Tags.Attach(tag);
             context.Tags.Remove(tag);
             context.SaveChanges();
         }
         catch
         {
             return;
         }
     }
 }
Example #19
0
 public void DeleteArticle(int id)
 {
     using (var context = new ArticlesContext())
     {
         try {
             var article = context.Articles.Single(a => a.ArticleId == id);
             context.Articles.Attach(article);
             context.Articles.Remove(article);
             context.SaveChanges();
         }
         catch
         {
             return;
         }
     }
 }
Example #20
0
        public bool QuestionIsAlreadyAnswered(string username, int questionID)
        {
            AnsweredQuestion answeredQuestion = new AnsweredQuestion(username, questionID);

            using (var context = new ArticlesContext())
            {
                if (context.AnsweredQuestions.Any(a => a.Username == answeredQuestion.Username && a.QuestionID == answeredQuestion.QuestionID))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }