// GET: ClientStatistics
        public ActionResult Query()
        {
            var accounts = context.ClientAccounts;

            var stationOptions = new SelectList(
                accounts.Select(
                    n => new SelectListItem()
            {
                Selected = false,
                Text     = n.ClientAccountName,
                Value    = n.ClientAccountId.ToString()
            }).ToList().Concat(new List <SelectListItem>()
            {
                new SelectListItem()
                {
                    Text = AllClientAccountName, Value = AllClientAccountId.ToString()
                }
            }),
                "Value",
                "Text",
                0);

            var model = new ClientStatisticsViewModel()
            {
                ClientAccountList = stationOptions
            };

            return(View(model));
        }
 public ActionResult Query([Bind(Include = "ClientAccountId, StartDate, EndDate")] ClientStatisticsViewModel clientStatistics)
 {
     if (ModelState.IsValid)
     {
         return(RedirectToAction(
                    "Show",
                    new
         {
             accountId = clientStatistics.ClientAccountId,
             startDate = clientStatistics.StartDate,
             endDate = clientStatistics.EndDate
         }));
     }
     else
     {
         throw new InvalidOperationException("非法请求");
     }
 }
        public ActionResult Show(long accountId, DateTime startDate, DateTime endDate)
        {
            var allStatistics = new ClientStatisticsViewModel();

            // The statistics for all the clients
            if (accountId == AllClientAccountId)
            {
                var accounts = context.ClientAccounts;

                allStatistics.ClientAccountId     = ClientStatisticsController.AllClientAccountId;
                allStatistics.ClientAccountName   = ClientStatisticsController.AllClientAccountName;
                allStatistics.StartDate           = startDate;
                allStatistics.EndDate             = endDate;
                allStatistics.ClientSubscriptions = new List <ClientSubscription>();


                foreach (var account in accounts)
                {
                    var statistics = GetClientStatistics(startDate, endDate, account);

                    allStatistics.TotalIncompleteQuantity          += statistics.TotalIncompleteQuantity;
                    allStatistics.TotalIncreasedBalance            += statistics.TotalIncreasedBalance;
                    allStatistics.TotalIncreasedLoan               += statistics.TotalIncreasedLoan;
                    allStatistics.TotalIncreasedSubscriptionAmount += statistics.TotalIncreasedSubscriptionAmount;
                    allStatistics.TotalPaidAmount += statistics.TotalPaidAmount;
                    allStatistics.TotalQuantity   += statistics.TotalQuantity;
                    allStatistics.ClientSubscriptions.AddRange(statistics.ClientSubscriptions);
                    allStatistics.Profit += statistics.Profit;
                }
            }
            else
            {
                var account = context.ClientAccounts.Find(accountId);

                allStatistics = GetClientStatistics(startDate, endDate, account);
            }

            return(View(allStatistics));
        }