Exemple #1
0
        private async void ModifyClick(object sender, RoutedEventArgs e)
        {
            if (grid.SelectedItem == null)
            {
                MessageBox.Show("Select a record!");
                return;
            }
            Region    r  = grid.SelectedItem as Region;
            AddRegion rg = new AddRegion(DialogTypes.Modify);

            rg.nameBox.Text   = r.Name;
            rg.areaBox.Text   = r.Area.ToString();
            rg.peopleBox.Text = r.PeopleId.ToString();
            if (rg.ShowDialog() == true)
            {
                r.Name     = rg.nameBox.Text;
                r.Area     = int.Parse(rg.areaBox.Text);
                r.PeopleId = int.Parse(rg.peopleBox.Text);
                using (PeopleContext db = new PeopleContext())
                {
                    db.Entry(r).State = System.Data.Entity.EntityState.Modified;
                    await db.SaveChangesAsync();
                }
            }
            ShowDataAsync();
        }
Exemple #2
0
        private async void AddClick(object sender, RoutedEventArgs e)
        {
            AddRegion rg = new AddRegion(DialogTypes.Add);

            if (rg.ShowDialog() == true)
            {
                Region r = new Region
                {
                    Name     = rg.nameBox.Text,
                    Area     = int.Parse(rg.areaBox.Text),
                    PeopleId = int.Parse(rg.peopleBox.Text)
                };
                await Task.Run(() => AddData(r));
            }
            ShowDataAsync();
        }