Пример #1
0
        public void GridViewLectures_DeleteItem(int id)
        {
            var context = new AcademyDbContext();

            Forum.Models.Lecture item = context.Lectures.Find(id);
            if (item == null)
            {
                ModelState.AddModelError("", String.Format("Item with id {0} was not found", id));
                ErrorSuccessNotifier.AddErrorMessage("The lecture was not found.");
                return;
            }

            try
            {
                context.Lectures.Remove(item);
                context.SaveChanges();

                this.GridViewLectures.SelectMethod = "GridViewLectures_GetData";
                this.GridViewLectures.DataBind();
                ErrorSuccessNotifier.AddInfoMessage("Lecture deleted successfully.");
            }
            catch (Exception ex)
            {
                ErrorSuccessNotifier.AddErrorMessage(ex.Message);
            }
        }
Пример #2
0
        protected void LinkButtonEmptyLectureInsert_Click(object sender, EventArgs e)
        {
            int      courseId        = Convert.ToInt32(this.RouteData.Values["courseId"]);
            var      table           = (sender as LinkButton).Parent;
            string   title           = (table.FindControl("TextBoxEmptyLectureTitleInsert") as TextBox).Text;
            string   description     = (table.FindControl("TextBoxEmptyLectureLocationInsert") as TextBox).Text;
            string   location        = (table.FindControl("TextBoxEmptyLectureLocationInsert") as TextBox).Text;
            DateTime homeworkDueDate = DateTime.Parse((table.FindControl("TextBoxEmptyHomeworkDue") as TextBox).Text);

            var context = new AcademyDbContext();
            var course  = context.Courses.Find(courseId);
            var lecture = new Forum.Models.Lecture()
            {
                Title           = title,
                Location        = location,
                HomeworkDueDate = homeworkDueDate
            };

            context.Lectures.Add(lecture);
            try
            {
                context.SaveChanges();
                lecture.Course = course;
                context.SaveChanges();
                ErrorSuccessNotifier.AddSuccessMessage("Lecture created successfully.");
            }
            catch (Exception ex)
            {
                ErrorSuccessNotifier.AddErrorMessage(ex.Message);
            }

            this.GridViewLectures.SelectMethod = "GridViewLectures_GetData";
            this.GridViewLectures.DataBind();
        }
Пример #3
0
        public void GridViewLectures_UpdateItem(int id)
        {
            var context = new AcademyDbContext();

            Forum.Models.Lecture item = context.Lectures.Find(id);
            if (item == null)
            {
                ModelState.AddModelError("", String.Format("Item with id {0} was not found", id));
                return;
            }

            TryUpdateModel(item);
            if (ModelState.IsValid)
            {
                context.SaveChanges();
                ErrorSuccessNotifier.AddInfoMessage("Lecture updated successfully.");
            }
            else
            {
                ErrorSuccessNotifier.AddErrorMessage("There was an error updating the lecture. Please try again.");
            }
        }
        protected void ButtonInsertLecture_Click(object sender, EventArgs e)
        {
            int courseId = Convert.ToInt32(this.RouteData.Values["courseId"]);
            string title = (this.GridViewLectures.FooterRow.FindControl("TextBoxInsertTitle") as TextBox).Text;
            string location = (this.GridViewLectures.FooterRow.FindControl("TextBoxInsertLocation") as TextBox).Text;
            DateTime homeworkDueDate = DateTime.Parse((this.GridViewLectures.FooterRow.FindControl("TextBoxInsertHomeworkDue") as TextBox).Text);

            var context = new AcademyDbContext();
            var course = context.Courses.Find(courseId);
            var lecture = new Forum.Models.Lecture()
            {
                Title = title,
                Location = location,
                HomeworkDueDate = homeworkDueDate
            };

            context.Lectures.Add(lecture);
            try
            {
                context.SaveChanges();
                lecture.Course = course;
                context.SaveChanges();
                ErrorSuccessNotifier.AddSuccessMessage("Lecture created successfully.");
            }
            catch (Exception ex)
            {
                ErrorSuccessNotifier.AddErrorMessage(ex.Message);
            }

            this.GridViewLectures.SelectMethod = "GridViewLectures_GetData";
            this.GridViewLectures.DataBind();
        }