コード例 #1
0
ファイル: CAT_Item.cs プロジェクト: tslekwadi/CDS
        internal static String Save(DB.CAT_Item entry, DataContext dataContext)
        {
            try
            {
                if (dataContext.EntityCatalogueContext.GetEntityState(entry) == System.Data.Entity.EntityState.Detached)
                {
                    dataContext.EntityCatalogueContext.CAT_Item.Add(entry);
                }
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException ex)
            {
                return(dataContext.PackageValidationException());
            }

            return("Success");
        }
コード例 #2
0
        private void btnAddEntity_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            using (AddCatalogueEntityDialogue dlg = new AddCatalogueEntityDialogue())
            {
                dlg.TopCategoryId = SelectedTopCategory == null ? null : (Int64?)SelectedTopCategory.Id;
                //I wanted to do this but the problem is with the Async load on the ddlCategory SearchLookupEdit
                //you cant get the Category form the Context befause the Async load has a DataReader open
                //and you can get it form the ddlCategory.View because it isn't populated yet
                dlg.CatalogueId = ((DB.CAT_Catalogue)BindingSource.DataSource).Id;

                if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    try
                    {
                        using (new CDS.Client.Desktop.Essential.UTL.WaitCursor())
                        {
                            try
                            {
                                using (TransactionScope transaction = DataContext.GetTransactionScope())
                                {
                                    DB.CAT_Item     item     = dlg.Item;
                                    DB.CAT_ItemData itemData = BL.CAT.CAT_ItemData.New;
                                    itemData.CategoryId = dlg.TopCategoryId.Value;
                                    //item.CAT_ItemData.Add(itemData);
                                    Parallel.ForEach(dlg.ListEntryMeta, entrymeta =>
                                                     //foreach (EntryMeta entryData in dlg.ListEntryMeta)
                                    {
                                        DB.CAT_MetaData metaData = BL.CAT.CAT_MetaData.New;
                                        metaData.MetaId          = entrymeta.Id;
                                        metaData.Data            = (string)entrymeta.Value;
                                        metaData.CategoryId      = entrymeta.CategoryId;
                                        item.CAT_MetaData.Add(metaData);
                                    });

                                    BL.EntityController.SaveCAT_Item(item, DataContext);
                                    DataContext.SaveChangesEntityCatalogueContext();

                                    itemData.ItemId       = item.Id;
                                    itemData.ParentItemId = item.Id;
                                    BL.EntityController.SaveCAT_ItemData(itemData, DataContext);
                                    DataContext.SaveChangesEntityCatalogueContext();
                                    DataContext.SaveChangesEntitySystemContext();
                                    DataContext.CompleteTransaction(transaction);
                                }
                                DataContext.EntityCatalogueContext.AcceptAllChanges();
                                DataContext.EntitySystemContext.AcceptAllChanges();
                                InstantFeedbackSourceEntity.Refresh();
                            }
                            catch (Exception ex)
                            {
                                DataContext.EntityCatalogueContext.RejectChanges();
                                DataContext.EntitySystemContext.RejectChanges();
                                HasErrors = true;
                                if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex))
                                {
                                    throw ex;
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        //DataContext.EntityAccountingContext.RollBackTransaction();
                        if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex))
                        {
                            throw ex;
                        }
                    }
                }
            }
        }