public async Task <IActionResult> Update(int Id, [FromBody] BookUpdateDTO bookDTO) { var location = GetControllerActionName(); try { _logger.LogInfo($"{location} : Attempt Book Update"); if (Id < 1 || bookDTO == null || Id != bookDTO.Id) { _logger.LogWarn($"{location} : Emtpy request was submitted"); return(BadRequest()); } var Exists = await _bookRepository.isExists(Id); if (!Exists) { return(NotFound()); } var author = await _bookRepository.FindById(Id); var isSuccess = await _bookRepository.Update(author); if (!isSuccess) { return(InternalError($"{location} : book Update failed")); } _logger.LogInfo($"{location} : book Updated"); return(NoContent()); } catch (Exception e) { return(InternalError($"{e.Message} - {e.InnerException}")); } }
public async Task <IActionResult> Update(int id, [FromBody] BookUpdateDTO bookDTO) { var location = GetControllerActionNames(); try { _logger.LogInfo("Update started"); if (id < 1 || bookDTO == null || id != bookDTO.Id) { _logger.LogWarn("Empty request"); return(BadRequest()); } var isExists = await _bookRepository.IsExists(id); if (!isExists) { _logger.LogWarn("Author does not exists"); return(BadRequest()); } var book = _mapper.Map <Book>(bookDTO); var isSuccess = await _bookRepository.Update(book); if (!isSuccess) { return(InternalError("Book update failed")); } _logger.LogInfo("Book updated"); return(NoContent()); } catch (Exception ex) { return(InternalError($"{location}: Something went wrong: {ex.Message}")); } }
public async Task <IActionResult> Update(int id, [FromBody] BookUpdateDTO bookDTO) { var location = GetControllerAndActionNames(); try { if (id < 1 || bookDTO == null || id != bookDTO.Id) { return(BadRequest(ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var book = _mapper.Map <Book>(bookDTO); var isSuccess = await _repository.Update(book); if (!isSuccess) { return(InternalError($"{location} - Book Updation is failed")); } return(NoContent()); } catch (Exception ex) { return(InternalError($"{location} : {ex.Message}-{ex.InnerException}")); } }
public async Task <IActionResult> Update(int id, [FromBody] BookUpdateDTO bookDTO) { try { if (id < 1 || bookDTO == null || id != bookDTO.Id) { return(BadRequest(ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var isExists = await _bookRepository.IsExists(id); if (!isExists) { return(NotFound()); } var book = _mapper.Map <Book>(bookDTO); var isSuccess = await _bookRepository.Update(book); if (!isSuccess) { return(InternalError()); } return(NoContent()); } catch (Exception) { return(InternalError()); } }
public IActionResult Put(int publisherId, int id, [FromBody] BookUpdateDTO DTO) { if (DTO == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var entity = _rep.Get <Book>(id); if (entity == null) { return(NotFound()); } Mapper.Map(DTO, entity); if (!_rep.Save()) { return(StatusCode(500, "A problem happened while handling your request.")); } return(NoContent()); }
public async Task <IActionResult> Update(int id, [FromBody] BookUpdateDTO bookDto) { var location = GetControllerActionNames(); try { _logger.LogInfo($"{location} Update Attempted with id: {id}"); if (id < 1 || bookDto == null || id != bookDto.Id) { _logger.LogWarn($"{location} : Update failed with bad date - id : {id} "); return(NotFound()); } var isExists = await _bookRepository.IsExists(id); if (!isExists) { _logger.LogWarn($"{location} : Failed to find data with - id : {id} "); return(BadRequest(ModelState)); } var book = _mapper.Map <Book>(bookDto); var isSucesss = await _bookRepository.Update(book); if (!isSucesss) { return(InternalError($"{location} : Failed update id : {id}")); } _logger.LogWarn($"{location} Record with id : {id} sucessfully updated"); return(NoContent()); } catch (Exception e) { return(InternalError($"{location} : {e.Message} - {e.InnerException}")); } }
public IActionResult Patch(int publisherId, int id, [FromBody] JsonPatchDocument <BookUpdateDTO> book) { if (book == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var bookToUpdate = _rep.GetBook(publisherId, id); if (bookToUpdate == null) { return(NotFound()); } var bookToPatch = new BookUpdateDTO() { PublisherId = bookToUpdate.PublisherId, Title = bookToUpdate.Title }; book.ApplyTo(bookToPatch, ModelState); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // here bookToPatch is used? _rep.UpdateBook(publisherId, id, bookToPatch); _rep.Save(); return(NoContent()); }
public async Task <IActionResult> Update(int id, [FromBody] BookUpdateDTO bookDTO) { var location = GetControllerActionName(); try { _logger.LogInfo($"{location}: Update attempted on record with id: {id}"); if (id < 1 || bookDTO == null || id != bookDTO.Id) { _logger.LogWarn($"{location}: Update failed with bad data - id: {id}"); return(BadRequest()); } var isExists = await _bookRepository.IsExists(id); if (!isExists) { _logger.LogWarn($"{location}: Failed to retrieve record with id: {id}"); return(NotFound()); } if (!ModelState.IsValid) { _logger.LogWarn($"{location}: Data was incomplete"); return(BadRequest()); } var oldImage = await _bookRepository.GetImageFileName(id); var book = _mapper.Map <Book>(bookDTO); var isSuccess = await _bookRepository.Update(book); if (!isSuccess) { return(InternalError($"{location}: Update failed for record with id: {id}")); } if (!bookDTO.Image.Equals(oldImage)) { if (System.IO.File.Exists(GetImagePath(oldImage))) { System.IO.File.Delete(GetImagePath(oldImage)); } } if (!string.IsNullOrEmpty(bookDTO.File)) { var imgPath = GetImagePath(bookDTO.Image); byte[] imgBytes = Convert.FromBase64String(bookDTO.File); System.IO.File.WriteAllBytes(imgPath, imgBytes); } _logger.LogInfo($"{location}: Record with id: {id} successfully updated"); return(NoContent()); } catch (Exception e) { return(InternalError($"{location}: {e.Message} - {e.InnerException}")); } }
public async Task <IActionResult> Update(int id, [FromBody] BookUpdateDTO bookUpdateDTO) { var location = GetControllerActionNames(); try { _logger.LogInfo($"End user attempted to an update existing Book with ID number: {id}."); if (id < 1 || bookUpdateDTO == null || id != bookUpdateDTO.Id) { _logger.LogWarn($"End user sent an HTTP 1.1 POST request to create a new Book with invalid Book data!"); return(BadRequest()); } if (!ModelState.IsValid) { _logger.LogWarn($"End user sent an HTTP 1.1 POST request to create a new Book with invalid Book data!"); return(BadRequest(ModelState)); } var book = _mapper.Map <Book>(bookUpdateDTO); var isSuccess = await _bookRepository.Update(book); if (!isSuccess) { _logger.LogWarn($"End user sent an HTTP 1.1 POST request to create a new Book with invalid Book data!"); return(InternalError($"Failed updating Author!")); } _logger.LogWarn($"{location}: Successfully updated Book with ID number {id}!"); return(NoContent()); } catch (Exception exception) { return(InternalError($"{location}: {exception.Message} - {exception.InnerException}")); } }
public async Task <IActionResult> Update(int id, [FromBody] BookUpdateDTO bookDTO) { var location = GetControllerActionNames(); try { if (id < 1 || bookDTO == null || id != bookDTO.Id) { return(BadRequest()); } var isExists = await _bookRepository.isExists(id); if (!isExists) { return(NotFound()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var book = _mapper.Map <Book>(bookDTO); var isSuccess = await _bookRepository.Update(book); if (!isSuccess) { return(InternalError($"{location}: Update failed for record with id: {id}")); } return(NoContent()); } catch (Exception e) { return(InternalError($"{location}: {e.Message} - {e.InnerException}")); } }
public async Task <IActionResult> Update(int id, [FromBody] BookUpdateDTO bookDTO) { try { if (bookDTO == null || id < 1 || id != bookDTO.Id) { return(BadRequest(ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var book = _mapper.Map <Book>(bookDTO); var isSuccess = await _bookRepository.Update(book); if (!isSuccess) { return(InternalError("Book creation failed")); } return(NoContent()); } catch (Exception e) { return(InternalError($"{e.Message}- {e.InnerException}")); } }
public async Task <IActionResult> UpdatePut(int id, [FromBody] BookUpdateDTO bookDTO) { var location = GetControllerActionNames(); try { _logger.LogInfo($"Author Update attempted"); if (id < 1 || bookDTO == null || id != bookDTO.Id) { _logger.LogInfo($"Id {id} does not exist! Or "); return(BadRequest()); } if (!ModelState.IsValid) { _logger.LogInfo($"Author data incomplete or not accepted"); return(BadRequest(ModelState)); } var bookUpdate = _map.Map <Book>(bookDTO); var isSuccess = await _bookRepository.Update(bookUpdate); if (!isSuccess) { return(internalError($"Author update failed")); } return(NoContent()); } catch (Exception e) { return(internalError($"{e.Message}-{e.InnerException}")); } }
public async Task <BookDTO> PatchAsync(BookUpdateDTO book) { this.Logger.LogTrace($"{nameof(this.PutAsync)} called"); var result = await this.BookUpdateService.UpdateAsync(this.Mapper.Map <BookUpdateModel>(book)); return(this.Mapper.Map <BookDTO>(result)); }
public async Task <IActionResult> Update(int id, [FromBody] BookUpdateDTO bookDTO) { var location = GetControllerActionNames(); try { if (id < 1 || bookDTO == null || id != bookDTO.Id) { _logger.LogWarn($"Empty Request was submitted"); return(BadRequest(ModelState)); } var isExists = await _bookRepository.isExists(id); if (!isExists) { return(NotFound()); } if (!ModelState.IsValid) { _logger.LogWarn($"Bad Data Dude"); return(BadRequest(ModelState)); } var oldImage = await _bookRepository.GetImageFileName(id); var book = _mapper.Map <Book>(bookDTO); var isSuccess = await _bookRepository.Update(book); if (!isSuccess) { _logger.LogWarn($"Bad Data Dude"); return(InternalError($"Did not Update to Flys Book store ")); } if (!bookDTO.Image.Equals(oldImage)) { if (System.IO.File.Exists(GetImagePath(oldImage))) { System.IO.File.Delete(GetImagePath(oldImage)); } } if (!string.IsNullOrEmpty(bookDTO.File)) { byte[] imageBytes = Convert.FromBase64String(bookDTO.File); System.IO.File.WriteAllBytes(GetImagePath(bookDTO.Image), imageBytes); } return(NoContent()); } catch (Exception e) { return(InternalError($"{e.Message } - {e.StackTrace }")); } }
public void UpdateBook(int publisherId, int bookId, BookUpdateDTO book) { var bookToUpdate = _db.Books.FirstOrDefault(b => b.PublisherId.Equals(publisherId) && b.Id.Equals(bookId)); if (bookToUpdate == null) { return; } bookToUpdate.Title = book.Title; bookToUpdate.PublisherId = book.PublisherId; }
public async Task <IActionResult> Edit(int id, BookUpdateDTO updatedBook) { if (id != updatedBook.Id) { return(NotFound()); } var book = Mapper.Map <BookDTO>(await BookUpdateService.UpdateAsync(Mapper.Map <BookUpdateModel>(updatedBook))); return(Redirect($"/books/{book.Id}")); }
public async Task <IActionResult> Update(int id, [FromBody] BookUpdateDTO bookDTO) { try { Info($"Book update attempted for id {id}"); if (id < 1 || bookDTO == null || id != bookDTO.Id) { Warn($"Update failed (bad id {id})"); return(BadRequest(ModelState)); } var doesExist = await _bookRepository.DoesExist(id); if (!doesExist) { Warn($"Failed to retrieve book with id {id}."); return(NotFound()); } if (!ModelState.IsValid) { Warn($"Invalid modelstate '{ModelState}'"); return(BadRequest(ModelState)); } var oldImage = await _bookRepository.GetImageFileName(id); var book = _mapper.Map <Book>(bookDTO); var isSuccess = await _bookRepository.Update(book); if (!isSuccess) { return(InternalError($"{By()}Book {id} '{book}' update failed.")); } if (!bookDTO.Image.Equals(oldImage) && System.IO.File.Exists(GetImagePath(oldImage))) { System.IO.File.Delete(GetImagePath(oldImage)); } if (!string.IsNullOrEmpty(bookDTO.File)) { var imageBytes = Convert.FromBase64String(bookDTO.File); System.IO.File.WriteAllBytes (GetImagePath(bookDTO.Image), imageBytes); } Info($"Book with id {id} updated"); return(NoContent()); } catch (Exception e) { return(InternalError(e)); } }
public async Task <IActionResult> Update(int id, [FromBody] BookUpdateDTO bookDTO) { try { this.loggerService.LogInfo($"{this.GetControllerActionNames()}: Update attempted on record with Id: {id}"); if (id <= 0 || id != bookDTO.Id) { this.loggerService.LogWarning($"{this.GetControllerActionNames()}: Update failed with bad data - Id: {id}"); return(BadRequest("Invalid book identifier passed through.")); } if (bookDTO == null) { this.loggerService.LogWarning($"{this.GetControllerActionNames()}: Data was empty"); return(BadRequest(ModelState)); } if (!ModelState.IsValid) { this.loggerService.LogWarning($"{this.GetControllerActionNames()}: Data was incomplete"); return(BadRequest(ModelState)); } var doesExist = await this.bookRepository.DoesExist(id); if (!doesExist) { return(NotFound($"{this.GetControllerActionNames()}: No record found with Id: {id}")); } var book = this.mapper.Map <Book>(bookDTO); var isSuccess = await this.bookRepository.Update(book); if (isSuccess) { this.loggerService.LogInfo($"{this.GetControllerActionNames()}: Update successful for record with Id: {id}"); return(NoContent()); } else { this.loggerService.LogError($"{this.GetControllerActionNames()}: Update failed for record with Id: {id}"); return(StatusCode(StatusCodes.Status500InternalServerError, "Book update failed.")); } } catch (Exception exc) { return(this.InternalError(exc)); } }
public async Task <ActionResult> UpdateBook(int id, [FromBody] BookUpdateDTO bookUpdateDTO) { var book = await _bookRepository.GetByIdAsync(id); if (book == null) { return(NotFound(new ApiResponse(404))); } _mapper.Map(bookUpdateDTO, book); await _bookRepository.Update(book); return(NoContent()); }
public ActionResult UpdateBook(int id, BookUpdateDTO bookToUpdate) { var bookModel = _mockLibreria.GetBookById(id); if (bookModel == null) { return(NotFound()); } _mapper.Map(bookToUpdate, bookModel); _mockLibreria.UpdateBook(bookModel); _mockLibreria.SaveChanges(); return(NoContent()); }
public async Task <IActionResult> Update(int Id, [FromBody] BookUpdateDTO bookDTO) { string location = GetControllerActionNames(); try { _logger.LogInfo($"{location}: Update attempted on record with Id: {Id}."); if (Id < 1 || bookDTO == null || Id != bookDTO.Id) { _logger.LogWarn($"{location}: Update failed with bad data - Id: {Id}"); return(BadRequest()); } bool isExists = await _bookRepository.isExists(Id); if (!isExists) { _logger.LogWarn($"{location}: Failed to retrieve record with Id: {Id}."); return(NotFound()); } if (!ModelState.IsValid) { _logger.LogWarn($"{location}: Data was incomplete."); return(BadRequest(ModelState)); } Book book = _mapper.Map <Book>(bookDTO); bool isSuccess = await _bookRepository.Update(book); if (!isSuccess) { return(InternalError($"{location}: Update failed for record with Id: {Id}.")); } _logger.LogInfo($"{location}: Record with Id: {Id} successfully updated."); return(NoContent()); } catch (Exception e) { return(InternalError($"{location}: {e.Message} - {e.InnerException}")); } }
public async Task <IActionResult> Update(int id, [FromBody] BookUpdateDTO bookUpdateDTO) { var location = GetControllerActionNames(); try { _logger.LogInfo($"{location} : Update Attempted on record with id: {id}"); if (id < 0 || bookUpdateDTO is null || id != bookUpdateDTO.Id) { _logger.LogWarn($"{location}: Updated failed with id: {id}"); return(BadRequest()); } var isExists = await _bookRepository.Exists(id); if (!isExists) { _logger.LogWarn($"{location}: Failed to find record with id: {id}"); return(NotFound()); } if (!ModelState.IsValid) { _logger.LogWarn($"{location}: Data was Incomplete"); return(BadRequest(ModelState)); } var oldImage = await _bookRepository.GetImageFileName(id); var book = _mapper.Map <Book>(bookUpdateDTO); var isSuccess = await _bookRepository.Update(book); if (!isSuccess) { return(StatusCode(500, $"{location}: Failed Update with id:{id}")); } StoreFileImg(bookUpdateDTO.File, bookUpdateDTO.Image, oldImage); _logger.LogInfo($"{location}: Update successful with id: {id}"); return(Ok(book)); } catch (Exception e) { return(InternalError(e, location)); } }
public async Task <IActionResult> Update(int id, [FromBody] BookUpdateDTO bookUpdateDTO) { var controllerAction = GetControllerActionNames(); try { _logger.LogInfo($"{controllerAction}: Attempted For ID {id}"); if (id < 1 || bookUpdateDTO == null || id != bookUpdateDTO.ID) { _logger.LogWarn($"{controllerAction}: Missing Data Or Invalid ID"); return(BadRequest(ModelState)); } var exists = await _bookRepository.Exists(id); if (!exists) { _logger.LogWarn($"{controllerAction}: ID {id} Not Found"); return(NotFound()); } if (!ModelState.IsValid) { _logger.LogWarn($"{controllerAction}: Invalid Or Incomplete Data Submitted"); return(BadRequest(ModelState)); } var book = _mapper.Map <Book>(bookUpdateDTO); var isSuccess = await _bookRepository.Update(book); if (!isSuccess) { return(InternalError($"{controllerAction}: Failed")); } _logger.LogInfo($"{controllerAction}: Successful For ID {id}"); return(NoContent()); } catch (Exception e) { return(InternalError($"{controllerAction}: {e.Message} - {e.InnerException}")); } }
public async Task <IActionResult> Update(int id, [FromBody] BookUpdateDTO bookDTO) { var location = GetControllerActionNames(); try { _logger.LogInfo($"{location}: Update attempted Record id: {id}"); if (id < 1 || bookDTO == null || id != bookDTO.Id) { _logger.LogWarn($"{location}: Update failed with bad data - id: {id}"); return(BadRequest()); } var isExists = await _bookRepository.IsExists(id); if (!isExists) { _logger.LogWarn($"{location}: Failed to retrieve record with id: {id}"); return(NotFound()); } if (!ModelState.IsValid) { _logger.LogWarn($"{location}: Data model invalid"); return(BadRequest(ModelState)); } var book = _mapper.Map <Book>(bookDTO); var isSuccess = await _bookRepository.Update(book); if (!isSuccess) { _logger.LogWarn($"{location}: Update failed record id: {id}"); return(InternalError($"{location}: Update failed")); } _logger.LogInfo($"{location}: Update success record id: {id}"); return(NoContent()); } catch (Exception e) { _logger.LogWarn($"{location}: Update failed"); return(InternalError($"{location}: {e.Message} - {e.InnerException}")); } }
public async Task <IActionResult> Update(int id, [FromBody] BookUpdateDTO bookDTO) { var location = GetControllerActionNames(); try { _loggerService.LogInfo($"{location}: updated attempted - id: {id}"); if (id < 1 || bookDTO == null || id != bookDTO.Id) { _loggerService.LogWarn($"{location}: Empty request was submitted"); return(BadRequest()); } var isExist = await _bookRepository.isExists(id); if (!isExist) { _loggerService.LogWarn($"{location}: not found - id: {id}"); return(NotFound()); } if (!ModelState.IsValid) { _loggerService.LogWarn($"{location}: data was incomplete"); return(BadRequest(ModelState)); } var book = _mapper.Map <Book>(bookDTO); var isSuccess = await _bookRepository.Update(book); if (!isSuccess) { return(InternalError($"{location}: Update failed")); } _loggerService.LogInfo($"{location}: updated"); return(NoContent()); } catch (Exception e) { return(InternalError($"{location}: {e.Message} - {e.InnerException}")); } }
public async Task <IActionResult> Update(int id, [FromBody] BookUpdateDTO bookDTO) { var location = GetControllerActionNames(); try { _logger.LogInfo($"{location}: Attempted Call for id:{id}"); if (id < 1 || bookDTO == null || id != bookDTO.Id) { _logger.LogWarn($"{location}: Bad data for Id:{id}"); return(BadRequest()); } var exists = await _bookRepository.Exists(id); if (!exists) { _logger.LogWarn($"{location}: id:{id} was not found"); return(NotFound()); } if (!ModelState.IsValid) { _logger.LogWarn($"{location}: Data was incomplete"); return(BadRequest(ModelState)); } var book = _mapper.Map <Book>(bookDTO); var isSuccess = await _bookRepository.Update(book); if (!isSuccess) { return(InternalError($"{location}: id:{id} Failure")); } _logger.LogInfo($"{location}: id:{id} Successful"); return(NoContent()); // success } catch (Exception e) { return(InternalError($"{location}: {e.Message} {e.InnerException}")); } }
public async Task <IActionResult> Update(int id, [FromBody] BookUpdateDTO bookDTO) { var location = GetCotrollerActionNames(); try { _logger.LogInfo($"{location}: Attempted to update Id: {id}"); if (id < 1 || bookDTO == null || id != bookDTO.Id) { _logger.LogWarn($"{location}: Update failed with bad data"); return(BadRequest()); } var isExist = await _bookRepository.IsExist(id); if (!isExist) { _logger.LogWarn($"{location}: Record with Id: {id} was not found"); return(NotFound()); } if (!ModelState.IsValid) { _logger.LogWarn($"{location}: Request data for update was incompleted"); return(BadRequest(ModelState)); } var book = _mapper.Map <Book>(bookDTO); var isSuccess = await _bookRepository.Update(book); if (!isSuccess) { return(InternalServerError($"{location}: Update failed")); } _logger.LogInfo($"{location} updated successfully."); return(NoContent()); } catch (Exception e) { return(InternalServerError($"{location}: {e.Message} - {e.InnerException}")); } }
public async Task <IActionResult> Update(int id, [FromBody] BookUpdateDTO bookDTO) { var location = GetControllerActionNames(); _logger.LogInfo($"{location}: Update Attempted with Id: {id}"); try { if (id < 1 || bookDTO == null || id != bookDTO.Id) // id in parameter (URL) must equal the id in the JSON body/payload received from user { _logger.LogWarn($"{location}: Bad Id or Empty Request was submitted"); return(BadRequest()); } //if (await _bookRepository.FindById(id) == null) { var doesExist = await _bookRepository.DoesExist(id); if (!doesExist) { _logger.LogWarn($"{location}: Update record not found with Id: {id}"); return(NotFound()); } if (!ModelState.IsValid) { _logger.LogWarn($"{location}: Update data was incomplete"); return(BadRequest(ModelState)); } // Map all the data from the bookDTO and map into the Book data set var book = _mapper.Map <Book>(bookDTO); var isSuccess = await _bookRepository.Update(book); // Did something outside user's control fail? if (!isSuccess) { return(InternalError($"{location}: Update Operation Failed")); } _logger.LogInfo($"{location}: Update Success with Id: {id}"); return(NoContent()); // "Ok" (204) result returned but with nothing additional to report back to user } // try catch (Exception ex) { return(InternalError($"{location}: {ex.Message} - {ex.InnerException}")); } // catch } // Update (book)
public async Task <IActionResult> Update(int id, [FromBody] BookUpdateDTO bookDTO) { var location = GetControllerActionNames(); try { _logger.LogInfo($"{location}: Update attempted on record with id: {id}"); if (id < 1 || bookDTO == null || id != bookDTO.Id) { _logger.LogWarn($"{location}: Update failed with with bad data - id: {id}"); return(BadRequest(ModelState)); } var isExists = await _bookRepository.isExists(id); if (!isExists) { _logger.LogWarn($"{location}: Failed to retrieve record with id: {id}"); return(NotFound()); } if (!ModelState.IsValid) { _logger.LogWarn($"{location}: Data was incomplete."); return(BadRequest(ModelState)); } var book = _mapper.Map <Book>(bookDTO); var isSuccess = await _bookRepository.Update(book); if (!isSuccess) { return(InternalError("Update Operation failed.")); } _logger.LogInfo($"{location}: Update successful for record of id: {id}."); //Means it's an OK but I don't have anything to show you. return(NoContent()); } catch (Exception ex) { return(InternalError($"{ex.Message} - {ex.InnerException}")); } }
public async Task <IActionResult> Update(int id, [FromBody] BookUpdateDTO bookDTO) { var location = GetControllerActionNames(); try { _logger.LogInfo($"{location}: Book update attempted for id: {id}"); if (id < 1 || bookDTO == null || id != bookDTO.Id) { _logger.LogWarn($"{location}: Bad request was submitted, null or no id match"); return(BadRequest()); } var isExists = await _bookRepository.isExists(id); if (!isExists) { _logger.LogWarn($"{location}: Book with id: {id} not found"); return(NotFound()); } if (!ModelState.IsValid) { _logger.LogWarn($"{location}: Submitted data not valid"); return(BadRequest(ModelState)); } var book = _mapper.Map <Book>(bookDTO); var isSucess = await _bookRepository.Update(book); if (!isSucess) { return(InternalError($"{location}: Update operation failed")); } _logger.LogInfo($"{location}: Book Created"); return(NoContent()); } catch (Exception e) { return(InternalError($"{ e.Message} - {e.InnerException }")); } }