コード例 #1
0
        // GET: Manager/Statistics
        public ActionResult Index(int?campaignId)
        {
            IndexStatisticsModel result = new IndexStatisticsModel();
            string userId = this.User.Identity.GetUserId();

            if (campaignId != null)
            {
                Campaign campaign = this.data.Campaigns.Find(campaignId);
                if ((campaign != null) && (campaign.ManagerId == userId))
                {
                    CampaignStatisticsModel campaignStatistics = GetCampaignStatistics(campaign.CampaignId);
                    result.CampaignStatistics  = new[] { campaignStatistics };
                    result.CampaignId          = campaign.CampaignId;
                    result.OperatorsStatistics = this.GetOperatorStatistics(campaign.CampaignId);
                }
                else
                {
                    this.TempData["ErrorMessage"] = "Invalid campaign";
                }
            }

            var campaings = this.data.Campaigns.All()
                            .Where(c => c.ManagerId == userId)
                            .Select(c => new SelectListItem()
            {
                Text  = c.Description,
                Value = c.CampaignId.ToString()
            })
                            .ToList();

            campaings.Insert(0, new SelectListItem()
            {
                Text  = "Select campaign",
                Value = "0"
            });
            result.Campaigns = campaings;
            return(View(result));
        }
コード例 #2
0
        private CampaignStatisticsModel GetCampaignStatistics(int campaignId)
        {
            var calls = this.data.CallResults.All()
                        .Where(c => c.CampaignId == campaignId);
            int callsCount   = calls.Count();
            int statusSoldId = this.data.Statuses.All()
                               .First(s => s.Description == "Sold")
                               .StatusId;
            var soldCalls = calls.Where(c => c.StatusId == statusSoldId);
            int soldCount = soldCalls.Count();
            CampaignStatisticsModel campaignStatistics = new CampaignStatisticsModel();

            campaignStatistics.SoldToTotalCalls = (decimal)soldCount / callsCount;
            int callsTotalTime = calls.Sum(c => c.Duration);

            campaignStatistics.SoldToTotalTime = (decimal)soldCount / callsTotalTime;
            decimal price = this.data.Campaigns.Find(campaignId).Price *soldCount;

            campaignStatistics.TotelSoldPriceToTotalTime = callsTotalTime / price;
            int notAnswered = calls.Count(c => c.Status.Description == "No answer");

            campaignStatistics.NotAnsweredToTotalCalls = (decimal)notAnswered / callsCount;
            return(campaignStatistics);
        }