예제 #1
0
 private void button_Click(object sender, RoutedEventArgs e)
 {
     using (var context = new Context())
     {
         var countryThird = new CountryProducing()
         {
             CountryName = textBox1.Text
                           // Mark = 12
         };
         context.CountryProducings.Add(countryThird);
         context.SaveChanges();
         var countryProducing = context.CountryProducings.OrderBy(val => val.Id).ToList();
         dataGrid.ItemsSource = countryProducing;
     }
 }
예제 #2
0
        private void Car_Model_Click(object sender, RoutedEventArgs e)
        {
            // try
            // {
            using (var context = new Context())
            {
                List <CountryProducing> temp = new List <CountryProducing>();
                var countryOne = new CountryProducing();
                countryOne.CountryName = "Japan";
                countryOne.Price       = 22.4;

                var countryTwo = new CountryProducing()
                {
                    CountryName = "Germany",
                    Price       = 10.1
                };
                var countryThird = new CountryProducing()
                {
                    CountryName = "France",
                    Price       = 31.3
                };
                temp.Add(countryOne);
                temp.Add(countryTwo);
                temp.Add(countryThird);
                foreach (var item in temp)
                {
                    context.CountryProducings.Add(item);
                }
                foreach (var item in context.CountryProducings)
                {
                    item.CarBrands = context.CarBrands.Where(s => s.CountryProducingId == item.Id).ToList();
                }
                context.SaveChanges();
                //int id = Convert.ToInt32(textBox.Text);
                //var updatedcountry = context.CountryProducings.FirstOrDefault(country => country.Id == id);
                //context.CountryProducings.Attach(updatedcountry);
                //context.Entry(updatedcountry).State = EntityState.Modified;
                //updatedcountry.CountryName = textBox1.Text;
                //context.SaveChanges();
                var countryProducing = context.CountryProducings.Include(car => car.CarBrands).OrderBy(val => val.Id).ToList();
                dataGrid.ItemsSource = countryProducing;
            }
            //}
            //catch (Exception ex)
            //{
            //     MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            //}
        }
예제 #3
0
        private void dataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            CountryProducing country = new CountryProducing();

            if (dataGrid.SelectedItem != null)
            {
                country = (CountryProducing)dataGrid.SelectedItem;
                using (var context = new Context())
                {
                    var responses = context.CarBrands
                                    .Join(context.CountryProducings,
                                          c => c.CountryProducingId,
                                          o => o.Id,
                                          (c, o) => new { c, o })
                                    .Where(t => t.c.CountryProducingId == country.Id)
                                    .OrderBy(x => x.c.Id)
                                    .Select(x => new { x.c.Id, x.c.Brand, x.o.CountryName, x.c.Logo }).ToList();
                    dataGrid_Copy.ItemsSource = responses;
                }
            }
        }