// GET: GestionSub/Create
 public ActionResult Create()
 {
     Subscriber abonne = new Subscriber()
     {
         CreationDate = DateTime.Now
     };
     return View(abonne);
 }
Пример #2
0
        public ActionResult Abonnement(Subscriber abonne)
        {
            abonne.CreationDate = DateTime.Now;
            NewsContext db = new NewsContext();

            foreach (Category cat in db.Categories)
            {
                if (Request.Params[cat.CategoryName] != null)
                {
                    if (abonne.Categories == null)
                    {
                        abonne.Categories = new List<Category>();
                    }
                    abonne.Categories.Add(cat);
                }
            }
            db.Subscribers.Add(abonne);
            db.SaveChanges();

            return View("merci", abonne);
        }
        public ActionResult Edit(Subscriber subscriber)
        {
            if (ModelState.IsValid)
            {
                db.Entry(subscriber).State = EntityState.Modified;
                db.Entry(subscriber).Collection(p => p.Categories).Load();

                subscriber.Categories.Clear();
                foreach (Category cat in db.Categories)
                {
                    if (Request.Params["Categories."
                              + cat.CategoryName].StartsWith("true"))
                    {
                        subscriber.Categories.Add(cat);
                    }
                }

                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.listeCategories = db.Categories.ToList();
            return View(subscriber);
        }