Exemple #1
0
        public ActionResult EditUserBudget(BudgetingPage currentPage, int budgetId)
        {
            var viewModel = new BudgetingPageViewModel
            {
                CurrentContent  = currentPage,
                NewBudgetOption = new BudgetViewModel(_budgetService.GetBudgetById(budgetId))
            };

            viewModel.NewBudgetOption.IsCurrentBudget = true;
            return(View(viewModel));
        }
Exemple #2
0
        public ActionResult AddBudgetToUser(BudgetingPage currentPage)
        {
            var viewModel = new BudgetingPageViewModel {
                CurrentContent = currentPage
            };
            var currentOrganization = !string.IsNullOrEmpty(_cookieService.Get(Constant.Fields.SelectedSuborganization))
               ? _organizationService.GetSubFoundationOrganizationById(_cookieService.Get(Constant.Fields.SelectedSuborganization))
               : _organizationService.GetCurrentFoundationOrganization();
            var budget = _budgetService.GetCurrentOrganizationBudget(currentOrganization.OrganizationId);

            if (budget == null)
            {
                return(RedirectToAction("Index"));
            }
            viewModel.NewBudgetOption = new BudgetViewModel(budget);

            return(View(viewModel));
        }
Exemple #3
0
        public ActionResult EditBudget(BudgetingPage currentPage, int budgetId)
        {
            var currentOrganization = !string.IsNullOrEmpty(_cookieService.Get(Constant.Fields.SelectedSuborganization))
                ? _organizationService.GetSubFoundationOrganizationById(_cookieService.Get(Constant.Fields.SelectedSuborganization))
                : _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));
        }
Exemple #4
0
        public ActionResult AddBudget(BudgetingPage currentPage)
        {
            var viewModel = new BudgetingPageViewModel {
                CurrentContent = currentPage
            };

            try
            {
                var selectedOrgId = _cookieService.Get(Constant.Fields.SelectedSuborganization);
                var org           = !string.IsNullOrEmpty(selectedOrgId)
                    ? _organizationService.GetFoundationOrganizationById(selectedOrgId)
                    : _organizationService.GetCurrentFoundationOrganization();
                _cookieService.Set(Constant.Fields.SelectedSuborganization, org.OrganizationId.ToString());
                _cookieService.Set(Constant.Fields.SelectedNavSuborganization, org.OrganizationId.ToString());
                if (!org.OrganizationEntity.IsParentOrganizationValid())
                {
                    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 {
                CurrentContent = currentPage
            };

            try
            {
                if (!string.IsNullOrEmpty(_cookieService.Get(Constant.Fields.SelectedSuborganization)))
                {
                    var suborganization           = _organizationService.GetSubOrganizationById(_cookieService.Get(Constant.Fields.SelectedSuborganization));
                    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));
        }
Exemple #6
0
        public ActionResult Index(BudgetingPage currentPage)
        {
            var selectedOrgId    = _cookieService.Get(Constant.Fields.SelectedSuborganization);
            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));
        }