Пример #1
0
        public ActionResult InsertChuDe([Bind(Include = "id,nametopic")] booktopic booktopic)
        {
            if (ModelState.IsValid)
            {
                var check_toppic = from s in db.booktopics
                                   where s.nametopic == booktopic.nametopic
                                   select s;
                if (check_toppic.Any())
                {
                    ViewBag.message = "Đã có chủ đề này";
                    return(View());
                }
                else
                {
                    db.booktopics.Add(booktopic);
                    db.SaveChanges();

                    ViewBag.message = "Thêm thành công";
                    ModelState.Clear();
                    return(View());
                }
            }

            //  ViewBag.id = new SelectList(db.books, "id", "booktitle", booktopic.id);
            return(View());
        }
        public ActionResult DeleteConfirmed(int id)
        {
            booktopic booktopic = db.booktopics.Find(id);

            db.booktopics.Remove(booktopic);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "id,nametopic")] booktopic booktopic)
 {
     if (ModelState.IsValid)
     {
         db.Entry(booktopic).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(booktopic));
 }
        public ActionResult Create([Bind(Include = "id,nametopic")] booktopic booktopic)
        {
            if (ModelState.IsValid)
            {
                db.booktopics.Add(booktopic);
                db.SaveChanges();
                ModelState.Clear();
                return(View());
            }

            return(View());
        }
        // GET: booktopics/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            booktopic booktopic = db.booktopics.Find(id);

            if (booktopic == null)
            {
                return(HttpNotFound());
            }
            return(View(booktopic));
        }