예제 #1
0
 public void Create(Models.Tag tag)
 {
     using (var context = new ArticlesContext())
     {
         context.Tags.Add(tag);
         context.SaveChanges();
     }
 }
예제 #2
0
 public void Create(Question question)
 {
     using (var context = new ArticlesContext())
     {
         context.Questions.Add(question);
         context.SaveChanges();
     }
 }
예제 #3
0
 public void Create(Models.Article article)
 {
     using (var context = new ArticlesContext())
     {
         context.Articles.Add(article);
         context.SaveChanges();
     }
 }
예제 #4
0
 public void CreateAccount(Account account)
 {
     using (var context = new ArticlesContext())
     {
         account.Points = 0;
         context.Accounts.Add(account);
         context.SaveChanges();
     }
 }
예제 #5
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();
            }
        }
예제 #6
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();
            }
        }
예제 #7
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;
         }
     }
 }
예제 #8
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();
            }
        }
예제 #9
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;
         }
     }
 }