public IHttpActionResult GetAuthor(int id) { try { return(Ok(authorRepository.getById(id))); } catch (Exception e) { return(NotFound()); } }
public IHttpActionResult GetProduct(int id) { try { return(Ok(repository.getById(id))); } catch (Exception e) { return(NotFound()); } }
public IHttpActionResult AddProduct(int id, [FromBody] AddProductToAuthorRequest request) { try { Author author = authorRepository.getById(id); if (productRepository.exists(request.ProductId)) { author.Products.Add(productRepository.getById(request.ProductId)); db.SaveChanges(); return(Ok(author)); } else { return(BadRequest("Product does not exist")); } } catch (Exception e) { return(NotFound()); } }