public async Task <IActionResult> createBook([FromBody] BookCreateDTO bookDTO) { var location = getControllerDetails(); try { _logger.LogInfo($"{location} Call Started "); if (bookDTO == null) { _logger.LogWarn($"{location} Empty request was submitted"); return(BadRequest(ModelState)); } if (!ModelState.IsValid) { _logger.LogWarn($"{location} Incomplete request was submitted"); return(BadRequest(ModelState)); } var book = _mapper.Map <Book>(bookDTO); var isSuccess = await _bookRepository.Create(book); if (!isSuccess) { return(internalError($"{location} Error while saving data")); } _logger.LogInfo($"{location} Created succesfully"); return(Created("Create", new { book })); } catch (Exception e) { return(internalError($"{location} - {e.Message} - {e.InnerException}")); } }
public async Task <IActionResult> Create([FromBody] BookCreateDTO bookCreateDTO) { var location = GetControllerActionNames(); try { _logger.LogInfo($"End user attempted to create a new Book."); if (bookCreateDTO == null) { _logger.LogWarn($"End user sent an empty HTTP 1.1 POST request!"); return(BadRequest(ModelState)); } if (!ModelState.IsValid) { _logger.LogWarn($"End user sent an empty HTTP 1.1 POST request to create a new Book with invalid Book data!"); return(BadRequest(ModelState)); } var newBook = _mapper.Map <Book>(bookCreateDTO); var isSuccess = await _bookRepository.Create(newBook); if (!isSuccess) { return(InternalError($"Failed creating new Book!")); } _logger.LogInfo("Successfully created a new Book!"); return(Created("Create", new { newBook })); } catch (Exception exception) { return(InternalError($"{location}: {exception.Message} - {exception.InnerException}")); } }
public async Task <IActionResult> CreateBook([FromBody] BookCreateDTO bookDTO) { var location = GetController(); try { _logger.LogInfo($"{location}: Attemted to create an Book"); if (bookDTO == null) { _logger.LogWarn($"{location}: Empty request was submitted"); return(BadRequest(ModelState)); } if (!ModelState.IsValid) { _logger.LogWarn($"{location}: Required data was not provided"); return(BadRequest(ModelState)); } var book = _mapper.Map <Book>(bookDTO); var isSuccess = await _bookRepository.Create(book); if (!isSuccess) { return(InternalError($"{location}: Book creation failed")); } _logger.LogInfo($"{location}: Successfully create an Book"); return(Created("book created", new { book })); } catch (Exception e) { return(InternalError($"{location}: {e.Message} - {e.InnerException}")); } }
public async Task <IActionResult> Create([FromBody] BookCreateDTO bookDTO) { var errLocation = GetControllerAndActionNames(); try { if (bookDTO == null) { return(BadRequest(ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var book = mapper.Map <Book>(bookDTO); var isSuccess = await bookRepository.Create(book); if (!isSuccess) { return(ErrorHandler($"{errLocation} creation failed")); } return(Created("create", new { book })); } catch (Exception ex) { return(ErrorHandler($"{errLocation} {ex.Message} - {ex.InnerException}")); } }
public async Task <IActionResult> CreateBook([FromBody] BookCreateDTO bookDTO) { var location = GetControllerActionNames(); try { _logger.LogInfo($"{location} attempted with {bookDTO.Title}"); if (bookDTO == null) { _logger.LogWarn($"{location} - Empty Request was submitted"); return(BadRequest(ModelState)); } if (!ModelState.IsValid) { _logger.LogWarn($"{location} : Data was Incomplete {bookDTO.Title}"); return(BadRequest(ModelState)); } var book = _mapper.Map <Book>(bookDTO); var success = await _bookRepository.Create(book); if (!success) { return(InternalError("{location} : Creation failed")); } _logger.LogInfo($"{location} : succeeded with {bookDTO.Title}"); return(Created("Create", new { book })); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(InternalError($"{location} - failed to create book {bookDTO.Title} - {ex.Message} - {ex.InnerException}")); } }
public async Task <IActionResult> Create([FromBody] BookCreateDTO bookCreateDTO) { var location = GetControllerActionNames(); try { if (bookCreateDTO == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest()); } var book = _mapper.Map <Book>(bookCreateDTO); var isSuccess = await _bookRepository.Create(book); if (!isSuccess) { return(StatusCode(500)); } return(Created("Create", new { book })); } catch (Exception ex) { return(StatusCode(500)); } }
public async Task <IActionResult> Create([FromBody] BookCreateDTO bookDTO) { try { if (bookDTO == null) { return(BadRequest(ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var isExists = await _authorRepository.IsExists(bookDTO.AuthorId); if (!isExists) { return(BadRequest(ModelState)); } var book = _mapper.Map <Book>(bookDTO); var isSuccess = await _bookRepository.Create(book); if (!isSuccess) { return(InternalError()); } return(Created("Create", new { book })); } catch (Exception) { return(InternalError()); } }
public IActionResult Post(int publisherId, [FromBody] BookCreateDTO book) { if (book == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var publisherExists = _bookStoreRepository.PublisherExist(publisherId); if (!publisherExists) { return(NotFound()); } var bookToAdd = new BookDTO { Title = book.Title, PublisherId = publisherId }; _bookStoreRepository.AddBook(bookToAdd); _bookStoreRepository.Save(); return(CreatedAtRoute("GetBook", new { publisherId, id = bookToAdd.Id }, bookToAdd)); }
public async Task <IActionResult> Create([FromBody] BookCreateDTO bookDTO) { var location = GetControllerActionNames(); try { _logger.LogInfo($"{location}: Create attempted"); if (bookDTO == null) { _logger.LogWarn($"{location}: Empty request submitted"); return(BadRequest(ModelState)); } if (!ModelState.IsValid) { _logger.LogWarn($"{location}: Model state not valid"); return(BadRequest(ModelState)); } var book = _mapper.Map <Book>(bookDTO); var IsSuccess = await _bookRepository.Create(book); if (!IsSuccess) { return(InternalError($"{location}: Creation failed")); } _logger.LogInfo($"{location} Book created"); return(Created("Create", new { book })); } catch (Exception ex) { return(InternalError($"{location}: Something went wrong: {ex.Message}")); } }
public async Task <IActionResult> Create([FromBody] BookCreateDTO bookDTO) { var location = GetControllerAndActionNames(); try { if (bookDTO == null) { return(BadRequest(ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var book = _mapper.Map <Book>(bookDTO); var isSuccess = await _repository.Create(book); if (!isSuccess) { return(InternalError($"{location} - Book Creation is failed")); } return(Created("Create", book)); } catch (Exception ex) { return(InternalError($"{location} : {ex.Message}-{ex.InnerException}")); } }
public async Task <IActionResult> Create([FromBody] BookCreateDTO bookCreateDTO) { var location = GetControllerActionNames(); try { _logger.LogInfo($"{location}: Tentativo di scrittura di un nuovo libro"); if (bookCreateDTO == null) { _logger.LogWarn($"{location}: La Request è vuota"); return(BadRequest(ModelState)); } if (!ModelState.IsValid) { _logger.LogWarn($"{location}: I dati del libro sono incompleti"); return(BadRequest(ModelState)); } var book = _mapper.Map <Book>(bookCreateDTO); var isSuccess = await _bookRepository.Create(book); if (!isSuccess) { return(InternalError($"{location}: Creazione libro fallita.")); } _logger.LogInfo($"{location}: Libro creato con successo."); return(Created("Create", new { book })); } catch (Exception ex) { return(InternalError($"{location}: {ex.Message} - {ex.InnerException}")); } }
public async Task <IActionResult> Create([FromBody] BookCreateDTO bookDTO) { try { _logger.LogInfo("Attempted to submit book "); if (bookDTO == null) { _logger.LogWarn("book Create is NULL!"); return(BadRequest(ModelState)); } if (!ModelState.IsValid) { _logger.LogWarn("book Create model state is incomplete!"); return(BadRequest(ModelState)); } var book = _mapper.Map <Book>(bookDTO); var isSuccess = await _bookRepository.Create(book); if (!isSuccess) { _logger.LogWarn("book Create failed!"); return(InternalError("book Create failed!")); } _logger.LogInfo("Successfully created book " + bookDTO.Title); return(Created("Create", new { book })); } catch (Exception ex) { return(InternalError("Controller: " + GetControllerActionNames() + " Error: " + ex.ToString())); } }
public async Task <IActionResult> CreateBook([FromBody] BookCreateDTO bookDTO) { var location = GetControllerActionNames(); try { _logger.LogInfo($"{location}:Create Attempted"); if (bookDTO == null) { BadRequest(ModelState); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var book = _map.Map <Book>(bookDTO); var isSuccess = await _bookRepository.Create(book); return(Created("Created", new { book })); } catch (Exception e) { return(internalError($"{location}:{e.Message}-{e.InnerException}")); } }
public async Task <IActionResult> Create([FromBody] BookCreateDTO bookCreate) { var location = GetControllerActionNames(); try { _logger.LogInfo($"{ location }: Create Attempted"); if (bookCreate == null) { _logger.LogWarn($"{location}: Empty request was submitted!"); return(BadRequest(ModelState)); } if (!ModelState.IsValid) { _logger.LogWarn($"{location}: Data was incomplte"); return(BadRequest(ModelState)); } var book = _mapper.Map <Book>(bookCreate); var isScuccess = await _book.Create(book); if (!isScuccess) { return(InternalError(($"{location} - Creation failed!"))); } _logger.LogInfo($"{location}: Creation was Successful!"); return(Created("Create", new { book })); } catch (Exception ex) { return(InternalError(($"{location} - {ex.Message} - {ex.InnerException}"))); } }
public async Task <IActionResult> Create([FromBody] BookCreateDTO bookDTO) { var location = GetControllerActionNames(); _logger.LogInfo($"{location}: Create attempted"); try { if (bookDTO == null) { _logger.LogWarn($"{location}: Empty Request was submitted"); // ModelState is DTOs required fields return(BadRequest(ModelState)); } if (!ModelState.IsValid) { _logger.LogWarn($"{location}: 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.Create(book); // Did something outside user's control fail? if (!isSuccess) { return(InternalError($"{location}: Create failed")); } _logger.LogInfo($"{location}: Create success"); return(Created("Create", new { book })); } // try catch (Exception ex) { return(InternalError($"{location}: {ex.Message} - {ex.InnerException}")); } // catch } // Create (book)
public async Task <IActionResult> Create([FromBody] BookCreateDTO bookDTO) { var location = GetControllerActionNames(); try { _loggerSerivce.LogInfor($"{location} Create Attempted."); if (bookDTO == null) { _loggerSerivce.LogInfor($"{location} Empty request was submitted."); return(BadRequest(ModelState)); } if (!ModelState.IsValid) { _loggerSerivce.LogInfor($"{location} Book's data was not completed."); return(BadRequest(ModelState)); } var book = _mapper.Map <Book>(bookDTO); var isSuccess = await _bookRepository.Create(book); if (!isSuccess) { return(InternalError($"{location} failed to created.")); } _loggerSerivce.LogInfor($"{location} Book is created!"); _loggerSerivce.LogInfor($"{location} {book}"); return(Created("Create", new { book })); } catch (Exception e) { return(InternalError($"{location}{e.Message} - {e.InnerException}")); } }
public async Task <IActionResult> Create([FromBody] BookCreateDTO Book) { var location = GetControllerActionNames(); try { _logger.LogInfo($"{location}: Book Submission Attempted"); if (Book == null) { _logger.LogWarn($"{location}: Empty request was submitted"); return(BadRequest(ModelState)); } if (!ModelState.IsValid) { _logger.LogWarn($"{location}: Book Data was incomplete"); return(BadRequest(ModelState)); } var mappedBook = _mapper.Map <Book>(Book); var isSucces = await _IBookRepository.Create(mappedBook); if (!isSucces) { return(InternalError($"{location}: Book Creation failed")); } _logger.LogInfo($"{location}: Book Created"); return(Created("Create", new { mappedBook })); } catch (Exception e) { return(InternalError($"{location}: {e.Message} - {e.InnerException}")); } }
public async Task <IActionResult> Create([FromBody] BookCreateDTO bookDTO) { try { if (bookDTO == null) { _logger.LogWarn("Empty Book was submitted."); return(BadRequest(ModelState)); } if (!ModelState.IsValid) { _logger.LogWarn("Book data was incomplete."); return(BadRequest(ModelState)); } var book = _mapper.Map <Book>(bookDTO); var isSuccess = await _bookRepository.Create(book); if (!isSuccess) { return(InternalError("Book creation failed.")); } return(Created("Create", new { book })); } catch (Exception ex) { return(InternalError(ex)); } }
public async Task <IActionResult> Create([FromBody] BookCreateDTO bookDTO) { try { _logger.LogInfo($"BooksController Intentando crear libro"); if (bookDTO == null) { _logger.LogWarn($"BooksController La petición de crear un libro se hizo sin datos"); return(BadRequest(ModelState)); } if (!ModelState.IsValid) { _logger.LogWarn($"BooksController La petición de crear un libro se hizo con datos incompletos"); return(BadRequest(ModelState)); } var book = _mapper.Map <Book>(bookDTO); var isSuccess = await _bookRepository.Create(book); if (!isSuccess) { _logger.LogError($"BooksController La creacion de libro nuevo falló"); return(StatusCode(500, "BooksController La creacion de libro nuevo falló")); } _logger.LogInfo($"BooksController Se creó nuevo autor correctamente"); return(Created("Create", new { book })); } catch (Exception e) { return(InternalError(e)); } }
public async Task <IActionResult> Create([FromBody] BookCreateDTO bookDTO) { var location = GetControllerActionNames(); try { _logger.LogInfo($"{location}: Create attempted"); if (bookDTO == null) { _logger.LogWarn($"{location} Empty request submitted"); return(BadRequest(ModelState)); } var book = _mapper.Map <Book>(bookDTO); var isSuccess = await _bookRepository.Create(book); if (!isSuccess) { return(InternalError($"{location} creation failed")); } _logger.LogInfo($"{location}: Creation was successful"); return(Created("Create", new { book })); } catch (Exception e) { return(InternalError($"{location}: {e.Message} - {e.InnerException}")); } }
public async Task <IActionResult> Create([FromBody] BookCreateDTO BookDTO) { var location = GetCollectActionNames(); try { _logger.LogInfo($"{location}:Attempted submission attempted"); if (BookDTO == null) { _logger.LogWarn($"{location}:Empty request submitted"); return(BadRequest(ModelState)); } if (!ModelState.IsValid) { _logger.LogWarn($"{location}:Book data was incomplete"); return(BadRequest(ModelState)); } var book = _Mapper.Map <Book>(BookDTO); var isSuccess = await _BookRepository.Create(book); if (!isSuccess) { return(InternalError($"{location}:Book creation failed")); } _logger.LogInfo($"{location}:Book created"); return(Created("Create", new { book })); } catch (Exception ex) { return(InternalError($"{location}-{ex.Message}-{ex.InnerException}")); } }
public async Task <IActionResult> Create([FromBody] BookCreateDTO bookDto) { var location = GetControllerActionNames(); try { _logger.LogInfo($"{location}: Create Attempted"); if (bookDto == null) { _logger.LogWarn($"{location}: Empty Request was submitted"); return(BadRequest(ModelState)); } if (!ModelState.IsValid) { _logger.LogWarn($"{location}: Data was Incomplete"); return(BadRequest(ModelState)); } var book = _mapper.Map <Book>(bookDto); var isSuccess = await _bookRepository.Create(book); if (!isSuccess) { return(InternalError($"{location}: Create book failed")); } _logger.LogInfo($"{location}: book created successfully"); return(Created("Create", new { book })); } catch (Exception e) { return(InternalError($"{e.Message} - {e.InnerException}")); } }
public async Task <IActionResult> Create([FromBody] BookCreateDTO bookDTO) { var location = GetControllerActionNames(); try { _logger.LogInfo($"{location}: Atempted"); if (bookDTO == null) { _logger.LogWarn($"{location}: Empty request"); return(NotFound()); } if (!ModelState.IsValid) { _logger.LogWarn($"{location}: Invalid data"); return(BadRequest(ModelState)); } var book = _mapper.Map <Book>(bookDTO); var isSuccess = await _bookRepository.Create(book); if (!isSuccess) { return(InternalError($"{location}: Failed")); } _logger.LogInfo($"{location}: Success"); return(Created("Create", new { book })); } catch (Exception e) { return(InternalError($"{location} - {e.Message} - {e.InnerException}")); } }
public async Task <IActionResult> Create([FromBody] BookCreateDTO bookDTO) { var getLocation = GetControllerActionNames(); try { _logger.logInfo($"{getLocation} book submission attempted"); if (bookDTO == null) { _logger.logWarning($"Empty Request Submitted"); return(BadRequest(ModelState)); } if (!ModelState.IsValid) { _logger.logWarning($"book Data was Incomplete"); return(BadRequest(ModelState)); } var book = _mapper.Map <Book>(bookDTO); var isSuccessful = await _bookRepository.Create(book); if (!isSuccessful) { return(Internalserver($"book creation Failed")); } _logger.logInfo($" {getLocation} book Created Successfully"); return(Created("Created", new { book })); } catch (Exception e) { return(Internalserver($"{e.Message} - {e.InnerException}")); } }
public async Task <IActionResult> Create([FromBody] BookCreateDTO bookDTO) { var location = GetControllerNames(); try { _logger.LogInfo($"{location}: Book creation is submitted"); if (bookDTO == null) { _logger.LogWarning($"{location}:Request was empty"); return(BadRequest(ModelState)); } if (!ModelState.IsValid) { _logger.LogWarning($"{location} : Request was incomplete"); return(BadRequest(ModelState)); } var book = _mapper.Map <Book>(bookDTO); var isSuccess = await _bookRepository.Create(book); if (!isSuccess) { return(InternalError($"{location} :Book creation failed")); } _logger.LogInfo($"{location} :Book created"); return(Created("Create", new { book })); } catch (Exception a) { return(InternalError($"{location} : {a.Message} - {a.InnerException}")); } }
public async Task <IActionResult> Create([FromBody] BookCreateDTO bookDTO) { try { if (bookDTO == null) { return(BadRequest(ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var book = _mapper.Map <Book>(bookDTO); var isSuccess = await _bookRepository.Create(book); if (!isSuccess) { return(InternalError("Book creation failed")); } return(Created("Created", new { book })); } catch (Exception e) { return(InternalError($"{e.Message }")); } }
public IActionResult Post(int publisherId, [FromBody] BookCreateDTO book) { if (book == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var publisherExists = _rep.PublisherExists(publisherId); if (!publisherExists) { return(NotFound()); } var bookToAdd = new BookDTO { PublisherId = publisherId, Title = book.Title }; _rep.AddBook(bookToAdd); _rep.Save(); return(CreatedAtRoute("GetBook", new { publisherId = publisherId, id = bookToAdd.Id }, bookToAdd)); }// end of POST method
public async Task <ActionResult> Create([FromBody] BookCreateDTO bookDTO) { var location = GetControllerActionName(); try { loggerService.LogInfo($"{location}: Book Created Attempted"); if (bookDTO == null) { loggerService.LogWarning($"{location}: empty request was submitted"); return(BadRequest(ModelState)); } if (!ModelState.IsValid) { loggerService.LogWarning($"{location}: Book data was Incomplete"); return(BadRequest(ModelState)); } var book = mapper.Map <Book>(bookDTO); var isSuccess = await bookRepository.Create(book); if (!isSuccess) { return(InternalError($"{location}: Book creation Failed")); } loggerService.LogInfo($"{location}: Book created successfully"); return(Created("Created", new { book })); } catch (Exception ex) { return(InternalError($"{location}: {ex.Message} - {ex.InnerException}")); } }
public async Task <IActionResult> Create([FromBody] BookCreateDTO bookDTO) { var location = GetControllerAction(); try { Log.Information($"{location}: Create Attempted"); if (bookDTO == null) { Log.Warning($"{location}: Empty Request was submitted"); return(BadRequest(ModelState)); } if (!ModelState.IsValid) { Log.Warning($"{location}: Data was Incomplete"); return(BadRequest(ModelState)); } var book = _mapper.Map <Book>(bookDTO); var isSuccess = await _bookRepository.Create(book); if (!isSuccess) { return(InternalError($"{location}: creation failed")); } Log.Information($"{location}: Creation was successful"); return(Created("Create", new { book })); } catch (Exception ex) { return(InternalError($"{location}: {ex.Message} - {ex.InnerException}")); } }
public async Task <BookDTO> PutAsync(BookCreateDTO book) { this.Logger.LogTrace($"{nameof(this.PutAsync)} called"); var result = await this.BookCreateService.CreateAsync(this.Mapper.Map <BookUpdateModel>(book)); return(this.Mapper.Map <BookDTO>(result)); }