View Code for Web/Courses/Default.aspx.cs

Source code for the file Web/Courses/Default.aspx.cs is shown below.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI.WebControls;
using QuantumConcepts.Common.Extensions;
using QuantumConcepts.CodeGenerator.Sample.DataAccess;
using QuantumConcepts.CodeGenerator.Sample.Logic;
using QuantumConcepts.CodeGenerator.Sample.Web.WebControls;
using QuantumConcepts.CommonWeb.WebControls;

namespace QuantumConcepts.CodeGenerator.Sample.Web.Courses
{
	public partial class Default : BasePage
	{
        protected CourseList ListControl;
        
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (!this.IsPostBack)
                BindList();
        }

        protected void ListControl_NeedsDataBinding(object sender, EventArgs e)
        {
            BindList();
        }

        protected void ListControl_Edit(object sender, Course obj)
        {
            Response.Redirect("Edit.aspx?ID={0}".FormatString(obj.ID));
        }

        protected void ListControl_Delete(object sender, Course obj)
        {
            CourseLogic.DeleteCourse(this.DataContext, obj.ID);
            this.DataContext.SubmitChanges();
            BindList();
        }

        private void BindList()
        {
            ListControl.DataBind(CourseLogic.GetAll().ToList());
        }
    }
}