public ActionResult EditUserBudget(BudgetingPage currentPage, int budgetId) { var viewModel = new BudgetingPageViewModel { CurrentPage = currentPage, NewBudgetOption = new BudgetViewModel(_budgetService.GetBudgetById(budgetId)) }; viewModel.NewBudgetOption.IsCurrentBudget = true; return(View(viewModel)); }
public IActionResult AddBudgetToUser(BudgetingPage currentPage) { var viewModel = new BudgetingPageViewModel { CurrentContent = currentPage }; var currentOrganization = !string.IsNullOrEmpty(_cookieService.Get(Constant.Fields.SelectedOrganization)) ? _organizationService.GetSubFoundationOrganizationById(_cookieService.Get(Constant.Fields.SelectedOrganization)) : _organizationService.GetCurrentFoundationOrganization(); var budget = _budgetService.GetCurrentOrganizationBudget(currentOrganization.OrganizationId); if (budget == null) { return(RedirectToAction("Index")); } viewModel.NewBudgetOption = new BudgetViewModel(budget); return(View(viewModel)); }
public ActionResult AddBudgetToUser(BudgetingPage currentPage) { var viewModel = new BudgetingPageViewModel { CurrentPage = currentPage }; var currentOrganization = !string.IsNullOrEmpty(Session[Constants.Fields.SelectedSuborganization]?.ToString()) ? _organizationService.GetSubOrganizationById(Session[Constants.Fields.SelectedSuborganization].ToString()) : _organizationService.GetCurrentUserOrganization(); var budget = _budgetService.GetCurrentOrganizationBudget(currentOrganization.OrganizationId); if (budget == null) { return(RedirectToAction("Index")); } viewModel.NewBudgetOption = new BudgetViewModel(budget); return(View(viewModel)); }
public ActionResult EditBudget(BudgetingPage currentPage, int budgetId) { var currentOrganization = !string.IsNullOrEmpty(Session[Constants.Fields.SelectedSuborganization]?.ToString()) ? _organizationService.GetSubOrganizationById(Session[Constants.Fields.SelectedSuborganization].ToString()) : _organizationService.GetCurrentUserOrganization(); var currentBudget = _budgetService.GetCurrentOrganizationBudget(currentOrganization.OrganizationId); var viewModel = new BudgetingPageViewModel { CurrentPage = currentPage, NewBudgetOption = new BudgetViewModel(_budgetService.GetBudgetById(budgetId)) }; if (currentBudget != null && currentBudget.BudgetId == budgetId) { viewModel.NewBudgetOption.IsCurrentBudget = true; } return(View(viewModel)); }
public IActionResult EditBudget(BudgetingPage currentPage, int budgetId) { var currentOrganization = !string.IsNullOrEmpty(_cookieService.Get(Constant.Fields.SelectedOrganization)) ? _organizationService.GetSubFoundationOrganizationById(_cookieService.Get(Constant.Fields.SelectedOrganization)) : _organizationService.GetCurrentFoundationOrganization(); var currentBudget = _budgetService.GetCurrentOrganizationBudget(currentOrganization.OrganizationId); var viewModel = new BudgetingPageViewModel { CurrentContent = currentPage, NewBudgetOption = new BudgetViewModel(_budgetService.GetBudgetById(budgetId)) }; if (currentBudget != null && currentBudget.BudgetId == budgetId) { viewModel.NewBudgetOption.IsCurrentBudget = true; } return(View(viewModel)); }
public IActionResult AddBudget(BudgetingPage currentPage) { var viewModel = new BudgetingPageViewModel { CurrentContent = currentPage }; try { var selectedOrgId = _cookieService.Get(Constant.Fields.SelectedOrganization); var org = !string.IsNullOrEmpty(selectedOrgId) ? _organizationService.GetFoundationOrganizationById(selectedOrgId) : _organizationService.GetCurrentFoundationOrganization(); _cookieService.Set(Constant.Fields.SelectedOrganization, org.OrganizationId.ToString()); _cookieService.Set(Constant.Fields.SelectedNavOrganization, org.OrganizationId.ToString()); if (!org.OrganizationEntity.ParentId.HasValue) { if (_currentMarket.GetCurrentMarket().Currencies is List <Currency> availableCurrencies) { var currencies = new List <string>(); currencies.AddRange(availableCurrencies.Select(currency => currency.CurrencyCode)); viewModel.AvailableCurrencies = currencies; } } else { var currentBudget = _budgetService.GetCurrentOrganizationBudget(org.OrganizationEntity.ParentId ?? Guid.Empty); viewModel.AvailableCurrencies = new List <string> { currentBudget.Currency }; viewModel.IsSubOrganization = true; viewModel.NewBudgetOption = new BudgetViewModel(currentBudget); } } catch (Exception ex) { LogManager.GetLogger(GetType()).Error(ex.Message, ex.StackTrace); return(RedirectToAction("Index")); } return(View(viewModel)); }
public ActionResult AddBudget(BudgetingPage currentPage) { var viewModel = new BudgetingPageViewModel { CurrentPage = currentPage }; try { if (!string.IsNullOrEmpty(Session[Constants.Fields.SelectedSuborganization]?.ToString())) { var suborganization = _organizationService.GetSubOrganizationById(Session[Constants.Fields.SelectedSuborganization].ToString()); var organizationCurrentBudget = _budgetService.GetCurrentOrganizationBudget(suborganization.ParentOrganization.OrganizationId); viewModel.AvailableCurrencies = new List <string> { organizationCurrentBudget.Currency }; viewModel.IsSubOrganization = true; viewModel.NewBudgetOption = new BudgetViewModel(organizationCurrentBudget); } else { var availableCurrencies = _currentMarket.GetCurrentMarket().Currencies as List <Currency>; if (availableCurrencies != null) { var currencies = new List <string>(); currencies.AddRange(availableCurrencies.Select(currency => currency.CurrencyCode)); viewModel.AvailableCurrencies = currencies; } } } catch (Exception ex) { LogManager.GetLogger(GetType()).Error(ex.Message, ex.StackTrace); return(RedirectToAction("Index")); } return(View(viewModel)); }
public ActionResult Index(BudgetingPage currentPage) { List <BudgetViewModel> organizationBudgets = new List <BudgetViewModel>(); List <BudgetViewModel> suborganizationsBudgets = new List <BudgetViewModel>(); var currentOrganization = !string.IsNullOrEmpty(Session[Constants.Fields.SelectedSuborganization]?.ToString()) ? _organizationService.GetSubOrganizationById(Session[Constants.Fields.SelectedSuborganization].ToString()) : _organizationService.GetCurrentUserOrganization(); var viewModel = new BudgetingPageViewModel { CurrentPage = currentPage, OrganizationBudgets = organizationBudgets }; viewModel.IsSubOrganization = !string.IsNullOrEmpty(Session[Constants.Fields.SelectedSuborganization]?.ToString()); var currentBudget = _budgetService.GetCurrentOrganizationBudget(currentOrganization.OrganizationId); if (currentBudget != null) { viewModel.CurrentBudgetViewModel = new BudgetViewModel(currentBudget); } var budgets = _budgetService.GetOrganizationBudgets(currentOrganization.OrganizationId); if (budgets != null) { organizationBudgets.AddRange(budgets.Select(budget => new BudgetViewModel(budget) { OrganizationName = currentOrganization.Name, IsCurrentBudget = (currentBudget?.BudgetId == budget.BudgetId) })); viewModel.OrganizationBudgets = organizationBudgets; } var suborganizations = currentOrganization.SubOrganizations; if (suborganizations != null) { foreach (var suborganization in suborganizations) { var suborgBudgets = _budgetService.GetCurrentOrganizationBudget(suborganization.OrganizationId); if (suborgBudgets != null) { suborganizationsBudgets.Add(new BudgetViewModel(suborgBudgets) { OrganizationName = suborganization.Name }); } viewModel.SubOrganizationsBudgets = suborganizationsBudgets; } } List <BudgetViewModel> purchasersBudgetsViewModel = new List <BudgetViewModel>(); var purchasersBudgets = _budgetService.GetOrganizationPurchasersBudgets(currentOrganization.OrganizationId); if (purchasersBudgets != null) { purchasersBudgetsViewModel.AddRange(purchasersBudgets.Select(purchaserBudget => new BudgetViewModel(purchaserBudget))); } viewModel.PurchasersSpendingLimits = purchasersBudgetsViewModel; viewModel.IsAdmin = CustomerContext.Current.CurrentContact.Properties[Constants.Fields.UserRole].Value.ToString() == Constants.UserRoles.Admin; return(View(viewModel)); }
public IActionResult Index(BudgetingPage currentPage) { var selectedOrgId = _cookieService.Get(Constant.Fields.SelectedOrganization); var isSubOrgSelected = !string.IsNullOrEmpty(selectedOrgId); var selectedOrg = isSubOrgSelected ? _organizationService.GetFoundationOrganizationById(selectedOrgId) : _organizationService.GetCurrentFoundationOrganization(); var viewModel = new BudgetingPageViewModel { CurrentContent = currentPage, IsSubOrganization = isSubOrgSelected, OrganizationBudgets = new List <BudgetViewModel>(), SubOrganizationsBudgets = new List <BudgetViewModel>(), PurchasersSpendingLimits = new List <BudgetViewModel>() }; if (selectedOrg != null) { var currentBudget = _budgetService.GetCurrentOrganizationBudget(selectedOrg.OrganizationId); if (currentBudget != null) { viewModel.CurrentBudgetViewModel = new BudgetViewModel(currentBudget); } var budgets = _budgetService.GetOrganizationBudgets(selectedOrg.OrganizationId); if (budgets != null) { viewModel.OrganizationBudgets.AddRange( budgets.Select(budget => new BudgetViewModel(budget) { OrganizationName = selectedOrg.Name, IsCurrentBudget = currentBudget?.BudgetId == budget.BudgetId }) ); } if (selectedOrg.SubOrganizations != null) { foreach (var subOrg in selectedOrg.SubOrganizations) { var budget = _budgetService.GetCurrentOrganizationBudget(subOrg.OrganizationId); if (budget != null) { viewModel.SubOrganizationsBudgets.Add(new BudgetViewModel(budget) { OrganizationName = subOrg.Name }); } } } var purchasersBudgets = _budgetService.GetOrganizationPurchasersBudgets(selectedOrg.OrganizationId); if (purchasersBudgets != null) { viewModel.PurchasersSpendingLimits.AddRange(purchasersBudgets.Select(purchaserBudget => new BudgetViewModel(purchaserBudget))); } } viewModel.IsAdmin = CustomerContext.Current.CurrentContact.Properties[Constant.Fields.UserRole].Value.ToString() == Constant.UserRoles.Admin; return(View(viewModel)); }