public ActionResult Index() { var products = _database.GetAll(); return(View(products.Select(p => p.ToModel()))); //return Json(products.Select(p => p.ToModel()), JsonRequestBehavior.AllowGet); }
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)); }
/// <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); }
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); }
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); } }
public IActionResult Index() { var products = _database.GetAll(); return(View(products.Select(p => p.ToModel()))); }
public IActionResult Get() { return(Ok(_productDatabase.GetAll())); }