Ejemplo n.º 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;
            }
        }
Ejemplo n.º 2
0
        public virtual ActionResult Wishlist()
        {
            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 <string>("current-points", "Current Point Balance", "{0:n0}")
                    .AddColumn <string>("wishlist-item", "Wishlist Item Name", null)
                    .AddColumn <string>("wishlist-item-cost", "Wishlist Item Cost", "{0:n0}")
                    .AddColumn <string>("enough-points-item", "Enough Points Per Item", null)
                    .AddColumn <string>("points-needed-item", "Points Needed Per Item", "{0:n0}")
                    .AddColumn <string>("points-needed-all", "Points Needed For All Items", "{0:n0}");

            var users = UserRepository.GetUsersWithWishlists();

            foreach (var u in users.OrderBy(x => x.LastName))
            {
                var l       = Accounting.GetPointsLedger(u);
                var balance = l.Balance;
                var needed  = balance - u.Wishlist.Sum(x => x.Value.UnitPrice * x.Value.Quantity);
                foreach (var i in u.Wishlist)
                {
                    t.AddRow(
                        u.Login,
                        u.FirstName,
                        u.LastName,
                        String.IsNullOrWhiteSpace(u.Group) ? "" : Groups[u.Group].Name,
                        String.IsNullOrWhiteSpace(u.Manager) ? "" : Users[u.Manager].DisplayName,
                        balance,
                        i.Value.ProductName,
                        i.Value.UnitPrice * i.Value.Quantity,
                        (i.Value.UnitPrice * i.Value.Quantity) <= balance,
                        balance - (i.Value.UnitPrice * i.Value.Quantity),
                        needed
                        );
                }
            }

            var r = new GoogleVisualizationResult(Request);

            r.Response.Table = t;
            return(r);
        }
Ejemplo n.º 3
0
        public virtual ActionResult Distribute(string id)
        {
            if (!Accounting.CanDistributeBudget(CurrentUser, UserSummaries[id]))
            {
                throw new HttpException((int)HttpStatusCode.Forbidden, "You cannot distribute points to this user.");
            }

            var employee = Users[id];
            var model    = BudgetDistributionViewModel.Create(
                CurrentBudget,
                employee,
                Accounting.GetPointsLedger(employee));

            return(PartialView(model));
        }
Ejemplo n.º 4
0
        public virtual ActionResult Distribute(string userId)
        {
            if (!Accounting.CanDistributeBudget(CurrentUser, UserSummaries[userId]))
            {
                throw new HttpException((int)HttpStatusCode.Forbidden, "You cannot distribute points to this user.");
            }

            var employee = Users[userId];
            var model    = BudgetDistributionViewModel.Create(
                CurrentBudget,
                employee,
                Accounting.GetPointsLedger(employee));

            //return Request.IsAjaxRequest() ? (ActionResult)Json(model, JsonRequestBehavior.AllowGet) : PartialView(model);
            return(PartialView(model));
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        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;
        }