public List <Campaign> GetAll()
        {
            List <Campaign> campaigns = new List <Campaign>();

            using (var dbContext = new CSPDatabaseModelEntities())
            {
                using (var dataCampaignManager = new DataManagers.MarketingCampaignManager(dbContext))
                {
                    List <MarketingCampaign> campaignsDb = dataCampaignManager.GetAll <MarketingCampaign>(null, c => c.MarketingCampaignsCustomers).ToList();

                    campaigns = campaignsDb != null
                                   ? campaignsDb.Select(x => MarketingCampaignMapper.MapFromSource(x)).ToList()
                                   : null;
                }
            }

            return(campaigns);
        }
        public Campaign GetCampaign(string campaignId)
        {
            Campaign campaign = new Campaign();

            using (var dbContext = new CSPDatabaseModelEntities())
            {
                using (var dataCampaignManager = new DataManagers.MarketingCampaignManager(dbContext))
                {
                    MarketingCampaign campaignsDb = dataCampaignManager.FirstOrDefaultBy <MarketingCampaign>(c => c.Id != null &&
                                                                                                             c.Id.ToString() == campaignId, c => c.MarketingCampaignsCustomers);

                    campaign = campaignsDb != null
                                   ? MarketingCampaignMapper.MapFromSource(campaignsDb)
                                   : null;
                }
            }

            return(campaign);
        }
        public Campaign Create(Campaign campaign)
        {
            Campaign          campaignResult    = null;
            MarketingCampaign marketingCampaign = MarketingCampaignMapper.MapFromSource(campaign);

            using (var dbContext = new CSPDatabaseModelEntities())
            {
                using (var dataCampaignManager = new DataManagers.MarketingCampaignManager(dbContext))
                {
                    MarketingCampaign campaignDb = dataCampaignManager.AddOrUpdate <MarketingCampaign>(marketingCampaign, c => c.Id.ToString() == campaign.CampaignId);

                    MarketingCampaign campaignNew = dbContext.MarketingCampaigns.Include(c => c.MarketingCampaignsCustomers)
                                                    .Include(c => c.MarketingCampaignsCustomers.Select(x => x.Customer)).FirstOrDefault(c => c.Id == campaignDb.Id);

                    campaignResult = MarketingCampaignMapper.MapFromSource(campaignNew);
                }
            }

            return(campaignResult);
        }