Exemplo n.º 1
0
        public async Task UpdateCustomer(customer customer, string password)
        {
            using (TransactionScope transaction = new TransactionScope(
                       TransactionScopeOption.Required,
                       new TransactionOptions {
                IsolationLevel = IsolationLevel.ReadUncommitted
            },
                       TransactionScopeAsyncFlowOption.Enabled))
            {
                using (B2CCustomerEntities entities = new B2CCustomerEntities())
                {
                    entities.Entry(customer).State = EntityState.Modified;
                    await entities.SaveChangesAsync();

                    foreach (address address in customer.addresses)
                    {
                        address.customer_id = customer.id;

                        if (address.id == 0)
                        {
                            entities.address.Add(address);
                        }
                        else
                        {
                            entities.Entry(address).State = EntityState.Modified;
                        }

                        await entities.SaveChangesAsync();
                    }
                }

                await UpdatePassword(customer.email, password);

                transaction.Complete();
            }
        }
Exemplo n.º 2
0
        public async Task <int> CreateCustomer(customer customer, string password)
        {
            customer.status_id = 1;

            using (TransactionScope transaction = new TransactionScope(
                       TransactionScopeOption.Required,
                       new TransactionOptions {
                IsolationLevel = IsolationLevel.ReadUncommitted
            },
                       TransactionScopeAsyncFlowOption.Enabled))
            {
                using (B2CCustomerEntities entities = new B2CCustomerEntities())
                {
                    entities.customer.Add(customer);
                    await entities.SaveChangesAsync();
                }

                await UpdatePassword(customer.email, password);

                transaction.Complete();
            }

            return(customer.id);
        }