예제 #1
0
        public BalancePage()
        {
            InitializeComponent();

            var vm = new BalancePageViewModel();

            this.BindingContext = vm;
        }
        private void BuildViewModel(Item contextItem)
        {
            _bpvm = new BalancePageViewModel();

            _bpvm.BreadcrumbItems     = BreadcrumbItems;
            _bpvm.ShowAccountBalances = Sitecore.Context.PageMode.IsExperienceEditorEditing || Sitecore.Context.PageMode.IsPreview;

            var userData = _userDataService.GetUserIdamDataFromCookie(System.Web.HttpContext.Current);

            if (userData == null)
            {
                return;
            }

            //account balances
            var userAccountBalances = _userDataService.GetAccountBalancesFromSession(System.Web.HttpContext.Current);

            if (userAccountBalances == null)
            {
                var accounts = _nomisService.GetPrisonerAccounts(userData.PrisonId, userData.NameIdentifier);
                if (accounts != null)
                {
                    userAccountBalances = new UserAccountBalances(accounts.Spends, accounts.Savings, accounts.Cash,
                                                                  DateTime.UtcNow);
                }
                else
                {
                    userAccountBalances = new UserAccountBalances(decimal.MinusOne, decimal.MinusOne, decimal.MinusOne,
                                                                  DateTime.UtcNow);
                }
                _userDataService.SaveAccountBalancesToSession(System.Web.HttpContext.Current, userAccountBalances);
            }

            _bpvm.AccountBalancesAvailable   = userAccountBalances.AreAccountBalancesAvailable;
            _bpvm.AccountSpends              = userAccountBalances.AccountSpends;
            _bpvm.AccountPrivateCash         = userAccountBalances.AccountPrivateCash;
            _bpvm.AccountSavings             = userAccountBalances.AccountSavings;
            _bpvm.ShowAccountBalances        = (contextItem["Show Account Balances"] == "1" && _bpvm.AccountBalancesAvailable) || Sitecore.Context.PageMode.IsExperienceEditorEditing || Sitecore.Context.PageMode.IsPreview;
            _bpvm.AccountBalancesLastUpdated = userAccountBalances.AccountBalancesLastUpdated;



            //phone credit
            _bpvm.PhoneCredit           = 0; //TODO when BT API available
            _bpvm.ShowPhoneCredit       = contextItem["Show Phone Credit"] == "1";
            _bpvm.PhoneCreditLastUpdate = DateTime.Now;
        }