using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LinqSqlEpisodeVIProVid
{
    class Program
    {
        static void Main(string[] args)
        {
            NorthwindDataContext northwindContext = new NorthwindDataContext();

            #region Stored Procedure 1
            //var productHistory = northwindContext.CustOrderHist("ALFKI");
            //foreach (CustOrderHistResult item in productHistory)
            //{
            //    Console.WriteLine(item.ProductName);
            //    Console.WriteLine(item.Total);
            //} 
            #endregion

            #region Stored Procedure 2
            //List<Product> products = northwindContext.GetProductsByCategory(1).ToList<Product>();

            //foreach (Product item in products)
            //{
            //    item.UnitPrice = item.UnitPrice * (decimal).9;
            //}
            //northwindContext.SubmitChanges();
            //Console.WriteLine("Changes Submitted."); 
            #endregion

            #region Ref Parameters
            //string companyName = "";
            //List<Order> orders = northwindContext.GetCustomerDetails("ALFKI", ref companyName).ToList();
            //Console.WriteLine(companyName);
            //foreach (Order item in orders)
            //{
            //    Console.WriteLine(item.OrderID);
            //} 
            #endregion

            #region Handling Multiple Result Shapes from SPROCs
            //IMultipleResults result = northwindContext.VariableShapeSample(1);
            //var products = result.GetResult<Product>();
            //foreach (Product product in products)
            //{
            //    Console.WriteLine(product.ProductName);
            //}

            //IMultipleResults result2 = northwindContext.VariableShapeSample(2);
            //var orders = result2.GetResult<Order>();
            //foreach (Order order in orders)
            //{
            //    Console.WriteLine(order.OrderID);
            //} 
            #endregion

            var products = from p in northwindContext.Products
                           where northwindContext.MyUpperFunction(p.Category.CategoryName) == "BEVERAGES"
                           select new
                           {
                               p.ProductID,
                               p.ProductName,
                               p.UnitPrice
                           };
            foreach (var item in products)
            {
                Console.WriteLine(item.ProductName);
            }
            Console.ReadKey();
        }
    }
}
