我在仓库类下面的方法多个参数与方法重载传递WEB API
public class LibraryRepository : IBookRepository
{
LibraryContext context = new LibraryContext();
public decimal findBookPrice(int book_id)
{
var bookprice = (
from r in context.Books
where r.Book_Id == book_id
select r.Price
).FirstOrDefault();
return bookprice;
}
public decimal findBookPrice(int book_id, string bookname)
{
var bookprice = (
from book in context.Books
where book.Book_Id == book_id & book.Book_Title == bookname
select book.Price
).FirstOrDefault();
return bookprice;
}
}
然后我想单独获得的Web API
public class BooksWithAuthersController : ApiController
{
private LibraryRepository db = new LibraryRepository();
// GET: api/BooksWithAuthers/id/Price
[ResponseType(typeof(decimal))]
[Route("api/BooksWithAuthers/{id}/Price")]
public IHttpActionResult GetBooksPriceById(int id)
{
decimal bookprice = db.findBookPrice(id);
return Ok(bookprice);
}
// GET: api/BooksWithAuthers/id,name/Price
[ResponseType(typeof(decimal))]
[Route("api/BooksWithAuthers/{id,name}/Price")]
public IHttpActionResult GetBooksPriceById(int id,string name)
{
decimal bookprice = db.findBookPrice(id,name);
return Ok(bookprice);
}
}
这里先法这两种方法工作正常,但我如何处理具有多个参数的场景
是逗号分隔的事{ID,名称}甚至有可能?任何对此的引用? –