Example #1
0
        /*
         *
         * protected TResponse GetResponse<TResponse>(string message = null) where TResponse : MobileResponse, new()
         * {
         *  return new TResponse
         *  {
         *      Success = null == message,
         *      Message = message,
         *
         *      Login = CurrentUser == null ? null : CurrentUser.Login,
         *      Name = CurrentUser == null ? null : CurrentUser.DisplayName,
         *      Wishlist = Wishlist == null ? 0 : Wishlist.Count,
         *      Points = CurrentLedger == null ? 0 : CurrentLedger.Balance,
         *      Budget = CurrentBudget == null ? -1 : CurrentBudget.Balance,
         *  };
         * }
         */

        protected void Init(string identityName)
        {
            // much simplified version of the SiteController.OnActionExecuting system.. deemed simple enough
            // not to justify another shared base class)
            if (String.IsNullOrEmpty(identityName))
            {
                CurrentUser     = null;
                CurrentLedger   = null;
                CurrentBudget   = null;
                CurrentWishlist = null;
            }
            else
            {
                CurrentUser   = Users[identityName];
                CurrentLedger = Accounting.GetPointsLedger(CurrentUser);
                CurrentBudget = Accounting.GetBudgetLedger(CurrentUser);
                if (null != CurrentBudget &&
                    null == CurrentBudget.Account.Budget &&
                    CurrentBudget.Balance <= 0)
                {
                    // if the user had a budget, but the balance has gone to zero (either because
                    // they gave out all points or we revoked the points), and we unchecked 'has budget',
                    // don't show the budget display at all anymore.s
                    CurrentBudget = null;
                }
                CurrentWishlist = CurrentUser.Wishlist;

                ViewData["currentUser"]       = CurrentUser;
                ViewData["currentUserLedger"] = CurrentLedger;
                ViewData["currentUserBudget"] = CurrentBudget;
                ViewData["wishlist"]          = CurrentWishlist;
            }
        }
Example #2
0
        public virtual ActionResult PointLiability()
        {
            if (String.IsNullOrEmpty(Request["tqx"]))
            {
                return(View());
            }

            var t = new GoogleVisualizationTable()
                    .AddColumn <string>("username", "User/Login Name", null)
                    .AddColumn <string>("firstname", "First Name", null)
                    .AddColumn <string>("lastname", "Last Name", null)
                    .AddColumn <string>("department", "Department", null)
                    .AddColumn <string>("manager", "Manager/Supervisor", null)
                    .AddColumn <int>("points", "Current Point Balance", "{0:n0}")
                    .AddColumn <int>("budget", "Current Budget Balance", "{0:n0}")
                    .AddColumn <string>("status", "Status (active only)", null)
                    .AddColumn <string>("account-created", "Account Creation Date", "{0:d}")
                    .AddColumn <string>("account-terminated", "Account Term. Date", "{0:d}")
                    .AddColumn <string>("last-login", "Last Logon Date", "{0:d}");

            var users = UserRepository.Where(x => x.State).Eq(UserState.Active).Spec().WithDocuments();

            foreach (var u in users.OrderBy(x => x.LastName))
            {
                var l = Accounting.GetPointsLedger(u);
                var b = Accounting.GetBudgetLedger(u);
                t.AddRow(
                    u.Login,
                    u.FirstName,
                    u.LastName,
                    String.IsNullOrWhiteSpace(u.Group) ? "" : Groups[u.Group].Name,
                    String.IsNullOrWhiteSpace(u.Manager) ? "" : Users[u.Manager].DisplayName,
                    null == l ? 0 : l.Balance,
                    null == b ? 0 : b.Balance,
                    u.State.ToString(),
                    u.DateActivated.HasValue ? u.DateActivated.Value.ToShortDateString() : "",
                    u.DateTerminated.HasValue ? u.DateTerminated.Value.ToShortDateString() : "",
                    u.LastSuccesfulLogin.HasValue ? u.LastSuccesfulLogin.Value.ToShortDateString() : ""
                    );
            }

            var r = new GoogleVisualizationResult(Request);

            r.Response.Table = t;
            return(r);
        }
        protected void ResolveLedger(ActionExecutingContext filterContext)
        {
            CurrentLedger = Accounting.GetPointsLedger(CurrentUser);
            ViewData["currentUserLedger"] = CurrentLedger;

            // budget will be null if user has no budget
            CurrentBudget = Accounting.GetBudgetLedger(CurrentUser);
            if (null != CurrentBudget &&
                null == CurrentBudget.Account.Budget &&
                CurrentBudget.Balance <= 0)
            {
                // if the user had a budget, but the balance has gone to zero (either because
                // they gave out all points or we revoked the points), and we unchecked 'has budget',
                // don't show the budget display at all anymore.s
                CurrentBudget = null;
            }
            ViewData["currentUserBudget"] = CurrentBudget;
        }