示例#1
0
        public ActionResult Index()
        {
            var products = _database.GetAll();

            return(View(products.Select(p => p.ToModel())));
            //return Json(products.Select(p => p.ToModel()), JsonRequestBehavior.AllowGet);
        }
示例#2
0
        public ActionResult Index()
        {
            //return View();
            // JsonRequestBehavior//
            // return Json(new { Name = "Index" });
            //var connString = ConfigurationManager.ConnectionStrings["NileDatabase"];

            var products = _database.GetAll();

            //return Content("Index");
            return(Json(products.Select(p => p.ToModel()), JsonRequestBehavior.AllowGet));
        }
示例#3
0
        /// <summary>Get a product by name.</summary>
        /// <param name="source">The source</param>
        /// <param name="name">The product name</param>
        /// <returns>The product, if found</returns>
        public static Product GetByName(this IProductDatabase source, string name)
        {
            foreach (var item in source.GetAll())
            {
                if (String.Compare(item.Name, name, true) == 0)
                {
                    return(item);
                }
            }
            ;

            return(null);
        }
示例#4
0
        public static IEnumerable <Product> GetProductsByDiscountPrice(this IProductDatabase source, Func <Product, decimal> priceCalculator)
        {
            var products = from product in source.GetAll()
                           where product.IsDiscontinued
                           //select new SomeType() {
                           select new {
                Product       = product,
                AdjustedPrice = product.IsDiscontinued ? priceCalculator(product) : product.Price
            };

            //Instead of anonymous type
            //var tuple = Tuple.Create<Product, decimal>(new Product(), 10M);

            return(from product in products
                   orderby product.AdjustedPrice
                   select product.Product);
        }
示例#5
0
        private void UpdateList()
        {
            try
            {
                var products = from p in _database.GetAll ()
                               orderby p.Name
                               select p;
                _bsProducts.DataSource = products.ToArray ();

            } catch (ArgumentException ex)
            {
                MessageBox.Show (ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            } catch (ValidationException ex)
            {
                MessageBox.Show (ex.Message, "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            } catch (Exception)
            {
                MessageBox.Show ("Save failed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#6
0
        public IActionResult Index()
        {
            var products = _database.GetAll();

            return(View(products.Select(p => p.ToModel())));
        }
示例#7
0
 public IActionResult Get()
 {
     return(Ok(_productDatabase.GetAll()));
 }