public GetPriceByUpc ( string upc ) : decimal? | ||
upc | string | |
return | decimal? |
public decimal? GetPriceByUpc(string upc)
{
var sql = "SELECT Price FROM Prices WHERE Upc = @upc";
using (var conn = new SQLiteConnection(_connectionString))
{
conn.Open();
var sqlCommand = new SQLiteCommand(sql, conn);
sqlCommand.Parameters.AddWithValue("upc", upc);
var price = (decimal?)sqlCommand.ExecuteScalar();
conn.Close();
return price;
}
}
PriceDb::GetPriceByUpc ( |
public ViewResult Index(PriceLookup price) { var connectionString = @"Data Source=" + Server.MapPath("App_Data/prices.s3db"); var priceDb = new PriceDb(connectionString); if (ModelState.IsValid) { if (!string.IsNullOrEmpty(price.Upc)) { priceDb.GetPriceByUpc(price); if (price.Price == null) { ModelState.AddModelError("NotFound", "UPC not found"); } } else if (!string.IsNullOrEmpty(price.Isbn)) { priceDb.GetPriceByIsbn(price); if (price.Price == null) { ModelState.AddModelError("NotFound", "ISBN not found"); } } else { ModelState.AddModelError("Required", "You must enter a UPC or an ISBN"); } } return(View(price)); }