GetPriceByUpc() public méthode

public GetPriceByUpc ( string upc ) : decimal?
upc string
Résultat decimal?
Exemple #1
0
        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));
        }
 public decimal?GetPrice(PriceLookup price)
 {
     if (!string.IsNullOrEmpty(price.Upc))
     {
         var priceValue = _priceDb.GetPriceByUpc(price.Upc);
         if (priceValue == null)
         {
             _modelState.AddModelError("NotFound", "UPC not found");
         }
         return(priceValue);
     }
     else if (!string.IsNullOrEmpty(price.Isbn))
     {
         var priceValue = _priceDb.GetPriceByIsbn(price.Isbn);
         if (price.Price == null)
         {
             _modelState.AddModelError("NotFound", "ISBN not found");
         }
         return(priceValue);
     }
     else
     {
         _modelState.AddModelError("Required", "You must enter a UPC or an ISBN");
     }
     return(null);
 }
        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))
                {
                    var sql = "SELECT Price FROM Prices WHERE Isbn = @isbn";
                    using (var conn = new SQLiteConnection(connectionString))
                    {
                        conn.Open();
                        var sqlCommand = new SQLiteCommand(sql, conn);
                        sqlCommand.Parameters.AddWithValue("isbn", price.Isbn);
                        var result = sqlCommand.ExecuteScalar();
                        if (result == null)
                            ModelState.AddModelError("NotFound", "ISBN not found");
                        else
                            price.Price = (decimal)result;
                        conn.Close();
                    }
                }
                else
                    ModelState.AddModelError("Required", "You must enter a UPC or an ISBN");
            }

            return View(price);
        }
        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))
                {
                    var sql = "SELECT Price FROM Prices WHERE Isbn = @isbn";
                    using (var conn = new SQLiteConnection(connectionString))
                    {
                        conn.Open();
                        var sqlCommand = new SQLiteCommand(sql, conn);
                        sqlCommand.Parameters.AddWithValue("isbn", price.Isbn);
                        var result = sqlCommand.ExecuteScalar();
                        if (result == null)
                        {
                            ModelState.AddModelError("NotFound", "ISBN not found");
                        }
                        else
                        {
                            price.Price = (decimal)result;
                        }
                        conn.Close();
                    }
                }
                else
                {
                    ModelState.AddModelError("Required", "You must enter a UPC or an ISBN");
                }
            }

            return(View(price));
        }
Exemple #5
0
 public decimal?GetPrice(PriceLookup priceLookup)
 {
     if (!string.IsNullOrEmpty(priceLookup.Upc))
     {
         if (_priceDb.DoesUpcExist(priceLookup.Upc))
         {
             return(_priceDb.GetPriceByUpc(priceLookup.Upc));
         }
         _modelState.AddModelError("NotFound", "UPC not found");
     }
     else if (!string.IsNullOrEmpty(priceLookup.Isbn))
     {
         if (_priceDb.DoesIsbnExist(priceLookup.Isbn))
         {
             return(_priceDb.GetPriceByIsbn(priceLookup.Isbn));
         }
         _modelState.AddModelError("NotFound", "ISBN not found");
     }
     else
     {
         _modelState.AddModelError("Required", "You must enter a UPC or an ISBN");
     }
     return(null);
 }
        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);
        }