public ViewResult AutoProperty() { Product myProduct = new Product(); myProduct.Name = "Kayak"; string productName = myProduct.Name; return View("Result", (object)String.Format("Product name: {0}", productName)); }
public ViewResult CreateProduct() { Product myProduct = new Product(); myProduct.ProductID = 100; myProduct.Name = "Kayak"; myProduct.Description = "A boat for one person"; myProduct.Price = 275M; myProduct.Category = "Watersports"; return View("Result", (object)String.Format("Category: {0}", myProduct.Category)); }
//public ViewResult FindProductsWithoutLinQ() public ViewResult FindProducts() { Product[] products = { new Product {Name = "Kayak", Category = "Watersports", Price = 275M}, new Product {Name = "Lifejacket", Category = "Watersports", Price = 48.95M}, new Product {Name = "Soccer ball", Category = "Soccer", Price = 19.50M}, new Product {Name = "Corner flag", Category = "Soccer", Price = 34.95M} }; //var foundProducts = from match in products // orderby match.Price descending // select new { match.Name, match.Price }; var foundProducts = products.OrderByDescending(e => e.Price) .Take(3) .Select(e => new { e.Name, e.Price }); var results = products.Sum(e => e.Price); //int count = 0; products[2] = new Product { Name = "Stadium", Price = 79600M }; StringBuilder result = new StringBuilder(); foreach(var p in foundProducts) { result.AppendFormat("Price: {0} ", p.Price); //if(++count == 3) //{ // break; //} } return View("Result", (object)String.Format("Sum: {0:c}", results)); //return View("Result", (object)result.ToString()); //Product[] foundProducts = new Product[3]; //Array.Sort(products, (item1, item2) => //{ // return Comparer<decimal>.Default.Compare(item1.Price, item2.Price); //}); //Array.Copy(products, foundProducts, 3); //StringBuilder result = new StringBuilder(); //foreach(Product p in foundProducts) //{ // result.AppendFormat("Price: {0} ", p.Price); //} //return View("Result", (object)result.ToString()); }