示例#1
0
 internal static BL.DomainModel.Supplier AdaptSupplier(Supplier s)
 {
     return new BL.DomainModel.Supplier()
     {
         AccountNumber = s.AccountNumber,
         CreditRating = s.CreditRating,
         PreferedSupplier = s.PreferedSupplier,
         ActiveFlag = s.ActiveFlag,
         PuchraseWebserviceUrl = s.PurchaseWebserviceUrl,
     };
 }
        public int StoreSupplier(Supplier supplier, IEnumerable<ChangeItem> changeItems)
        {
            int accountNumber = default(int);
            using (TransactionScope transaction = new TransactionScope())
            {
                accountNumber = rep.SaveSupplier(supplier);
                
                transaction.Complete();
            }

            return accountNumber;
        }
示例#3
0
        public int SaveAddress(HsrOrderApp.BL.DomainModel.Address address, HsrOrderApp.BL.DomainModel.Supplier forThisSupplier)
        {
            AddressRepository rep       = new AddressRepository(db);
            Address           dbAddress = rep.SaveAddressInternal(address);

            if (address.IsNew)
            {
                Supplier supplier = db.SupplierSet.First(c => c.SupplierId == forThisSupplier.SupplierId);
                supplier.Addresses.Add(dbAddress);
                db.SaveChanges();
            }
            return(dbAddress.AddressId);
        }
        public int SaveAddress(HsrOrderApp.BL.DomainModel.Address address, HsrOrderApp.BL.DomainModel.Supplier forThisSupplier)
        {
            AddressRepository rep = new AddressRepository(db);
            int addressid         = rep.SaveAddress(address);

            if (address.IsNew)
            {
                SupplierAddress ca = new SupplierAddress();
                ca.AddressId  = addressid;
                ca.SupplierId = forThisSupplier.SupplierId;
                db.SupplierAddresses.InsertOnSubmit(ca);
                db.SubmitChanges();
            }
            return(addressid);
        }
示例#5
0
        public int SaveSupplier(HsrOrderApp.BL.DomainModel.Supplier supplier)
        {
            try
            {
                string   setname = "SupplierSet";
                Supplier dbSupplier;

                bool isNew = false;
                if (supplier.SupplierId == default(int) || supplier.SupplierId <= 0)
                {
                    isNew      = true;
                    dbSupplier = new Supplier();
                }
                else
                {
                    dbSupplier = new Supplier()
                    {
                        SupplierId = supplier.SupplierId, Version = supplier.Version.ToTimestamp()
                    };
                    dbSupplier.EntityKey = db.CreateEntityKey(setname, dbSupplier);
                    db.AttachTo(setname, dbSupplier);
                }

                dbSupplier.Name = supplier.Name;
                if (isNew)
                {
                    db.AddToSupplierSet(dbSupplier);
                }
                db.SaveChanges();

                supplier.SupplierId = dbSupplier.SupplierId;
                return(dbSupplier.SupplierId);
            }
            catch (OptimisticConcurrencyException ex)
            {
                if (ExceptionPolicy.HandleException(ex, "DA Policy"))
                {
                    throw;
                }
                return(default(int));
            }
        }
        public int SaveSupplier(HsrOrderApp.BL.DomainModel.Supplier supplier)
        {
            try
            {
                Supplier dbSupplier = new Supplier();
                bool     isNew      = false;
                if (supplier.SupplierId == default(int) || supplier.SupplierId <= 0)
                {
                    isNew = true;
                }

                dbSupplier.SupplierId              = supplier.SupplierId;
                dbSupplier.Version                 = supplier.Version.ToTimestamp();
                dbSupplier.Name                    = supplier.Name;
                dbSupplier.ActiveFlag              = supplier.ActiveFlag;
                dbSupplier.PreferredSupplierFlag   = supplier.PreferredSupplierFlag;
                dbSupplier.AccountNumber           = supplier.AccountNumber;
                dbSupplier.CreditRating            = supplier.CreditRating;
                dbSupplier.PurchasingWebServiceURL = supplier.PurchasingWebServiceUrl;

                if (isNew)
                {
                    db.Suppliers.InsertOnSubmit(dbSupplier);
                }
                else
                {
                    db.Suppliers.Attach(dbSupplier, true);
                }
                db.SubmitChanges();
                supplier.SupplierId = dbSupplier.SupplierId;
                return(dbSupplier.SupplierId);
            }
            catch (ChangeConflictException ex)
            {
                if (ExceptionPolicy.HandleException(ex, "DA Policy"))
                {
                    throw;
                }
                return(default(int));
            }
        }
        internal Supplier SaveSupplierInternal(BL.DomainModel.Supplier supplier)
        {
            try
            {
                string setname = "SupplierSet";
                Supplier dbSupplier;
                bool isNew = false;
                if (supplier.AccountNumber == default(int) || supplier.AccountNumber <= 0)
                {
                    isNew = true;
                    dbSupplier = new Supplier();
                }
                else
                {
                    dbSupplier = new Supplier() { AccountNumber = supplier.AccountNumber, Version = supplier.Version.ToTimestamp() };
                    dbSupplier.EntityKey = db.CreateEntityKey(setname, dbSupplier);
                    db.AttachTo(setname, dbSupplier);
                }
                dbSupplier.CreditRating = supplier.CreditRating;
                dbSupplier.PreferedSupplier = supplier.PreferedSupplier;
                dbSupplier.ActiveFlag = supplier.ActiveFlag;
                dbSupplier.PurchaseWebserviceUrl = supplier.PuchraseWebserviceUrl;


                if (isNew)
                {
                    db.AddToSupplierSet(dbSupplier);
                }
                db.SaveChanges();

                return dbSupplier;
            }
            catch (OptimisticConcurrencyException ex)
            {
                if (ExceptionPolicy.HandleException(ex, "DA Policy")) throw;
                return null;
            }
        }