コード例 #1
0
        public async Task CreateContact(ContactDomainObj contactDomainObj)
        {
            await DoDatabaseValidation(contactDomainObj);

            var strategy = DbContext.Database.CreateExecutionStrategy();
            await strategy.ExecuteAsync(async() =>
            {
                using (var transaction = DbContext.Database.BeginTransaction())
                {
                    var bizEntity = new BusinessEntity {
                    };
                    DbContext.BusinessEntity.Add(bizEntity);
                    await Save();

                    contactDomainObj.BusinessEntityID = bizEntity.BusinessEntityID;
                    var contact = new AdventureWorks.Models.Person.Person {
                    };
                    contact.Map(contactDomainObj);

                    contact.EmailAddressObj = new EmailAddress
                    {
                        BusinessEntityID   = bizEntity.BusinessEntityID,
                        PersonEmailAddress = contactDomainObj.EmailAddress
                    };

                    contact.PasswordObj = new PersonPWord
                    {
                        PasswordHash = contactDomainObj.EmailPasswordHash,
                        PasswordSalt = contactDomainObj.EmailPasswordSalt
                    };

                    DbContext.Person.Add(contact);
                    await Save();

                    var bec = new BusinessEntityContact
                    {
                        BusinessEntityID = contactDomainObj.ParentEntityID,
                        PersonID         = contact.BusinessEntityID,
                        ContactTypeID    = contactDomainObj.ContactTypeID
                    };
                    DbContext.BusinessEntityContact.Add(bec);
                    await Save();
                    transaction.Commit();
                }
            });
        }
コード例 #2
0
        public async Task CreateEmployee(EmployeeDomainObj employeeDomainObj)
        {
            var strategy = DbContext.Database.CreateExecutionStrategy();
            await strategy.ExecuteAsync(async() =>
            {
                using (var transaction = DbContext.Database.BeginTransaction())
                {
                    var bizEntity = new BusinessEntity {
                    };
                    DbContext.BusinessEntity.Add(bizEntity);
                    await Save();

                    employeeDomainObj.BusinessEntityID = bizEntity.BusinessEntityID;

                    var person = new AdventureWorks.Models.Person.Person {
                    };
                    person.BusinessEntityID = bizEntity.BusinessEntityID;
                    person.Map(employeeDomainObj);
                    person.EmailAddressObj = new EmailAddress
                    {
                        BusinessEntityID   = bizEntity.BusinessEntityID,
                        PersonEmailAddress = employeeDomainObj.EmailAddress
                    };
                    person.PasswordObj = new PersonPWord
                    {
                        BusinessEntityID = bizEntity.BusinessEntityID,
                        PasswordHash     = employeeDomainObj.PasswordHash,
                        PasswordSalt     = employeeDomainObj.PasswordSalt
                    };

                    var employee = new Employee {
                    };
                    employee.Map(employeeDomainObj);
                    employee.BusinessEntityID = bizEntity.BusinessEntityID;

                    person.EmployeeObj = employee;
                    DbContext.Person.Add(person);
                    await Save();

                    transaction.Commit();
                }
            });
        }