public ActionResult Index(int orgId = 0) { var model = new AccountModel(); var allOrgs = DataSession.Query <Org>().OrderBy(x => x.OrgName).ToList(); var activeOrgs = allOrgs.Where(x => x.Active).OrderBy(x => x.OrgName).ToList(); var currentOrg = allOrgs.FirstOrDefault(x => x.OrgID == orgId); if (currentOrg == null) { currentOrg = allOrgs.First(x => x.PrimaryOrg); // throw an error if there isn't one } model.ActiveOrgs = activeOrgs.CreateModels <IOrg>(); model.CurrentOrg = currentOrg.CreateModel <IOrg>(); var activeAccounts = DataSession.Query <Account>().Where(x => x.Active && x.Org.OrgID == currentOrg.OrgID).OrderBy(x => x.Name).ToList(); model.ActiveAccounts = activeAccounts.CreateModels <IAccount>(); model.IsChartFieldOrg = AccountChartFields.IsChartFieldOrg(currentOrg.CreateModel <IOrg>()); return(View(model)); }
public ActionResult Edit(int orgId, int accountId) { var currentOrg = DataSession.Single <Org>(orgId); if (currentOrg == null) { return(RedirectToAction("Index", new { orgId })); } var model = new AccountEditModel { AccountID = accountId, CurrentOrg = currentOrg }; var fundingSources = DataSession.Query <FundingSource>().OrderBy(x => x.FundingSourceName).ToList(); model.FundingSources = fundingSources; var technicalFields = DataSession.Query <TechnicalField>().OrderBy(x => x.TechnicalFieldName).ToList(); model.TechnicalFields = technicalFields; var specialTopics = DataSession.Query <SpecialTopic>().OrderBy(x => x.SpecialTopicName).ToList(); model.SpecialTopics = specialTopics; Account acct = null; if (accountId > 0) { acct = DataSession.Single <Account>(accountId); if (acct == null && accountId > 0) { return(RedirectToAction("Index", new { orgId })); } if (acct.Org.OrgID != orgId) { return(RedirectToAction("Index", new { orgId })); } model.AccountName = acct.Name; } AccountEdit acctEdit; IAccount a = acct.CreateModel <IAccount>(); IOrg o = currentOrg.CreateModel <IOrg>(); if (Session["AccountEdit"] == null) { InitAccountEdit(a, o); } else { acctEdit = (AccountEdit)Session["AccountEdit"]; if (acctEdit.OrgID != currentOrg.OrgID || acctEdit.AccountID != accountId) { InitAccountEdit(a, o); } } acctEdit = (AccountEdit)Session["AccountEdit"]; model.AvailableManagers = AccountEditUtility.GetAvailableManagers(acctEdit); model.IsChartFieldOrg = AccountChartFields.IsChartFieldOrg(o); return(View(model)); }
private void InitAccountEdit(IAccount acct, IOrg org) { AccountEdit acctEdit = new AccountEdit(); // null means adding a new account if (acct != null) { acctEdit.OrgID = acct.OrgID; acctEdit.AccountID = acct.AccountID; acctEdit.AccountName = acct.AccountName; acctEdit.AccountNumber = acct.AccountNumber; acctEdit.AccountTypeID = acct.AccountTypeID; acctEdit.FundingSourceID = acct.FundingSourceID; acctEdit.Managers = AccountEditUtility.GetManagerEdits(acct.AccountID); acctEdit.ShortCode = acct.ShortCode.Trim(); acctEdit.SpecialTopicID = acct.SpecialTopicID; acctEdit.TechnicalFieldID = acct.TechnicalFieldID; acctEdit.InvoiceNumber = acct.InvoiceNumber; acctEdit.InvoiceLine1 = acct.InvoiceLine1; acctEdit.InvoiceLine2 = acct.InvoiceLine2; acctEdit.PoEndDate = acct.PoEndDate; acctEdit.PoInitialFunds = acct.PoInitialFunds; acctEdit.PoRemainingFunds = acct.PoRemainingFunds; acctEdit.Addresses = new Dictionary <string, AddressEdit> { { "billing", AccountEditUtility.GetAddressEdit(acct.BillAddressID) }, { "shipping", AccountEditUtility.GetAddressEdit(acct.ShipAddressID) } }; if (AccountChartFields.IsChartFieldOrg(org)) { var cf = ServiceProvider.Current.Data.Account.GetChartFields(acct); acctEdit.ChartFields = new AccountChartFieldEdit() { Account = cf.Account, Fund = cf.Fund, Department = cf.Department, Program = cf.Program, Class = cf.Class, Project = cf.Project, ShortCode = cf.ShortCode }; } } else { acctEdit.OrgID = org.OrgID; acctEdit.Managers = new List <AccountManagerEdit>(); acctEdit.Addresses = new Dictionary <string, AddressEdit> { { "billing", AccountEditUtility.GetAddressEdit(org.DefBillAddressID) }, { "shipping", AccountEditUtility.GetAddressEdit(org.DefShipAddressID) } }; acctEdit.AccountTypeID = 1; if (AccountChartFields.IsChartFieldOrg(org)) { acctEdit.ChartFields = new AccountChartFieldEdit(); } } Session["AccountEdit"] = acctEdit; }