protected void LessonRepeater_ItemCommand(object source, RepeaterCommandEventArgs e) { ApplicationDbContext dbContext = new ApplicationDbContext(); int lessonId = int.Parse(e.CommandArgument.ToString()); Lesson lesson = dbContext.Lessons.Where(l => l.Id == lessonId).FirstOrDefault(); LessonTitleLabel.Text = lesson.Title; try { LessonContentLabel.Text = BBCode.ToHtml(lesson.Content); } catch { LessonContentLabel.Text = "Some tags did not load correctly<br />" + lesson.Content; } Session["CurrentLesson"] = lesson; //currentLesson = lesson; LessonAttachmentRepeater.DataBind(); HomePanel.Visible = false; LessonPanel.Visible = true; ActivePanelLabel.Text = "Lessons"; }
protected void DeleteLessonLink_Click(object sender, EventArgs e) { ApplicationDbContext dbContext = new ApplicationDbContext(); Lesson lesson = (Lesson)Session["CurrentLesson"]; dbContext.Lessons.Remove(dbContext.Lessons.Where(l => l.Id == lesson.Id).FirstOrDefault()); dbContext.SaveChanges(); LessonTitleLabel.Text = ""; LessonContentLabel.Text = ""; LessonRepeater.DataBind(); LessonAttachmentRepeater.DataBind(); HomePanel.Visible = false; LessonPanel.Visible = true; ActivePanelLabel.Text = "Lessons"; }
protected void LessonAttachmentButton_Click(object sender, EventArgs e) { if (LessonAttachmentUpload.HasFile) { try { ApplicationDbContext dbContext = new ApplicationDbContext(); string fileName = Path.GetFileName(LessonAttachmentUpload.FileName); string fileType = Path.GetExtension(fileName).Replace(".", ""); LessonAttachment lessonAttachment = new LessonAttachment(); lessonAttachment.Title = LessonAttachmentUpload.FileName; lessonAttachment.FileType = fileType; lessonAttachment.Data = LessonAttachmentUpload.FileBytes; Lesson CurrentLesson = (Lesson)Session["CurrentLesson"]; lessonAttachment.Lesson = dbContext.Lessons.Where(l => l.Id == CurrentLesson.Id).FirstOrDefault(); dbContext.LessonAttachments.Add(lessonAttachment); dbContext.SaveChanges(); LessonAttachmentRepeater.DataBind(); HomePanel.Visible = false; LessonPanel.Visible = true; ActivePanelLabel.Text = "Lessons"; } catch { } } }