using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using IdeaBlade.EntityModel;
using CodeFirstWalk.Model;
using CodeFirstWalk.Model2;
using System.Windows;

namespace CodeFirstWalk {
  public class MainWindowViewModel {
    public MainWindowViewModel() {
      var manager = new ProductEntities();
      manager.EntityServerError += Manager_EntityServerError;

      var manager2 = new ProductEntities2();
      manager2.EntityServerError += Manager_EntityServerError;

      var supplier = new Supplier { CompanyName = "All Fine Foods" };
      manager.AddEntity(supplier);
      var supplier2 = new Supplier2 { CompanyName = "All Fine Foods - Second Model Test" };
      manager2.AddEntity(supplier2);

      var category = new Category { CategoryName = "Sweet Things on " + DateTime.Now.ToString("o") };
      manager.AddEntity(category);
      var category2 = new Category2 { Category2Name = "Sweet Things - Second Model Test - on " + DateTime.Now.ToString("o") };
      manager2.AddEntity(category2);

      AddNewProduct("Chocolate Cream Pie", category, supplier);
      AddNewProduct("Baklava", category, supplier);

      AddNewProduct2("Chocolate Cream Pie - Model2 test", category2, supplier2);
      AddNewProduct2("Baklava - Model2 test", category2, supplier2);

      manager.SaveChanges();
      manager2.SaveChanges();
    }

    void Manager_EntityServerError(object sender, EntityServerErrorEventArgs e) {
      MessageBox.Show(e.Exception.Message);
    }

    private void AddNewProduct(string productName, Category category, Supplier supplier) {
      var newProduct = new Product {
        ProductName = productName,
        Category = category,
        Supplier = supplier,
      };
    }

    private void AddNewProduct2(string productName, Category2 category2, Supplier2 supplier2) {
      var newProduct2 = new Product2 {
        Product2Name = productName,
        Category2 = category2,
        Supplier2 = supplier2,
      };
    }
  }
}
