public static int SaveObject(route_table MyObject) { //get method name string MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name; //initialize entities var ctx = new rentalanguageteacherEntities(); { try { log.Debug(MethodName + "**********************************************************************************************************"); log.Debug(MethodName + "() - Start"); //Check object state, add or update if (MyObject.route_id == 0) { //Add new object ctx.route_table.Add(MyObject); log.Debug(MethodName + "() - New object added"); } else { //Update object ctx.Entry(MyObject).State = System.Data.EntityState.Detached; ctx.Entry(MyObject).State = System.Data.EntityState.Modified; // log.Debug(MethodName + "() - The object for ID " + MyObject.quick_registration_id + " was updated"); } //save context changes int num = ctx.SaveChanges(); //return? return(num); } catch (Exception e) { log.Error(MethodName + "() - " + e.Message); log.Debug(MethodName + "() - " + e.StackTrace); throw (e); } finally { log.Debug(MethodName + "() - Finish"); log.Debug(MethodName + "**********************************************************************************************************"); } } }
protected void btnNewCategory_Click(object sender, EventArgs e) { try { //Create and Save new Category contentcategory NewCategory = new contentcategory(); NewCategory.category = txtNewCategory.Text.Trim().Replace(" ", ""); NewCategory.image = txtCategoryImage.Text.Trim(); NewCategory.description = txtCategoryDescription.Text.Trim(); App_Code.ContentService.SaveCategory(NewCategory); //Clear form txtNewCategory.Text = ""; txtCategoryDescription.Text = ""; txtCategoryImage.Text = ""; //Save the new route to the DB route_table NewRoute = new route_table(); NewRoute.rout_name = NewCategory.category; NewRoute.rout_url = "" + NewCategory.category + "/{Language}/{Title}"; NewRoute.physical_file = "~/Pages/Content/Content.aspx"; App_Code.RoutingService.SaveObject(NewRoute); //Register the route for this run RouteTable.Routes.MapPageRoute("" + NewCategory.category + "-Route", "" + NewCategory.category + "/{Language}/{Title}", "~/Pages/Content/Content.aspx"); //Rebind the Category with new route BindCategory(); //Success Notification App_Code.NotificationService.SendNotification("NewCategorySuccess", "Category Added Successfully", "success", "4000"); } catch (Exception ex) { //Error App_Code.NotificationService.SendNotification("NewCategory", ex.Message, "error"); } }