diff --git a/Controllers/ProductController.cs b/Controllers/ProductController.cs index 1d5546f..5cf7885 100644 --- a/Controllers/ProductController.cs +++ b/Controllers/ProductController.cs @@ -45,6 +45,17 @@ namespace FirmTracker_Server.Controllers return Ok(product); } + [HttpGet("name/{name}")] + [ProducesResponseType(200)] + [ProducesResponseType(404)] + public IActionResult GetProductByName(string name) + { + var product = _productCrud.GetProductByName(name); + if (product ==null) + return NotFound(); + return Ok(product); + } + // PUT: api/Products/5 [HttpPut("{id}")] [ProducesResponseType(200)] // Created diff --git a/nHIbernate/Products/ProductCRUD.cs b/nHIbernate/Products/ProductCRUD.cs index e14b12b..d07df8f 100644 --- a/nHIbernate/Products/ProductCRUD.cs +++ b/nHIbernate/Products/ProductCRUD.cs @@ -74,6 +74,16 @@ namespace FirmTracker_Server.nHibernate.Products } } + public Product GetProductByName(string productName) + { + using (var session = SessionFactory.OpenSession()) + { + var query = session.CreateQuery("from Product where Name = :name"); + query.SetParameter("name", productName); + return query.UniqueResult(); + } + } + public void UpdateProduct(Product product) { using (var session = SessionFactory.OpenSession())