public ActionResult Create([Bind(Include = "CampaignID,CampaignName,ProductID,StartDate,EndDate")] Campaign campaign)
        {
            try
            {
                ViewData["ProductList"] = ProductList();

                if (ModelState.IsValid)
                {
                    campaign.Product = db.Products.Where(p => p.ID == campaign.ProductID).FirstOrDefault();
                    db.Campaigns.Add(campaign);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch (DataException)
            {
                ModelState.AddModelError("", "Unable to save changes");
            }

            return(View(campaign));
        }
Example #2
0
 public void AddCampaign(Model.Campaign C)
 {
     _db.Campaigns.Local.Add(C);
     _db.SaveChanges();
 }