Example #1
0
        public static Guid CreateExportContract(Guid tenantId, string number, Guid creator)
        {
            ShippingExportDC contractDC = null;

            using (ExtensibleObjectContext context = new ExtensibleObjectContext(Constants.Database.TenantData))
            {
                KeyValuePair <string, object>        keyValueTenantId = new KeyValuePair <string, object>("TenantId", tenantId);
                KeyValuePair <string, object>        keyValueNumber   = new KeyValuePair <string, object>("Number", number);
                EntityQuery <ShippingExportContract> query            = context.GetQuery <ShippingExportContract>(keyValueTenantId, keyValueNumber);
                if (query.GetCount() > 0)
                {
                    throw new ExportContractExcepiton(string.Format("The export contract with number {0} has already existed!"));
                }

                contractDC            = new ShippingExportDC();
                contractDC.Id         = Guid.NewGuid();
                contractDC.TenantId   = tenantId;
                contractDC.Number     = number;
                contractDC.CreateDate = DateTime.Now;
                contractDC.Creator    = creator;
                ShippingExportContract contract = new ShippingExportContract();
                EntityExchanger.WriteDCToEntity(contractDC, contract);
                context.AddObject(contract);
                context.SaveAllChanges();
            }
            ExportProcessLogic.OpenExportProcess(tenantId, contractDC);
            return(contractDC.Id);
        }
Example #2
0
 public static void UpdateExportContract(ShippingExportDC dc)
 {
     using (ExtensibleObjectContext context = new ExtensibleObjectContext(Constants.Database.TenantData))
     {
         string         entityDefName = ExtensibleDC.GetEntityClassName(dc.GetType());
         EntityMetadata metadata      = DataModelWorkspace.Current.GetEntityMetadata(entityDefName);
         KeyValuePair <string, object>[] keyValues = new KeyValuePair <string, object>[] { new KeyValuePair <string, object>("Id", dc.Id) };
         EntityKey key = context.CreateKey(typeof(ShippingExportContract), keyValues);
         ShippingExportContract exportContract = context.GetObjectByKey <ShippingExportContract>(key);
         EntityExchanger.WriteDCToEntity(dc, exportContract);
         context.SaveAllChanges();
     }
 }