Beispiel #1
0
        /// <summary>
        /// Update Customer
        /// </summary>
        /// <param name="customer"></param>
        /// <param name="transaction"></param>
        public void UpdateCustomer(Customer customer, out TransactionalInformation transaction)
        {
            transaction = new TransactionalInformation();

            try
            {
                CustomerBusinessRules customerBusinessRules = new CustomerBusinessRules();
                ValidationResult      results = customerBusinessRules.Validate(customer);

                bool validationSucceeded           = results.IsValid;
                IList <ValidationFailure> failures = results.Errors;

                if (validationSucceeded == false)
                {
                    transaction = ValidationErrors.PopulateValidationErrors(failures);
                    return;
                }

                _customerDataService.CreateSession();
                _customerDataService.BeginTransaction();

                Customer existingCustomer = _customerDataService.GetCustomer(customer.CustomerID);

                existingCustomer.CustomerCode = customer.CustomerCode;
                existingCustomer.CompanyName  = customer.CompanyName;
                existingCustomer.ContactName  = customer.ContactName;
                existingCustomer.ContactTitle = customer.ContactTitle;
                existingCustomer.Address      = customer.Address;
                existingCustomer.City         = customer.City;
                existingCustomer.Region       = customer.Region;
                existingCustomer.PostalCode   = customer.PostalCode;
                existingCustomer.Country      = customer.Country;
                existingCustomer.MobileNumber = customer.MobileNumber;
                existingCustomer.PhoneNumber  = customer.PhoneNumber;

                _customerDataService.UpdateCustomer(customer);
                _customerDataService.CommitTransaction(true);

                transaction.ReturnStatus = true;
                transaction.ReturnMessage.Add("Customer was successfully updated.");
            }
            catch (Exception ex)
            {
                string errorMessage = ex.Message;
                transaction.ReturnMessage.Add(errorMessage);
                transaction.ReturnStatus = false;
            }
            finally
            {
                _customerDataService.CloseSession();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Create Customer
        /// </summary>
        /// <param name="customer"></param>
        /// <param name="transaction"></param>
        /// <returns></returns>
        public Customer CreateCustomer(Customer customer, out TransactionalInformation transaction)
        {
            transaction = new TransactionalInformation();

            try
            {
                CustomerBusinessRules customerBusinessRules = new CustomerBusinessRules();
                ValidationResult      results = customerBusinessRules.Validate(customer);

                bool validationSucceeded           = results.IsValid;
                IList <ValidationFailure> failures = results.Errors;

                if (validationSucceeded == false)
                {
                    transaction = ValidationErrors.PopulateValidationErrors(failures);
                    return(customer);
                }

                _customerDataService.CreateSession();
                _customerDataService.BeginTransaction();
                _customerDataService.CreateCustomer(customer);
                _customerDataService.CommitTransaction(true);

                transaction.ReturnStatus = true;
                transaction.ReturnMessage.Add("Customer successfully created.");
            }
            catch (Exception ex)
            {
                string errorMessage = ex.Message;
                transaction.ReturnMessage.Add(errorMessage);
                transaction.ReturnStatus = false;
            }
            finally
            {
                _customerDataService.CloseSession();
            }

            return(customer);
        }