Exemplo n.º 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();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get Customer
        /// </summary>
        /// <param name="customerID"></param>
        /// <param name="transaction"></param>
        /// <returns></returns>
        public CustomerDTO GetCustomer(int customerID, out TransactionalInformation transaction)
        {
            transaction = new TransactionalInformation();

            var ci = new CustomerDTO();

            try
            {
                _customerDataService.CreateSession();
                Customer customer = _customerDataService.GetCustomer(customerID);
                ci = mapper.Map <Customer, CustomerDTO>(customer);
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
                transaction.ReturnMessage = new List <string>();
                string errorMessage = ex.Message;
                transaction.ReturnStatus = false;
                transaction.ReturnMessage.Add(errorMessage);
            }
            finally
            {
                _customerDataService.CloseSession();
            }

            return(ci);
        }
        public decimal GetCustomerCurrentAmountDue(Guid customerId)
        {
            var customer = _customerDataService.GetCustomer(customerId);

            var mowingCharge   = customer.GetMowingCharge();
            var weedingCharge  = customer.GetWeedingCharge();
            var wateringCharge = customer.GetWateringCharge();

            return(mowingCharge + weedingCharge + wateringCharge);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Update Customer
        /// </summary>
        /// <param name="customerInformation"></param>
        /// <param name="transaction"></param>
        public void UpdateCustomer(CustomerInformation customerInformation, out TransactionalInformation transaction)
        {
            transaction = new TransactionalInformation();

            Customer customer = new Customer();

            try
            {
                customer.CustomerCode = customerInformation.CustomerCode;
                customer.CompanyName  = customerInformation.CompanyName;
                customer.CustomerID   = customerInformation.CustomerID;
                CustomerBusinessRules customerBusinessRules = new CustomerBusinessRules(_customerDataService, customer);
                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();

                if (customerInformation.CustomerID == 0)
                {
                    customer.AddressLine1 = customerInformation.AddressLine1;
                    customer.AddressLine2 = customerInformation.AddressLine2;
                    customer.City         = customerInformation.City;
                    customer.State        = customerInformation.State;
                    customer.ZipCode      = customerInformation.ZipCode;
                    customer.PhoneNumber  = customerInformation.PhoneNumber;

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

                    customerInformation.CustomerID = customer.CustomerID;

                    transaction.ReturnStatus = true;
                    transaction.ReturnMessage.Add("Customer was successfully created at " + DateTime.Now.ToString());
                }
                else
                {
                    Customer existingCustomer = _customerDataService.GetCustomer(customerInformation.CustomerID);
                    existingCustomer.CustomerCode = customerInformation.CustomerCode;
                    existingCustomer.CompanyName  = customerInformation.CompanyName;
                    existingCustomer.AddressLine1 = customerInformation.AddressLine1;
                    existingCustomer.AddressLine2 = customerInformation.AddressLine2;
                    existingCustomer.City         = customerInformation.City;
                    existingCustomer.State        = customerInformation.State;
                    existingCustomer.ZipCode      = customerInformation.ZipCode;
                    existingCustomer.PhoneNumber  = customerInformation.PhoneNumber;

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

                    transaction.ReturnStatus = true;
                    transaction.ReturnMessage.Add("Customer was successfully updated at " + DateTime.Now.ToString());
                }
            }
            catch (Exception ex)
            {
                string errorMessage = ex.Message;
                transaction.ReturnMessage.Add(errorMessage);
                transaction.ReturnStatus = false;
            }
            finally
            {
                _customerDataService.CloseSession();
            }

            return;
        }
Exemplo n.º 5
0
 public async Task <Customer> GetCustomer(int id)
 {
     return(await _customerDataService.GetCustomer(id));
 }
Exemplo n.º 6
0
 public List <Customer> GetCustomer()
 {
     return(customerDataService.GetCustomer());
 }