public EmailBasesCampaignStatsViewModel GetModel(int id)
        {
            var campaign = _db.Campaigns.First(c => c.CampaignType == Campaign.CampaignTypeEnum.EmailBases && c.CampaignId == id);

            if (_db.AcquireEmails.Count(a => a.RelatedCampaignId == id) != 0)
            {
                var newCampaign = new EmailBasesCampaignStatsViewModel()
                {
                    Campaign         = campaign,
                    TotalCount       = _db.AcquireEmails.Count(a => a.RelatedCampaignId == campaign.CampaignId),
                    NotVerifiedCount = _db.AcquireEmails.Count(a => a.RelatedCampaignId == campaign.CampaignId && a.AcquireEmailStatus != AcquireEmail.AcquireEmailStatusEnum.Verified),
                    CreatedPercent   = Math.Round(((_db.AcquireEmails.Count(a => a.RelatedCampaignId == campaign.CampaignId && a.AcquireEmailStatus == AcquireEmail.AcquireEmailStatusEnum.Created)
                                                    / (decimal)_db.AcquireEmails.Count(a => a.RelatedCampaignId == campaign.CampaignId)) * 100), 0),
                    CheckedPercent = Math.Round(((_db.AcquireEmails.Count(a => a.RelatedCampaignId == campaign.CampaignId && a.AcquireEmailStatus == AcquireEmail.AcquireEmailStatusEnum.Checked)
                                                  / (decimal)_db.AcquireEmails.Count(a => a.RelatedCampaignId == campaign.CampaignId)) * 100), 0),
                    VerifiedPercent = Math.Round(((_db.AcquireEmails.Count(a => a.RelatedCampaignId == campaign.CampaignId && (a.AcquireEmailStatus == AcquireEmail.AcquireEmailStatusEnum.Verified || a.AcquireEmailStatus == AcquireEmail.AcquireEmailStatusEnum.Reviewed))
                                                   / (decimal)_db.AcquireEmails.Count(a => a.RelatedCampaignId == campaign.CampaignId)) * 100), 0),
                };
                return(newCampaign);
            }
            else
            {
                var newCampaign = new EmailBasesCampaignStatsViewModel()
                {
                    Campaign         = campaign,
                    TotalCount       = 0,
                    NotVerifiedCount = 0,
                    CreatedPercent   = 0,
                    CheckedPercent   = 0,
                    VerifiedPercent  = 0
                };
                return(newCampaign);
            }
        }
        public IQueryable <EmailBasesCampaignStatsViewModel> GetModels()
        {
            var campaignsTemp = _db.Campaigns.Where(c => c.CampaignType == Campaign.CampaignTypeEnum.EmailBases && c.CampaignStatus != Campaign.CampaignStatusEnum.Completed);
            var list          = new List <EmailBasesCampaignStatsViewModel>();

            if (campaignsTemp.Count() != 0)
            {
                foreach (var campaign in campaignsTemp)
                {
                    var totalCount = _db.AcquireEmails.Count(a => a.RelatedCampaignId == campaign.CampaignId);
                    if (totalCount != 0)
                    {
                        var newCampaign = new EmailBasesCampaignStatsViewModel()
                        {
                            Campaign         = campaign,
                            TotalCount       = totalCount,
                            NotVerifiedCount = _db.AcquireEmails.Count(a =>
                                                                       a.RelatedCampaignId == campaign.CampaignId && a.AcquireEmailStatus !=
                                                                       AcquireEmail.AcquireEmailStatusEnum.Verified && a.AcquireEmailStatus != AcquireEmail.AcquireEmailStatusEnum.Reviewed),
                            CreatedPercent = Math.Round(((_db.AcquireEmails.Count(a =>
                                                                                  a.RelatedCampaignId == campaign.CampaignId &&
                                                                                  a.AcquireEmailStatus ==
                                                                                  AcquireEmail.AcquireEmailStatusEnum.Created)
                                                          / (decimal)_db.AcquireEmails.Count(a =>
                                                                                             a.RelatedCampaignId == campaign.CampaignId)) * 100), 0),
                            CheckedPercent = Math.Round(((_db.AcquireEmails.Count(a =>
                                                                                  a.RelatedCampaignId == campaign.CampaignId &&
                                                                                  a.AcquireEmailStatus ==
                                                                                  AcquireEmail.AcquireEmailStatusEnum.Checked)
                                                          / (decimal)_db.AcquireEmails.Count(a =>
                                                                                             a.RelatedCampaignId == campaign.CampaignId)) * 100), 0),
                            VerifiedPercent = Math.Round(((_db.AcquireEmails.Count(a =>
                                                                                   a.RelatedCampaignId == campaign.CampaignId &&
                                                                                   (a.AcquireEmailStatus ==
                                                                                    AcquireEmail.AcquireEmailStatusEnum.Verified || a.AcquireEmailStatus == AcquireEmail.AcquireEmailStatusEnum.Reviewed))
                                                           / (decimal)_db.AcquireEmails.Count(a =>
                                                                                              a.RelatedCampaignId == campaign.CampaignId)) * 100), 0),
                        };
                        list.Add(newCampaign);
                    }
                    else
                    {
                        var newCampaign = new EmailBasesCampaignStatsViewModel()
                        {
                            Campaign         = campaign,
                            TotalCount       = totalCount,
                            NotVerifiedCount = _db.AcquireEmails.Count(a => a.RelatedCampaignId == campaign.CampaignId && a.AcquireEmailStatus != AcquireEmail.AcquireEmailStatusEnum.Verified),
                            CreatedPercent   = 0,
                            CheckedPercent   = 0,
                            VerifiedPercent  = 0,
                        };
                        list.Add(newCampaign);
                    }
                }
                return(list.AsQueryable());
            }
            return(list.AsQueryable());
        }