예제 #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));
        }
예제 #2
0
        public PriceController()
        {
            var sqlLiteDbPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data", "prices.s3db");
            var priceDb       = new PriceDb("Data Source=" + sqlLiteDbPath);

            _priceService = new PriceService(new ModelStateAdapter(ModelState), priceDb);
        }
        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);
            var priceSvc = new PriceService(ModelState, priceDb);
            if (ModelState.IsValid)
                price.Price = priceSvc.GetPrice(price);

            return View(price);
        }
        public ViewResult Index(PriceLookup price)
        {
            var connectionString = @"Data Source=" + Server.MapPath("App_Data/prices.s3db");
            var priceDb          = new PriceDb(connectionString);
            var priceSvc         = new PriceService(ModelState, priceDb);

            if (ModelState.IsValid)
            {
                price.Price = priceSvc.GetPrice(price);
            }

            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));
        }
        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);
        }
예제 #8
0
 public PriceService(IValidationAdapter modelState, PriceDb priceDb)
 {
     _modelState = modelState;
     _priceDb    = priceDb;
 }
 public PriceService(ModelStateDictionary modelState, PriceDb priceDb)
 {
     this._modelState = modelState;
     this._priceDb    = priceDb;
 }
 public PriceService(ModelStateDictionary modelState, PriceDb priceDb)
 {
     this._modelState = modelState;
     this._priceDb = priceDb;
 }