// Creates Customer account and on success creates a new webship account for it
        public static AccountsCreationResponse CreateAccounts(AccountsCreationRequest request)
        {
            // TODO: Some of the tables updated in webship account creation do not have domain objects
            // TODO: So they lack code to prevent killing the database insert with bad data
            // TODO: For now, just scrub the fields in question here
            request.BillingZip     = ToDigitsOnly(request.BillingZip);
            request.CompanyBillZip = ToDigitsOnly(request.CompanyBillZip);
            request.CCNumber       = ToDigitsOnly(request.CCNumber);
            request.RequesterPhone = ToDigitsOnly(request.RequesterPhone);
            request.CompanyPhone   = ToDigitsOnly(request.CompanyPhone);
            request.CompanyPhyZip  = ToDigitsOnly(request.CompanyPhyZip);

            var response       = new AccountsCreationResponse();
            var custfactory    = new LsoCustomerFactory();
            var webacctfactory = new WebshipAccountFactory();

            var cust    = custfactory.Create(request);
            var webacct = webacctfactory.Create(request);


            // TODO: make a validator class that looks at all data in these new
            // domain instances and either run it on them, or weave it into the
            // property set code in each domain object

            var customerRepository       = RepositoryFactory.GetNewCustomerRepository();
            var webshipAccountRepository = RepositoryFactory.GetNewWebshipAccountRepository();

            response.Success = true;

            // TODO: We don't have validation in place, so bad data errors will be lost with this current implementation
            try
            {
                // TODO: With different databases, and the repository pattern we don't get transactions
                // TODO: We will need to modify this code to catch errors and remove spurious accounts
                // TODO: Or add a transaction pattern
                customerRepository.Add(cust);
                webacct.CustID = cust.CustID;
                webshipAccountRepository.Add(webacct);
                response.CustomerId = webacct.CustID;
                response.LoginName  = webacct.LoginName;
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Errors  = new ValidationErrors();
                response.Errors.ErrorsMessage = new List <string>();
                var trace = new System.Diagnostics.StackTrace(ex, true);

                response.Errors.ErrorsMessage.Add(ex.Message + " " + trace.GetFrame(0).GetMethod().Name + " " + "Line: " + trace.GetFrame(0).GetFileLineNumber() + " " + "Column: " + trace.GetFrame(0).GetFileColumnNumber());
                if (ex.InnerException != null)
                {
                    var trace2 = new System.Diagnostics.StackTrace(ex.InnerException, true);
                    response.Errors.ErrorsMessage.Add(ex.InnerException.Message + " " + trace2.GetFrame(0).GetMethod().Name + " " + "Line: " + trace2.GetFrame(0).GetFileLineNumber() + " " + "Column: " + trace2.GetFrame(0).GetFileColumnNumber());
                }
            }

            return(response);
        }
示例#2
0
        public IList <ILsoCustomer> GetAllWithCustIdZipcode(int custId, string zipcode)
        {
            var accounts = from p in _Db.Customers
                           where p.CustID == custId && p.PhyZip == zipcode
                           select p;
            var converter = new LsoCustomerFactory();

            return(accounts.Select(customer => converter.Create(customer)).ToList());
        }
示例#3
0
        public IList <ILsoCustomer> GetAllWithCustId(int custId)
        {
            var accounts = from p in _Db.Customers
                           where p.CustID == custId
                           select p;
            var converter = new LsoCustomerFactory();

            return(accounts.Select(customer => converter.Create(customer)).ToList());
        }
示例#4
0
        public IList <ILsoCustomer> GetAllWithCustName(string custName)
        {
            // TODO: Names should be normalized to prevent entries with extra spaces from failing the search
            var accounts = from p in _Db.Customers
                           where p.CustName.ToLower() == custName.ToLower()
                           select p;
            var converter = new LsoCustomerFactory();

            return(accounts.Select(customer => converter.Create(customer)).ToList());
        }
示例#5
0
        public IList <ILsoCustomer> GetAllWithCustContactPhone(string CustContactPhone)
        {
            var searchstring = DbUtils.ConvertToSqlLike(CustContactPhone);
            var accounts     = from p in _Db.Customers
                               where System.Data.Linq.SqlClient.SqlMethods.Like(p.PhyAddress1, searchstring)
                               select p;
            var converter = new LsoCustomerFactory();

            return(accounts.Select(customer => converter.Create(customer)).ToList());
        }
示例#6
0
        public IList <ILsoCustomer> GetAllWithDataLike(string custName, string CustContactName, string BillToAddress1, string CustContactPhone, string PhyAddress1)
        {
            // TODO: we are using a hard coded take on this right now as a web client
            // doesn't normally need to see many records.  instead we should rework the interface to
            // work in both use cases

            // For the moment it makes the most sense if we require all of these to be present because the
            // primary place where this will be used will require them
            // later it might be nice to use only one or 2, but that can wait
            if (!String.IsNullOrEmpty(custName) && !String.IsNullOrEmpty(CustContactName) && !String.IsNullOrEmpty(BillToAddress1) && !String.IsNullOrEmpty(CustContactPhone) && !String.IsNullOrEmpty(PhyAddress1))
            {
                var accounts = (from p in _Db.Customers
                                where System.Data.Linq.SqlClient.SqlMethods.Like(p.CustName, DbUtils.ConvertToSqlLike(custName)) ||
                                System.Data.Linq.SqlClient.SqlMethods.Like(p.CustContactName, DbUtils.ConvertToSqlLike(CustContactName)) ||
                                System.Data.Linq.SqlClient.SqlMethods.Like(p.BillToAddress1, DbUtils.ConvertToSqlLike(BillToAddress1)) ||
                                System.Data.Linq.SqlClient.SqlMethods.Like(p.CustContactPhone, DbUtils.ConvertToSqlLike(CustContactPhone)) ||
                                System.Data.Linq.SqlClient.SqlMethods.Like(p.PhyAddress1, DbUtils.ConvertToSqlLike(PhyAddress1))
                                select p).Take(1000);
                var converter = new LsoCustomerFactory();
                return(accounts.Select(customer => converter.Create(customer)).ToList());
            }
            return(new List <ILsoCustomer>());
        }