// 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); }
public IList <IWebshipAccount> GetAllWithCustomerId(int custId) { var accounts = from p in _Db.UserProfiles where p.CustID == custId select p; var converter = new WebshipAccountFactory(); return(accounts.Select(userProfile => converter.Create(userProfile)).ToList()); }
public IList <IWebshipAccount> GetAllWithLoginNameCustId(string loginName, int custId) { var accounts = from p in _Db.UserProfiles where p.LoginName.Trim() == loginName && p.CustID == custId select p; var converter = new WebshipAccountFactory(); return(accounts.Select(userProfile => converter.Create(userProfile)).ToList()); }
public IList <IWebshipAccount> GetAllWithUid(int UID) { var accounts = from p in _Db.UserProfiles where p.UID == UID select p; var converter = new WebshipAccountFactory(); return(accounts.Select(userProfile => converter.Create(userProfile)).ToList()); }