new [] { "application/vnd.tmaturano.author.full+json" })] //should only accept requests with this media type public IActionResult CreateAuthor([FromBody] AuthorInputDto authorDto) { if (authorDto == null) { return(BadRequest()); } var result = _authorService.Add(authorDto); if (!result.sucess) { //Throwing an exception is expensive, but at this case, we have at the global level on Startup handling all the //500 Error, so to keep it in one place, I'm throwing . throw new Exception("Creating an author failed on save."); //return StatusCode(500, ""); } var authorToReturn = _mapper.Map <AuthorOutputDto>(authorDto); authorToReturn.Id = result.id; //CreatedAtRoute will contain the URI where the newly author can be found 1st parameter //also, the id of the generated author in 2nd parameter //The URI is sent through response's header Location return(CreatedAtRoute("GetAuthor", new { id = authorToReturn.Id }, authorToReturn)); }
public IActionResult AddAuthor(AuthorInputModel input) { if (!input.IsValid()) { return(BadRequest(input.ValidationMessage)); } var author = _authorAppService.Add(input); return(Created(new Uri($"{Request.Path}/{author.Id}", UriKind.Relative), author)); }
public ResponseBase Add(Author author) { ResponseBase response = new ResponseBase(); try { response.Success = _appService.Add(author); } catch (LibraryException ex) { response.Message = ex.Message; } catch (Exception ex) { throw ex; } return(response); }
public ActionResult Add(Author_DTO obj) { _AuthorAppService.Add(obj); return(RedirectToAction("GetAll")); }