public bool delete(int id) { try { Database.Products.Remove(getById(id)); Database.SaveChanges(); return(true); } catch (Exception e) { throw e; } }
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()); } }