示例#1
0
        public ActionResult Create([Bind(Include = "IdKsiazka,IdAutor")] Autorstwo autorstwo)
        {
            ViewBag.IdKsiazka = autorstwo.IdKsiazka;

            if (ModelState.IsValid)
            {
                db.DodajAutorstwo(autorstwo.IdKsiazka, autorstwo.IdAutor);
                try {
                    db.SaveChanges();
                }
                catch (Exception e) {
                    string message = "";

                    if (e.InnerException == null)
                    {
                        message = "Podano nieprawidłowe dane autorstwa!";
                    }
                    else
                    {
                        message = e.InnerException.InnerException.Message;
                    }
                    ViewBag.Exception = message;
                    return(View(autorstwo));
                }
                return(RedirectToAction("Index", new { id = autorstwo.IdKsiazka }));
            }

            return(View(autorstwo));
        }