// 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()); }
public void Add(IWebshipAccount item) { // // by convention new users are added to the newusers table, and // then added to the userprofile table // I believe newusers served a role in a manual process before, but am unsure // Mapper.Reset(); Mapper.CreateMap <IWebshipAccount, NewUser>() .ForMember(dest => dest.Created, opt => opt.Ignore()) .ForMember(dest => dest.CreatedDate, opt => opt.Ignore()) .ForMember(dest => dest.RequestDate, opt => opt.Ignore()); var newuser = Mapper.Map <IWebshipAccount, NewUser>(item); Mapper.AssertConfigurationIsValid(); // Fill in data not automapped newuser.CreatedDate = DateTime.Now; newuser.RequestDate = DateTime.Now; newuser.Created = true; // Per Bill set this to easily recognizable value newuser.CreatedBy = -1; _Db.NewUsers.InsertOnSubmit(newuser); // // The userprofile row is where the "webship account" is stored // var userprofile = new UserProfile(); // We need access to the underlying implementation var actualitem = (WebshipAccount)item; actualitem.CreatedFrom = userprofile; // this empty userprofile will be updated in the factory below new WebshipAccountNewDefaults().SetDefaults(actualitem); WebshipAccountFactory.Update(actualitem); // queue for storage in DB _Db.UserProfiles.InsertOnSubmit(userprofile); // there must be a row in customerProfiles to schedule a pickup // for now, leaving this awkwardness here since moving it would // make error handling that much harder customerProfile cp = null; var cprofile = from p in _Db.customerProfiles where p.CustID == item.CustID select p; if (!cprofile.Any()) { // create customerprofile row cp = new customerProfile { AccountLockout = false, CustContactPhone = item.CompanyPhone, CustID = item.CustID, CustName = item.CompanyName, PhyAddress1 = item.CompanyAddress1, PhyAddress2 = item.CompanyAddress2, KnownShipper = false, PhyCity = item.CompanyCity, PhyState = item.CompanyState, PhyZip = item.CompanyZip }; _Db.customerProfiles.InsertOnSubmit(cp); } // check to see if this object will fit into the DB columns try { _Db.TestSubmitChanges(); } catch (InvalidOperationException ex) { // discard the changes _Db.DiscardInsertsAndDeletes(); _Db.SubmitChanges(); // rethrow the exception for the benefit of our caller); throw; } // If we made it to here, we can proceed safely // Get a new UID from the DB int?newUid = 0; _Db.sp_getuid(ref newUid); if (!newUid.HasValue || newUid == 0) { // discard the changes _Db.DiscardInsertsAndDeletes(); _Db.SubmitChanges(); throw new CannotCreateNewIdException("WebshipAccountRepository.Add: sp_getuid returned null or zero for the next UID"); } // store customer id into objects before storing them in the DB newuser.UID = newUid.Value; item.UID = newUid.Value; actualitem.CreatedFrom.UID = newUid.Value; _Db.SubmitChanges(); }