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")); }
public ActionResult AddBook(Book book) { if (book.ISBN is null || book.Title is null) { return(BadRequest(new { errorText = "indexes can not be null" })); } var role = DataBase.GetRoleOfUser(studentId); if (role.canAdd) { if (DataBase.AddBook(book)) { return(Ok(book)); } return(BadRequest(new { errorText = "ISBN exists" })); } else { return(BadRequest(new { errorText = "You have no access." })); } }