public static void UpdateCategoryById(int id, CanonCategory newValues) { CanonDataContext db = Cdb.Instance; Category cat = db.Categories.First(u => u.CategoryId == id); cat.CategoryName = newValues.CategoryName; cat.InternalId = newValues.InternalId; db.SubmitChanges(); }
public static void InsertCategory(CanonCategory newValues) { CanonDataContext db = Cdb.Instance; Category cat = new Category(); cat.CategoryName = newValues.CategoryName; cat.InternalId = newValues.InternalId; db.Categories.InsertOnSubmit(cat); db.SubmitChanges(); }
protected void gridCategories_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e) { try { SessionManager.IsEditFormCreated = false; int keyToUpdate = int.Parse(e.Keys[0].ToString()); //update category CanonCategory cc = new CanonCategory(); cc.CategoryName = e.NewValues["CategoryName"].ToString(); cc.InternalId = e.NewValues["InternalId"].ToString(); CanonCategory.UpdateCategoryById(keyToUpdate, cc); e.Cancel = true; gridCategories.CancelEdit(); this.BindData(); } catch (Exception ex) { Logger.Log(string.Format("exception {0}", ex.ToString()), LogLevel.Error); } }
protected void gridCategories_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e) { try { SessionManager.IsEditFormCreated = false; //insert category CanonCategory cc = new CanonCategory(); cc.CategoryName = e.NewValues["CategoryName"].ToString(); cc.InternalId = e.NewValues["InternalId"].ToString(); CanonCategory.InsertCategory(cc); e.Cancel = true; gridCategories.CancelEdit(); this.BindData(); } catch (Exception ex) { Logger.Log(string.Format("exception {0}", ex.ToString()), LogLevel.Error); } }