Ejemplo n.º 1
0
 public ActionResult Edit([Bind(Include = "title_id,title1,type,pub_id,price,advance,royalty,ytd_sales,notes,pubdate")] title title, string[] author_ids)
 {
     if (ModelState.IsValid)
     {
         foreach (var ta in db.titleauthors.Where(ta => ta.title_id == title.title_id).ToList())
         {
             db.titleauthors.Remove(ta);
         }
         foreach (var aid in author_ids)
         {
             titleauthor ta = new titleauthor();
             ta.au_id    = aid;
             ta.title_id = title.title_id;
             db.titleauthors.Add(ta);
         }
         db.Entry(title).State = EntityState.Modified;
         db.SaveChanges();
         TempData["message_css"] = "alert alert-success";
         TempData["message"]     = "Successful";
         return(RedirectToAction("Index"));
     }
     ViewBag.pub_id          = new SelectList(db.publishers, "pub_id", "pub_name", title.pub_id);
     ViewBag.author_ids      = new MultiSelectList(db.authors.Select(a => new { id = a.au_id, au_fulname = a.au_lname + " " + a.au_fname }), "id", "au_fulname");
     TempData["message_css"] = "alert alert-danger";
     TempData["message"]     = "Invalid input";
     return(View(title));
 }
Ejemplo n.º 2
0
        public ActionResult Create([Bind(Include = "au_id,title_id,au_ord,royaltyper")] titleauthor titleauthor)
        {
            if (ModelState.IsValid)
            {
                var test = db.titleauthors.Find(titleauthor.au_id, titleauthor.title_id); //find if au_id and title_id (prim key's) already exists as a combination

                if (test == null)
                {
                    db.titleauthors.Add(titleauthor);
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (Exception e) //sql exception
                    {
                        return(RedirectToAction("../Home/Error"));
                    }
                }
                else //value already exists
                {
                    return(RedirectToAction("../Home/Error"));
                }

                return(RedirectToAction("Index"));
            }

            ViewBag.au_id    = new SelectList(db.authors, "au_id", "au_lname", titleauthor.au_id);
            ViewBag.title_id = new SelectList(db.titles, "title_id", "title1", titleauthor.title_id);
            return(View(titleauthor));
        }
        public ActionResult DeleteConfirmed(string id)
        {
            titleauthor titleauthor = db.titleauthors.Find(id);

            db.titleauthors.Remove(titleauthor);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 4
0
        public ActionResult DeleteConfirmed(string id)
        {
            string[]    splitid     = id.Split(',');
            titleauthor titleauthor = db.titleauthor.Find(splitid[0], splitid[1]);

            db.titleauthor.Remove(titleauthor);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 5
0
        // GET: titleauthors/Details/5
        public ActionResult Details(string au_id, string title_id)
        {
            titleauthor titleauthor = db.titleauthor.Find(au_id, title_id);

            if (titleauthor == null)
            {
                return(HttpNotFound());
            }
            return(View(titleauthor));
        }
 public ActionResult Edit([Bind(Include = "au_id,title_id,au_ord,royaltyper")] titleauthor titleauthor)
 {
     if (ModelState.IsValid)
     {
         db.Entry(titleauthor).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.au_id    = new SelectList(db.authors, "au_id", "au_lname", titleauthor.au_id);
     ViewBag.title_id = new SelectList(db.titles, "title_id", "title1", titleauthor.title_id);
     return(View(titleauthor));
 }
Ejemplo n.º 7
0
        // GET: titleauthors/Edit/5
        public ActionResult Edit(string au_id, string title_id)
        {
            titleauthor titleauthor = db.titleauthor.Find(au_id, title_id);

            if (titleauthor == null)
            {
                return(HttpNotFound());
            }
            ViewBag.au_id    = new SelectList(db.authors, "au_id", "au_lname", titleauthor.au_id);
            ViewBag.title_id = new SelectList(db.titles, "title_id", "title", titleauthor.title_id);
            return(View(titleauthor));
        }
        // GET: titleauthors/Details/5
        public ActionResult Details(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            titleauthor titleauthor = db.titleauthors.Find(id);

            if (titleauthor == null)
            {
                return(HttpNotFound());
            }
            return(View(titleauthor));
        }
Ejemplo n.º 9
0
        public ActionResult DeleteConfirmed(string au_id, string title_id)
        {
            titleauthor titleauthor = db.titleauthors.Find(au_id, title_id);

            db.titleauthors.Remove(titleauthor);
            try
            {
                db.SaveChanges();
            }
            catch (Exception e)
            {
                return(RedirectToAction("../Home/Error"));
            }
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 10
0
        // GET: titleauthors/Details/5
        public ActionResult Details(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            string[]    splitid     = id.Split(',');
            titleauthor titleauthor = db.titleauthor.Find(splitid[0], splitid[1]);

            if (titleauthor == null)
            {
                return(HttpNotFound());
            }
            return(View(titleauthor));
        }
        // GET: titleauthors/Edit/5
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            titleauthor titleauthor = db.titleauthors.Find(id);

            if (titleauthor == null)
            {
                return(HttpNotFound());
            }
            ViewBag.au_id    = new SelectList(db.authors, "au_id", "au_lname", titleauthor.au_id);
            ViewBag.title_id = new SelectList(db.titles, "title_id", "title1", titleauthor.title_id);
            return(View(titleauthor));
        }
Ejemplo n.º 12
0
        // GET: titleauthors/Details/5
        public ActionResult Details(string au_id, string title_id)
        {
            if (au_id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            if (title_id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            titleauthor titleauthor = db.titleauthors.Find(au_id, title_id);

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

            ViewBag.au_id    = new SelectList(db.titleauthors, "au_id", "au_id", titleauthor.au_id);
            ViewBag.title_id = new SelectList(db.titleauthors, "title_id", "title_id", titleauthor.title_id);
            return(View(titleauthor));
        }