public int SaveChanges(bool IsNewRecord) { string NewsTitle = ""; Courses ObjTable; if (IsNewRecord) { ObjTable = new Courses(); dataContext.Courses.InsertOnSubmit(ObjTable); } else { ObjTable = dataContext.Courses.Single(p => p.Code.Equals(this.Code)); } try { #region Save Controls string BaseID = this.ToString().Substring(3, this.ToString().Length - 3); Tools tools = new Tools(); tools.AccessList = tools.GetAccessList(BaseID); foreach (WebControl wc in ObjectList) { string Property = wc.ID.Substring(3, wc.ID.Length - 3); PropertyInfo pi = ObjTable.GetType().GetProperty(Property); string FullPropName = BaseID + "." + Property; if (tools.HasAccess("Edit", BaseID + "." + Property)) { pi.SetValue(ObjTable, Tools.GetControlValue(wc), new object[] { }); } if (Property == "Title") { NewsTitle = ((TextBox)wc).Text; } } #endregion if (tools.HasAccess("Edit", "Courses")) { dataContext.SubmitChanges(); } } catch (Exception exp) { throw exp; } if (IsNewRecord) { BOLNews NewsBOL = new BOLNews(); NewsBOL.Insert(NewsTitle, "Courses.aspx"); } return(ObjTable.Code); }