Exemplo n.º 1
0
        // GET: Campaigns/Campaigns/Details/5
        public ActionResult Details(int id)
        {
            Campaign campaign           = _db.Campaigns.Find(id);
            var      model              = new CampaignDetailsViewModel();
            var      campaignBasesStats = new EmailBasesCampaignStatsViewModel();
            var      campaignSalesStats = new SalesCampaignStatsViewModel();

            if (campaign == null)
            {
                return(HttpNotFound());
            }

            var list = _db.CampaignMembers.Where(cm => cm.CampaignId == id);

            switch (campaign.CampaignType)
            {
            case Campaign.CampaignTypeEnum.EmailBases:
                model = new CampaignDetailsViewModel
                {
                    Campaign                   = campaign,
                    EmailBasesStats            = campaignBasesStats.GetModel(id),
                    SalesStats                 = null,
                    NumberOfUnassignedEntities = model.GetUnassignedEntities(id),
                    NumberOfUnassignedEntitiesWithoutTelephone = model.GetUnassignedEntitiesWithoutTelephone(id),
                    AssignedMembers = list,
                    AssignedAgents  = model.GetAssignedAgentsInfo(id),
                    EmailsBasesEntityStatusStats              = model.GetEmailBasesEntityStats(id),
                    SalesOpportunitiesStatusStats             = null,
                    SalesLeadsStatusStats                     = null,
                    SalesGeneralStatus                        = null,
                    CampaignLeadsAgentEfficiencies            = null,
                    CampaignAttributes                        = campaign.CampaignAttributes,
                    NumberOfNewlyAcquiredReceivingInformation = _db.AcquireEmails.Count(ae => ae.RelatedCampaignId == id && ae.IsNewlyAcquired == true)
                };
                return(View(model));

            case Campaign.CampaignTypeEnum.Sales:
                model = new CampaignDetailsViewModel
                {
                    Campaign                   = campaign,
                    EmailBasesStats            = null,
                    SalesStats                 = campaignSalesStats.GetModel(id),
                    NumberOfUnassignedEntities = model.GetUnassignedEntities(id),
                    NumberOfUnassignedEntitiesWithoutTelephone = model.GetUnassignedEntitiesWithoutTelephone(id),
                    AssignedMembers = list,
                    AssignedAgents  = model.GetAssignedAgentsInfo(id),
                    EmailsBasesEntityStatusStats              = null,
                    SalesOpportunitiesStatusStats             = model.GetOpportunitiesSalesStatusStats(id),
                    SalesLeadsStatusStats                     = model.GetLeadsSalesStatusStats(id),
                    SalesGeneralStatus                        = model.GetSalesGeneralStatus(id),
                    CampaignLeadsAgentEfficiencies            = model.GetCampaignLeadsAgentEfficiencies(id),
                    CampaignAttributes                        = campaign.CampaignAttributes,
                    NumberOfNewlyAcquiredReceivingInformation = null
                };
                return(View(model));
            }
            return(View(model));
        }
        // GET: Campaigns/Campaigns/Details/5
        public ActionResult Details(int id)
        {
            _campaignHelper.UpdateCampaignMembers(id);

            Campaign campaign               = _db.Campaigns.Find(id);
            var      model                  = new CampaignDetailsViewModel();
            var      campaignBasesStats     = new EmailBasesCampaignStatsViewModel();
            var      campaignSalesStats     = new SalesCampaignStatsViewModel();
            var      campaignEducationStats = new EducationCampaignStatsViewModel();

            if (campaign == null)
            {
                return(HttpNotFound());
            }

            if (_contractHelper.GetContractDate(campaign.RelatedCompanyId) != null)
            {
                campaign.ContractStartDate = _contractHelper.GetContractDate(campaign.RelatedCompanyId);
            }
            _db.SaveChanges();

            var list = _db.CampaignMembers.Where(cm => cm.CampaignId == id);

            // Preparing DetailsView based on the CampaignType
            switch (campaign.CampaignType)
            {
            case Campaign.CampaignTypeEnum.EmailBases:
                model = new CampaignDetailsViewModel
                {
                    Campaign                   = campaign,
                    EmailBasesStats            = campaignBasesStats.GetModel(id),
                    SalesStats                 = null,
                    EducationStats             = null,
                    NumberOfUnassignedEntities = model.GetUnassignedEntities(id),
                    NumberOfUnassignedEntitiesWithoutTelephone = model.GetUnassignedEntitiesWithoutTelephone(id),
                    AssignedMembers = list,
                    AssignedAgents  = model.GetAssignedAgentsInfo(id, 1),
                    EmailsBasesEntityStatusStats              = model.GetEmailBasesEntityStats(id),
                    SalesOpportunitiesStatusStats             = null,
                    SalesLeadsStatusStats                     = null,
                    SalesGeneralStatus                        = null,
                    EducationStatusStats                      = null,
                    CampaignLeadsAgentEfficiencies            = null,
                    CampaignAttributes                        = campaign.CampaignAttributes,
                    NumberOfNewlyAcquiredReceivingInformation = _db.AcquireEmails.Count(ae => ae.RelatedCampaignId == id && ae.IsNewlyAcquired == true),
                    NumberOfEducationAtendees                 = null
                };
                return(View(model));

            case Campaign.CampaignTypeEnum.Sales:
                model = new CampaignDetailsViewModel
                {
                    Campaign                   = campaign,
                    EmailBasesStats            = null,
                    SalesStats                 = campaignSalesStats.GetModel(id),
                    EducationStats             = null,
                    NumberOfUnassignedEntities = model.GetUnassignedEntities(id),
                    NumberOfUnassignedEntitiesWithoutTelephone = model.GetUnassignedEntitiesWithoutTelephone(id),
                    AssignedMembers = list,
                    AssignedAgents  = model.GetAssignedAgentsInfo(id, 3),
                    EmailsBasesEntityStatusStats              = null,
                    SalesOpportunitiesStatusStats             = model.GetOpportunitiesSalesStatusStats(id),
                    SalesLeadsStatusStats                     = model.GetLeadsSalesStatusStats(id),
                    SalesGeneralStatus                        = model.GetSalesGeneralStatus(id),
                    EducationStatusStats                      = null,
                    CampaignLeadsAgentEfficiencies            = model.GetCampaignLeadsAgentEfficiencies(id),
                    CampaignAttributes                        = campaign.CampaignAttributes,
                    NumberOfNewlyAcquiredReceivingInformation = null,
                    NumberOfEducationAtendees                 = null
                };
                return(View(model));

            case Campaign.CampaignTypeEnum.Education:
                model = new CampaignDetailsViewModel
                {
                    Campaign                   = campaign,
                    EmailBasesStats            = null,
                    SalesStats                 = null,
                    EducationStats             = campaignEducationStats.GetModel(id),
                    NumberOfUnassignedEntities = 0,
                    NumberOfUnassignedEntitiesWithoutTelephone = 0,
                    AssignedMembers = list,
                    AssignedAgents  = model.GetAssignedAgentsInfo(id, 2),
                    EmailsBasesEntityStatusStats              = null,
                    SalesOpportunitiesStatusStats             = null,
                    SalesLeadsStatusStats                     = null,
                    SalesGeneralStatus                        = null,
                    EducationStatusStats                      = model.GetEducationStatusStats(id),
                    CampaignLeadsAgentEfficiencies            = null,
                    CampaignAttributes                        = campaign.CampaignAttributes,
                    NumberOfNewlyAcquiredReceivingInformation = null,
                    NumberOfEducationAtendees                 = _db.Educations.Where(e => e.RelatedCampaignId == id && e.AtendeesNumber != null).Sum(c => c.AtendeesNumber)
                };
                return(View(model));
            }
            return(View(model));
        }