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

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

            #region Custom Property Validation Support
            //Customer c = northwindContext.Customers.Where(c1 => c1.CustomerID == "ALFKI").Single();
            //Console.WriteLine(c.CustomerID);
            //Console.WriteLine(c.Phone);
            //Console.ReadKey();
            //Console.WriteLine("Updating");
            //try
            //{
            //    c.Phone = "123-456-7890";
            //    northwindContext.SubmitChanges();
            //    Console.WriteLine("Updated");
            //}
            //catch (Exception e)
            //{

            //    Console.WriteLine(e.Message);
            //    Console.WriteLine("Update Aborted.");
            //}


            #endregion

            #region Custom Entity Object Validation Support
            //Order o = new Order();
            //o.OrderDate = DateTime.Now;
            //o.RequiredDate = DateTime.Now.AddDays(-1);

            //northwindContext.Orders.InsertOnSubmit(o);
            //northwindContext.SubmitChanges(); 
            #endregion

            Customer customer = northwindContext.Customers.Single(c => c.CompanyName == "Alfreds Futterkiste");

            Order o = new Order()
            {
                OrderDate=DateTime.Now,
                ShipAddress = "Some Address",
                ShipPostalCode = "23456"
            };

            customer.Orders.Add(o);

            northwindContext.SubmitChanges();
            Console.WriteLine("Changes Submitted");
            Console.ReadKey();


        }
    }
}
