Пример #1
0
        protected Boolean SubmitForm()
        {
            StringBuilder formattedHtml         = new StringBuilder();
            StringBuilder formattedInternalHtml = new StringBuilder();
            string        seasonalMonths        = "";

            try
            {
                foreach (ListItem item in cblSeasonal.Items)
                {
                    if (item.Selected)
                    {
                        seasonalMonths += item.Value + " - ";
                    }
                }

                if (seasonalMonths.Length > 3)
                {
                    seasonalMonths = seasonalMonths.Substring(0, seasonalMonths.Length - 3);
                }
            }
            catch (System.Exception ex)
            {
                _newLogic.WriteExceptionToDB(ex, "AdminSubmitForm - Get Seasonal Months");
            }

            try
            {
                //Instanciate new model objects for each piece of data to be created
                MerchantModel          newMerchant                        = new MerchantModel();
                MerchantPrincipalModel newMerchantPrincipal               = new MerchantPrincipalModel();
                ContactModel           newMerchantPrincipalContact        = new ContactModel();
                AddressModel           newMerchantPrincipalContactAddress = new AddressModel();
                ContactModel           newContact         = new ContactModel();
                ContactModel           newBusiness        = new ContactModel();
                AddressModel           newBusinessAddress = new AddressModel();
                ProcessorModel         newProcessor       = new ProcessorModel();
                DebitCardModel         newDebitCard       = new DebitCardModel();
                BankModel        newBankModel             = new BankModel();
                BankAccountModel newBankAccountModel      = new BankAccountModel();

                //Set base merchant information in newMerchant object
                if (txtMerchantId.Text != "")
                {
                    newMerchant.MerchantId = txtMerchantId.Text;
                }
                if (txtCorpName.Text != "")
                {
                    newMerchant.CorpName = txtCorpName.Text;
                }
                if (txtDBAName.Text != "")
                {
                    newMerchant.DbaName = txtDBAName.Text;
                }
                if (txtBusLicNumber.Text != "")
                {
                    newMerchant.BusLicNumber = txtBusLicNumber.Text;
                }
                if (txtBusLicType.Text != "")
                {
                    newMerchant.BusLicType = txtBusLicType.Text;
                }
                if (txtBusLicIssuer.Text != "")
                {
                    newMerchant.BusLicIssuer = txtBusLicIssuer.Text;
                }
                if (radBusLicDate.SelectedDate.HasValue)
                {
                    newMerchant.BusLicDate = Convert.ToDateTime(radBusLicDate.SelectedDate);
                }
                if (txtFedTaxId.Text != "")
                {
                    newMerchant.FedTaxId = txtFedTaxId.Text;
                }
                if (txtMerchandiseSold.Text != "")
                {
                    newMerchant.MerchandiseSold = txtMerchandiseSold.Text;
                }
                if (txtYearsInBus.Text != "")
                {
                    newMerchant.YearsInBusiness = Convert.ToInt32(txtYearsInBus.Text);
                }
                if (txtMonthsInBus.Text != "")
                {
                    newMerchant.MonthsInBusiness = Convert.ToInt32(txtMonthsInBus.Text);
                }
                if (rblSeasonal.SelectedValue != "")
                {
                    newMerchant.SeasonalSales = Convert.ToBoolean(rblSeasonal.SelectedValue);
                }
                if (seasonalMonths != "")
                {
                    newMerchant.SeasonalMonths = seasonalMonths;
                }
                if (txtSwipedPct.Text != "")
                {
                    newMerchant.SwipedPct = Convert.ToInt32(txtSwipedPct.Text);
                }
                if (txtAvgMonthlySales.Text != "")
                {
                    newMerchant.AvgMonthlySales = Convert.ToDecimal(txtAvgMonthlySales.Text);
                }
                if (txtHighestMonthlySales.Text != "")
                {
                    newMerchant.HighestMonthlySales = Convert.ToDecimal(txtHighestMonthlySales.Text);
                }
                if (txtAvgWeeklySales.Text != "")
                {
                    newMerchant.AvgWeeklySales = Convert.ToDecimal(txtAvgWeeklySales.Text);
                }
                if (rblHighRisk.SelectedValue != "")
                {
                    newMerchant.HighRisk = Convert.ToBoolean(rblHighRisk.SelectedValue);
                }
                if (txtHighRiskWho.Text != "")
                {
                    newMerchant.HighRiskWho = txtHighRiskWho.Text;
                }
                if (radHighRiskDate.SelectedDate.HasValue)
                {
                    newMerchant.HighRiskDate = Convert.ToDateTime(radHighRiskDate.SelectedDate);
                }
                if (rblBankruptcy.SelectedValue != "")
                {
                    newMerchant.Bankruptcy = Convert.ToBoolean(rblBankruptcy.SelectedValue);
                }
                if (radBankruptcyDate.SelectedDate.HasValue)
                {
                    newMerchant.BankruptcyDate = Convert.ToDateTime(radBankruptcyDate.SelectedDate);
                }

                //Add Legal Org State to merchant
                if (ddlLegalOrgState.SelectedValue != "")
                {
                    Int32 legalOrgStateId = Convert.ToInt32(ddlLegalOrgState.SelectedValue);
                    newMerchant.LegalOrgState = _globalCtx.GeoStates.Where(gs => gs.RecordId == legalOrgStateId).FirstOrDefault();
                }

                //Add Legal Org Type to merchant
                if (ddlLegalOrgType.SelectedValue != "")
                {
                    Int32 legalOrgTypeId = Convert.ToInt32(ddlLegalOrgType.SelectedValue);
                    newMerchant.LegalOrgType = _globalCtx.LegalOrgTypes.Where(lot => lot.RecordId == legalOrgTypeId).FirstOrDefault();
                }

                //Add Merchant Type to Merchant
                if (rblMerchantType.SelectedValue != "")
                {
                    newMerchant.MerchantType = _globalCtx.MerchantTypes.Where(mt => mt.MerchantTypeName == rblMerchantType.SelectedValue).FirstOrDefault();
                }

                //Add MCC to merchant
                if (ddlMCC.SelectedValue != "")
                {
                    Int32 mccId = Convert.ToInt32(ddlMCC.SelectedValue);
                    newMerchant.Mcc = _globalCtx.MerchantCategoryCodes.Where(mcc => mcc.RecordId == mccId).FirstOrDefault();
                }

                //Add Business Contact info - Email, Phone, Fax
                if (txtBusEmail.Text != "")
                {
                    newBusiness.Email = txtBusEmail.Text;
                }
                if (txtBusFax.Text != "")
                {
                    newBusiness.Fax = txtBusFax.Text;
                }
                if (txtBusPhone.Text != "")
                {
                    newBusiness.HomePhone = txtBusPhone.Text;
                }

                _globalCtx.Contacts.Add(newBusiness);

                //Add Business Contact Addess
                if (txtCorpAddress.Text != "")
                {
                    newBusinessAddress.Address = txtCorpAddress.Text;
                }
                if (txtCorpCity.Text != "")
                {
                    newBusinessAddress.City = txtCorpCity.Text;
                }
                if (ddlCorpState.SelectedValue != "")
                {
                    Int32 businessAddressStateId = Convert.ToInt32(ddlCorpState.SelectedValue);
                    newBusinessAddress.State = _globalCtx.GeoStates.Where(gs => gs.RecordId == businessAddressStateId).FirstOrDefault();
                }
                if (txtCorpZip.Text != "")
                {
                    newBusinessAddress.Zip = txtCorpZip.Text;
                }

                _globalCtx.Addresses.Add(newBusinessAddress);

                //Add new Business Contact Address to new Business
                newBusiness.Address = newBusinessAddress;

                //Add new Contact to new Merchant
                newMerchant.Business = newBusiness;

                //Add new Contact
                if (txtContactFirstName.Text != "")
                {
                    newContact.FirstName = txtContactFirstName.Text;
                }
                if (txtContactLastName.Text != "")
                {
                    newContact.LastName = txtContactLastName.Text;
                }
                if (txtContactEmail.Text != "")
                {
                    newContact.Email = txtContactEmail.Text;
                }
                if (txtContactPhone.Text != "")
                {
                    newContact.HomePhone = txtContactPhone.Text;
                }
                if (txtContactFax.Text != "")
                {
                    newContact.Fax = txtContactFax.Text;
                }

                _globalCtx.Contacts.Add(newContact);

                //Add new contact to new Merchant
                newMerchant.Contact = newContact;

                //Add new Merchant Principal
                if (txtPrincipalDLNumber.Text != "")
                {
                    newMerchantPrincipal.PrincipalDLNumber = PWDTK.StringToUtf8Bytes(txtPrincipalDLNumber.Text);
                }
                if (ddlPrincipalDLState.SelectedValue != "")
                {
                    Int32 dlStateId = Convert.ToInt32(ddlPrincipalDLState.SelectedValue);
                    newMerchantPrincipal.PrincipalDLState = _globalCtx.GeoStates.Where(gs => gs.RecordId == dlStateId).FirstOrDefault();
                }
                if (radPrincipalDoB.SelectedDate.HasValue)
                {
                    newMerchantPrincipal.PrincipalDoB = Convert.ToDateTime(radPrincipalDoB.SelectedDate);
                }
                if (txtPrincipalPctOwn.Text != "")
                {
                    newMerchantPrincipal.PrincipalPctOwn = Convert.ToInt32(txtPrincipalPctOwn.Text);
                }

                _globalCtx.MerchantPrincipal.Add(newMerchantPrincipal);

                //Create new contact for Merchant Principal
                if (txtPrincipalFirstName.Text != "")
                {
                    newMerchantPrincipalContact.FirstName = txtPrincipalFirstName.Text;
                }
                if (txtPrincipalLastName.Text != "")
                {
                    newMerchantPrincipalContact.LastName = txtPrincipalLastName.Text;
                }
                if (txtPrincipalMI.Text != "")
                {
                    newMerchantPrincipalContact.MiddleInitial = txtPrincipalMI.Text;
                }
                if (txtPrincipalTitle.Text != "")
                {
                    newMerchantPrincipalContact.Title = txtPrincipalTitle.Text;
                }
                if (txtPrincipalCellPhone.Text != "")
                {
                    newMerchantPrincipalContact.CellPhone = txtPrincipalCellPhone.Text;
                }
                if (txtPrincipalHomePhone.Text != "")
                {
                    newMerchantPrincipalContact.HomePhone = txtPrincipalHomePhone.Text;
                }

                _globalCtx.Contacts.Add(newMerchantPrincipalContact);

                //Create new address for Merchant principal Contact
                if (txtPrincipalAddress.Text != "")
                {
                    newMerchantPrincipalContactAddress.Address = txtPrincipalAddress.Text;
                }
                if (txtPrincipalCity.Text != "")
                {
                    newMerchantPrincipalContactAddress.City = txtPrincipalCity.Text;
                }
                if (ddlPrincipalState.SelectedValue != "")
                {
                    Int32 mpcStateId = Convert.ToInt32(ddlPrincipalState.SelectedValue);
                    newMerchantPrincipalContactAddress.State = _globalCtx.GeoStates.Where(gs => gs.RecordId == mpcStateId).FirstOrDefault();
                }
                if (txtPrincipalZip.Text != "")
                {
                    newMerchantPrincipalContactAddress.Zip = txtPrincipalZip.Text;
                }

                _globalCtx.Addresses.Add(newMerchantPrincipalContactAddress);

                //Add new address to Merchant Principal Contact
                newMerchantPrincipalContact.Address = newMerchantPrincipalContactAddress;

                //Add new Contact to Merchant Principal
                newMerchantPrincipal.Contact = newMerchantPrincipalContact;

                //Add new Principal to the new merchant
                newMerchant.MerchantPrincipal = newMerchantPrincipal;

                //Check if merchant processor already exists, if so link to merchant.  If not, create it and add to merchant.
                if (txtCardProcessor.Text != "")
                {
                    if (_globalCtx.Processor.Where(p => p.ProcessorName == txtCardProcessor.Text.Trim()).ToList().Count > 0)
                    {
                        newMerchant.Processor = _globalCtx.Processor.First(p => p.ProcessorName == txtCardProcessor.Text.Trim());
                    }
                    else
                    {
                        newProcessor.ProcessorName = txtCardProcessor.Text.Trim();
                        _globalCtx.Processor.Add(newProcessor);
                        newMerchant.Processor = newProcessor;
                    }
                }

                _globalCtx.Banks.Add(newBankModel);

                newBankAccountModel.Bank = newBankModel;
                newDebitCard.Bank        = newBankModel;

                _globalCtx.BankAccounts.Add(newBankAccountModel);
                _globalCtx.DebitCards.Add(newDebitCard);

                newMerchant.BankAccount = newBankAccountModel;
                newMerchant.DebitCard   = newDebitCard;

                //Set Merchant Status to "Admin Registered"
                newMerchant.MerchantStatus = _globalCtx.MerchantStatuses.FirstOrDefault(ms => ms.StatusDescription == "Pre-Enrolled");

                //Set Underwriting Status to "Pending"
                newMerchant.UnderwritingStatus = _globalCtx.UnderwritingStatuses.FirstOrDefault(ms => ms.StatusDescription == "Pending");

                newMerchant.AdvancePlan = _globalCtx.AdvancePlans.First(ap => ap.DefaultPlan == true);

                //Add new Merchant to context
                _globalCtx.Merchants.Add(newMerchant);

                //Add new merchant to selected User
                if (txtSelectedUserName.Text != "")
                {
                    var             manager      = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(_globalCtx));
                    ApplicationUser selectedUser = manager.FindByName(txtSelectedUserName.Text);
                    if (selectedUser != null)
                    {
                        selectedUser.Merchant = newMerchant;

                        //Save Context and Update DB
                        _globalCtx.SaveChanges();
                    }
                }
                else
                {
                    lblSubmissionMessage.Text = "Please select a User to join with this merchant.";
                    return(false);
                }
            }
            catch (System.Exception ex)
            {
                _newLogic.WriteExceptionToDB(ex, "AdminSubmitForm - Add Data to DB");
                return(false);
            }

            return(true);
        }