示例#1
0
        public IEnumerable <int> CreateContacts(IEnumerable <ContactsBo> contactList)
        {
            if (contactList == null)
            {
                throw new ValidationException(string.Format(BusinessRuleResource.Error_InstanceObject,
                                                            nameof(contactList)));
            }

            return(_ruleProcessor.CreateContacts(contactList));
        }
示例#2
0
        public bool CreateCustomer(CustomerBo customer)
        {
            if (customer == null)
            {
                throw new EvaluateException(BusinessRuleResource.Error_CustomerObject);
            }

            using (var transaction = new TransactionScope())
            {
                try
                {
                    var customerId = _customerRulesProcessor.CreateCustomer(customer);
                    if (customerId <= 0)
                    {
                        return(false);
                    }
                    var address = customer.CustomerAddress.Select(s => s.Address).ToArray();
                    if (address.Any())
                    {
                        var addressSaved = _addressRuleProcessor.CreateAddress(address).ToArray();
                        if (addressSaved.Any())
                        {
                            var count = 0;
                            foreach (var customerAddress in customer.CustomerAddress)
                            {
                                customerAddress.AddressId  = addressSaved[count];
                                customerAddress.CustomerId = customerId;
                                customerAddress.IsPrimary  = customerAddress.IsPrimary;
                                count++;
                            }
                            _customerRulesProcessor.CreateCustomerAddress(customer.CustomerAddress);
                        }
                    }

                    var contacts = customer.CustomerContacts.Select(s => s.Contact).ToArray();
                    if (contacts.Any())
                    {
                        var savesContacts = _contactsRuleProcessor.CreateContacts(contacts).ToArray();
                        if (savesContacts.Any())
                        {
                            var count = 0;
                            foreach (var customerContact in customer.CustomerContacts)
                            {
                                customerContact.ContactId  = savesContacts[count];
                                customerContact.CustomerId = customerId;
                                customerContact.IsPrimary  = customerContact.IsPrimary;
                                count++;
                            }
                            _customerRulesProcessor.CreateCustomerContacts(customer.CustomerContacts);
                        }
                    }
                    transaction.Complete();
                }
                catch (Exception e)
                {
                    transaction.Dispose();
                    throw e;
                }
            }
            return(true);
        }