public IHttpActionResult PutAuthors(long id, Authors authors) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != authors.Id_Author) { return(BadRequest()); } db.Entry(authors).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!AuthorsExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public static string AddEditorial(DBNexosBook db, Editorials editorial) { if (editorial.Name == null || editorial.AddressMail == null) { return("Los datos no son correctos"); } if (editorial.MaxBooks == 0) { editorial.MaxBooks = -1; } editorial.CurrenBooks = 0; db.Editorials.Add(editorial); db.SaveChanges(); return("Editor registrado con exito"); }
public static string AddBook(DBNexosBook db, BooksEntities books) { if (books.Title == null || books.Gender == null) { return("Los datos no son correctos"); } AuthorsController authorsController = new AuthorsController(); EditorialsController editorialsController = new EditorialsController(); var author = db.Authors.Where(x => x.Name == books.Author).FirstOrDefault(); if (author == null) { return("El autor no está registrado"); } var editorial = db.Editorials.Where(x => x.Name == books.Editorial).FirstOrDefault(); if (editorial == null) { return("La editorial no está registrada"); } if (editorial.CurrenBooks >= editorial.MaxBooks) { return("La editorial no tiene capacidad para mas libros"); } Books bookUpdate = new Books(); bookUpdate.Title = books.Title; bookUpdate.CreationDate = books.CreationDate; bookUpdate.Gender = books.Gender; bookUpdate.NumPages = books.NumPages; bookUpdate.Id_Author = author.Id_Author; bookUpdate.Id_Editorial = editorial.Id_Editorial; db.Books.Add(bookUpdate); db.SaveChanges(); editorial.CurrenBooks += 1; editorialsController.PutEditorials(editorial.Id_Editorial, editorial); return("El libro fue registrado con exito"); }