Esempio n. 1
0
        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 = products.OrderByDescending(e => e.Price)
            .Take(3)
            .Select(e => new { e.Name, e.Price });

            products[2] = new Product { Name = "Stadium", Price = 79600M };

            // create the result
            int count = 0;
            StringBuilder result = new StringBuilder();
            foreach (var p in foundProducts)
            {
                result.AppendFormat("Price: {0} ", p.Price);
                if (++count == 3)
                {
                    break;
                }
            }
            return View("Result", (object)result.ToString());
        }
 public ViewResult AutoProperty()
 {
     Product myProduct = new Product();
     myProduct.Name = "Kajak";
     string productName = myProduct.Name;
     return View("Result", (object)String.Format("Nazwa produktu: {0}", productName));
 }
Esempio n. 3
0
        public ViewResult FindProducts()
        {
            Product[] products = {
                new Product {Name = "Kayak", Price = 275M, Category="Watersports"},
                new Product {Name = "Lifejacket", Price = 48.95M, Category="Watersports"},
                new Product {Name = "Soccer ball", Price = 19.50M, Category="Soccer" },
                new Product {Name = "Corner flag", Price = 34.95M, Category="Soccer" }
            };

            Product[] aFoundProducts = new Product[3];
            Array.Sort(products, (item1, item2) => {
                return Comparer<decimal>.Default.Compare(item1.Price, item2.Price);
            });

            // get the first three items in the array as the results
            Array.Copy(products, aFoundProducts, 3);

            // create the result
            StringBuilder result2 = new StringBuilder();
            foreach (Product prod in aFoundProducts) {
                result2.AppendFormat("Product: {0} ", prod.Price);
            }

            var lFoundProducts = from match in products
                                 orderby match.Price descending
                                 select new {
                                     match.Name,
                                     match.Price
                                 };

            return View("Result", (object)result2.ToString());
        }
Esempio n. 4
0
        public ViewResult AutoProperty() {
            Product myProduct = new Product();

            myProduct.Name = "kim";

            string productName = myProduct.Name;

            return View("Result", (object)String.Format("Product name : {0}", productName));
        }
        public ViewResult CreateProduct()
        {
            // create and populate a new product object
            Product myProduct = new Product { 
                ProductID = 100, Name = "kayak", Description = "A boat for one person",
                Price = 275m, Category = "Watersports"
            };

            return View("Result", (object)String.Format("Category: {0}", myProduct.Category));
        }
Esempio n. 6
0
        public ViewResult AutoProperty()
        {
            // create a new Product object
            Product myProduct = new Product();
            // set the property value
            myProduct.Name = "Kayak";

            // get the property
            string productName = myProduct.Name;
            // generate the view
            return View("Result",(object)String.Format("Product name: {0}", productName));
        }
        public ViewResult CreateProduct()
        {
            Product myProduct = new Product
            {
                ProductID = 100,
                Name = "Kajak",
                Description = "Lódka jednosobowa",
                Price = 275M,
                Category = "Sporty wodne"
            };

            return View("Result", (object)String.Format("Nazwa produktu: {0}", myProduct.Category));
        }
Esempio n. 8
0
        public ViewResult AutoProperty()
        {
            Product product = new Product()
            {
                Category = "Watersports",
                Desp = "A boat for one person",
                Id = 100,
                Name = "Carey",
                Price = 275M
            };

            return View("Result", (object) string.Format("Product name:{0}", product.Name));
        }
Esempio n. 9
0
        public ViewResult CreateProduct()
        {
            Product myProduct = new Product
            {
                productID = 100,
                name = "Kajak",
                description = "Łódka jednoosobowa",
                price = 275M,
                category = "Sporty wodne",
            };

            return View("Result", (object)String.Format("Kategoria: {0}", myProduct.category));
        }
Esempio n. 10
0
        public ViewResult CreateProduct() {
            // 개체 이니셜라이저 기능 
            Product myProduct = new Product
            {
                ProductId = 1,
                Name = "Lee",
                Description = "hi~",
                Price = 200M,
                Category = "waterSports"
            };

            return View("Result", (object)String.Format("Category: {0}", myProduct.Category));
        }
Esempio n. 11
0
 public ViewResult CreateProduct()
 {
     //Создать и заполнить новый обьект Product
     var myProduct = new Product
     {
         ProductID = 100,
         Name = "Kayak",
         Description = "A boat for one person",
         Price = 275M,
         Category = "Watersports"
     };
     return View("Result",
         (object) string.Format("Category: {0}", myProduct.Category));
 }
Esempio n. 12
0
        public ViewResult AutoProperty()
        {
            //Создать новый обьект Product
            var myProduct = new Product();

            //Установить значения свойства
            myProduct.Name = "Kayak";

            //Получить значения свойства
            var productName = myProduct.Name;

            //Сгенерировать представление
            return View("Result",
                (object) string.Format("Product name: {0}", productName));
        }
Esempio n. 13
0
        public ViewResult CreateProduct()
        {
            //// create a new Product object
            //Product myProduct = new Product();

            //// set the property values
            //myProduct.ProductID = 100;
            //myProduct.Name = "Kayak";
            //myProduct.Description = "A boat for one person";
            //myProduct.Price = 275M;
            //myProduct.Category = "Watersports";
            Product myProduct = new Product { ProductID = 100, Name = "Kayak", Description = "A 1p boat", Price = 275m, Category = "WSp" };

            // generate the view
            return View("Result", (object)String.Format("Category: {0}", myProduct.Category  ));
        }
        public ViewResult CreateProduct()
        {
            // create a new Product object

            Product myProduct = new Product();

            // set the property values

            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 FindProducts()
        {
            Product[] products =
            {
                new Product {Name = "Kajak", Category = "Sporty wodne", Price = 275M},
                new Product {Name = "Kamizelka ratunkowa", Category = "Sporty wodne", Price = 48.95M},
                new Product {Name = "Piłka nożna", Category = "Piłka nożna", Price = 19.50M},
                new Product {Name = "Flaga narożna", Category = "Piłka nożna", Price = 34.95M},
            };

            var foundProducts = products.OrderByDescending(prod => prod.Price).
                Take(3).Select(prod => new { prod.Name, prod.Price});

            products[2] = new Product { Name="Stadion", Price = 7960M };

            var result = new StringBuilder();

            foreach (var prod in foundProducts)
            {
                result.AppendFormat("Cena: {0} ", prod.Price);
            }
            return View("Result", (object)result.ToString());
        }
Esempio n. 16
0
        public ViewResult SumProducts() {
            Product[] products = {
                new Product {Name = "kim1", Category = "A", Price = 200M },
                new Product {Name = "kim2", Category = "B", Price = 300M },
                new Product {Name = "kim3", Category = "C", Price = 400M },
                new Product {Name = "kim4", Category = "A", Price = 500M }
            };

            var results = products.Sum(e => e.Price); //즉시 수행되는 linq질의

            products[2] = new Product { Name = "lee", Price = 800M };

            return View("Result", (object)String.Format("Sum : {0:c}", results));
           
        }
        public ViewResult SumProducts()
        {
            Product[] products =
            {
                new Product {Name = "Kajak", Category = "Sporty wodne", Price = 275M},
                new Product {Name = "Kamizelka ratunkowa", Category = "Sporty wodne", Price = 48.95M},
                new Product {Name = "Piłka nożna", Category = "Piłka nożna", Price = 19.50M},
                new Product {Name = "Flaga narożna", Category = "Piłka nożna", Price = 34.95M},
            };

            var results = products.Sum(prod => prod.Price);

            products[2] = new Product { Name = "Stadion", Price = 7960M };

            return View("Result", (object)String.Format("Razem: {0:c}", results));
        }
Esempio n. 18
0
        //Shows how to use LINQ (Language Integrated Queries) (List of LINQ extension methods on page 94)
        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 = products.OrderByDescending( e => e.Price )
                                    .Take( 3 )
                                    .Select( e => new {
                                        e.Name,
                                        e.Price
                                    } );

            //This line shows how a deferred extension method will alter the OrderByDescending result based on the change.
            products[2] = new Product { Name = "Stadium", Price = 79600M };

            StringBuilder result = new StringBuilder();
            foreach ( var p in foundProducts ) {
                result.AppendFormat( "Price: {0} ", p.Price );
            }

            return View( "Result", (object)result.ToString() );
        }
Esempio n. 19
0
 public ViewResult SumProducts()
 {
     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 results = products.Sum(e => e.Price);
     products[2] = new Product { Name = "Stadium", Price = 79500M };
     return View("Result", (object)String.Format("Sum: {0:c}", results));
 }
Esempio n. 20
0
        public ViewResult FindProducts() {

            Product[] products = {
                new Product {Name = "kim1", Category = "A", Price = 200M },
                new Product {Name = "kim2", Category = "B", Price = 300M },
                new Product {Name = "kim3", Category = "C", Price = 400M },
                new Product {Name = "kim4", Category = "A", Price = 500M }
            };

            // ======== linq 미사용
            //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);
            //}

            // ======== linq 사용
            //var foundProducts = from match in products
            //                    orderby match.Price descending
            //                    select new { match.Name, match.Price };

            //int count = 0;
            //StringBuilder result = new StringBuilder();
            //foreach (var p in foundProducts)
            //{
            //    result.AppendFormat("Price : {0} ", p.Price);
            //    if (++count == 3)
            //    {
            //        break;
            //    }
            //}


            // ======== linq 사용 (마침표 기법)
            var foundProducts = products.OrderByDescending(e => e.Price)
                                    .Take(3)
                                    .Select(e => new { e.Name, e.Price });

            // 지연되는 Linq 확장 메서드
            products[2] = new Product { Name = "Lee", Price = 700M }; //linq 사용으로 인해 다시 질의 수행. 결과 변경.

            StringBuilder result = new StringBuilder();
            foreach (var p in foundProducts)
            {
                result.AppendFormat("Price : {0} ", p.Price);
            }

            return View("Result", (object)result.ToString());
        }