protected void Grid_ItemCommand(object sender, DataGridCommandEventArgs e) { if ("Edit".Equals(e.CommandName)) { int primaryKey = (int)this.Grid.DataKeys[e.Item.ItemIndex]; this.OnEdit(CourseLogic.GetByID(this.DataContext, primaryKey)); } else if ("Delete".Equals(e.CommandName)) { int primaryKey = (int)this.Grid.DataKeys[e.Item.ItemIndex]; this.OnDelete(CourseLogic.GetByID(this.DataContext, primaryKey)); } }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); string idString = this.Request.QueryString["ID"]; int id; if (int.TryParse(idString, out id)) { this.Course = CourseLogic.GetByID(this.DataContext, id); if (!this.IsPostBack) { this.EditControl.DataBind(this.Course); } } }
protected void SaveButton_Click(object sender, EventArgs e) { if (this.ObjectID.HasValue) { Course obj = CourseLogic.GetByID(this.DataContext, this.ObjectID.Value); obj.SemesterID = int.Parse(this.SemesterField.SelectedValue); obj.TeacherID = int.Parse(this.TeacherField.SelectedValue); obj.Number = this.NumberField.Text; obj.Name = this.NameField.Text; obj.Status = (DataAccess.CourseStatus)Enum.Parse(typeof(DataAccess.CourseStatus), this.CourseStatusField.SelectedValue); this.DataContext.AcceptAllChanges(); OnSaved(obj); } else { Course obj = CourseLogic.CreateCourse(this.DataContext, int.Parse(this.SemesterField.SelectedValue), int.Parse(this.TeacherField.SelectedValue), this.NumberField.Text, this.NameField.Text, (DataAccess.CourseStatus)Enum.Parse(typeof(DataAccess.CourseStatus), this.CourseStatusField.SelectedValue)); this.DataContext.AcceptAllChanges(); OnSaved(obj); } }
/// <summary>Gets the Course with the specified primary key.</summary> /// <param name="id">The primary key of the Course to return.</param> /// <returns>The matching Course, if one exists, or null.</returns> public SO.Course GetCourseByID(int id) { return(SO.Course.FromDataAccessObject(CourseLogic.GetByID(id))); }
/// <summary>Gets the Course with the specified primary key.</summary> /// <param name="id">The primary key of the Course to return.</param> /// <returns>The matching Course, if one exists, or null.</returns> public SO.Course GetCourseByID(string id) { return(SO.Course.FromDataAccessObject(CourseLogic.GetByID(ParseInt("id", id)))); }