internal static String Save(DB.CAT_Category entry, DataContext dataContext) { try { if (dataContext.EntityCatalogueContext.GetEntityState(entry) == System.Data.Entity.EntityState.Detached) { dataContext.EntityCatalogueContext.CAT_Category.Add(entry); } } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { return(dataContext.PackageValidationException()); } return("Success"); }
private void btnAddCategory_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { try { DB.CAT_Category newCategory = BL.CAT.CAT_Category.New; newCategory.CAT_Catalogue = ((DB.CAT_Catalogue)BindingSource.DataSource); BL.EntityController.SaveCAT_Category(newCategory, DataContext); //Werner //I realy dont want to do this but if the Category does not have an ID you cant place a child under it //Need to find a way to do it in some kind of transaction to reserve the IDs but should be able to rollback OnSaveRecord(); BindingSourceCategory.Add(newCategory); } catch (Exception ex) { if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex)) { throw ex; } } }