예제 #1
0
    protected void DeleteArticleLink_Command(object sender, CommandEventArgs e)
    {
        ApplicationDbContext dbContext = new ApplicationDbContext();

        int articleId = int.Parse(e.CommandArgument.ToString());

        CourseArticle courseArticle = dbContext.CourseArticles.Where(c => c.Id == articleId).FirstOrDefault();

        dbContext.CourseArticles.Remove(courseArticle);
        dbContext.SaveChanges();

        CourseArticleRepeater.DataBind();
    }
예제 #2
0
    protected void NewArticleButton_Click(object sender, EventArgs e)
    {
        ApplicationDbContext dbContext = new ApplicationDbContext();

        CourseArticle courseArticle = new CourseArticle();

        courseArticle.Title    = NewArticleTitle.Text;
        courseArticle.Content  = NewArticleContent.Text;
        courseArticle.PostedOn = DateTime.Now;
        courseArticle.Author   = dbContext.Members.Where(m => m.Id == member.Id).FirstOrDefault();
        courseArticle.Course   = dbContext.Courses.Where(c => c.Id == course.Id).FirstOrDefault();

        dbContext.CourseArticles.Add(courseArticle);

        dbContext.SaveChanges();

        CourseArticleRepeater.DataBind();

        NewArticleTitle.Text   = "";
        NewArticleContent.Text = "";
    }