public async Task <int> CreateBook(Book book) { int DbResult = 0; int authorId = 0; if (dataReqiered.IsDataNoEmpty(book)) { bool isNewBook = await CheckingBookOnDuplicate(book); if (isNewBook) { authorId = Convert.ToInt32(book.AuthorId); BookPostgreSql newBook = new BookPostgreSql { Name = book.Name, Description = book.Description, Year = book.Year, AuthorId = authorId }; db.Books.Add(newBook); try { DbResult = await db.SaveChangesAsync(); } catch { return(DbResult); } } } return(DbResult); }
public async Task <int> CreateBook(Book book) { int DbResult = 0; if (dataReqiered.IsDataNoEmpty(book)) { bool isNewBook = await CheckingBookOnDuplicate(book); if (isNewBook) { BookMongoDb newBook = new BookMongoDb { Id = book.Id, Year = book.Year, Name = book.Name, Description = book.Description, AuthorId = book.AuthorId }; try { await db.Books.InsertOneAsync(newBook); DbResult = 1; } catch { return(DbResult); } } } return(DbResult); }
public async Task <HttpResponseMessage> CreateAuthor([FromBody] Author author) { int DbResult = 0; HttpResponseMessage RespMessage = new HttpResponseMessage(HttpStatusCode.BadRequest); if (dataReqiered.IsDataNoEmpty(author)) { DbResult = await repository.CreateAuthor(author); if (DbResult != 0) { RespMessage = new HttpResponseMessage(HttpStatusCode.Created); } } return(RespMessage); }
public async Task <IActionResult> CreateBook([FromBody] Book book) { int DbResult = 0; IActionResult ActionRes = BadRequest(); if (dataReqiered.IsDataNoEmpty(book)) { DbResult = await repository.CreateBook(book); if (DbResult != 0) { ActionRes = Ok(); } } return(ActionRes); }
public async Task <IActionResult> CreateAuthor([FromBody] Author author) { int DbResult = 0; IActionResult ActionRes = BadRequest(); if (dataReqiered.IsDataNoEmpty(author)) { DbResult = await repository.CreateAuthor(author); if (DbResult != 0) { ActionRes = Ok(author); } } return(ActionRes); }
public async Task <int> CreateAuthor(Author author) { int DbResult = 0; if (dataReqiered.IsDataNoEmpty(author)) { AuthorMsSql newAuthor = new AuthorMsSql { Name = author.Name, Surname = author.Surname }; db.Authors.Add(newAuthor); try { DbResult = await db.SaveChangesAsync(); } catch { return(DbResult); } } return(DbResult); }
public async Task <int> CreateAuthor(Author author) { int DbResult = 0; if (dataReqiered.IsDataNoEmpty(author)) { AuthorMongoDb newAuthor = new AuthorMongoDb { Id = author.Id, Name = author.Name, Surname = author.Surname }; try { await db.Authors.InsertOneAsync(newAuthor); DbResult = 1; } catch { return(DbResult); } } return(DbResult); }