Beispiel #1
0
        public ActionResult AddBook(string name, string authorFirst, string authorLast, string description)
        {
            DataBase Db     = new DataBase(connectionString);
            bool     exists = Db.CheckAuthor(authorFirst, authorLast);

            if (exists)
            {
                Author a = Db.GetAuthor(authorFirst, authorLast);
                Book   b = new Book();
                b.AuthorId    = a.Id;
                b.Name        = name;
                b.Description = description;
                Db.AddBook(b);
            }
            else
            {
                Author a = new Author();
                a.FirstName = authorFirst;
                a.LastName  = authorLast;
                Db.AddAuthor(a);
                Book b = new Book();
                b.AuthorId    = a.Id;
                b.Name        = name;
                b.Description = description;
                Db.AddBook(b);
            }
            return(RedirectToAction("Main"));
        }