public Change_cGroup(BD.CatalogGroupManagers rg) { InitializeComponent(); using (CRMContext dbContext = new CRMContext()) { group = dbContext.CatalogGroupManagers.Find(rg.Group); l_id.Text = group.Group; } }
private void button_Click(object sender, RoutedEventArgs e) { using (CRMContext dbContext = new CRMContext()) { var group = new BD.CatalogGroupManagers(); Random rnd = new Random(); try { int i = 1 + rnd.Next(10000); group.Group = l_id.Text; group.Id = i; } catch (Exception) { MessageBox.Show("Повторите попытку"); } var results = new List <System.ComponentModel.DataAnnotations.ValidationResult>(); var context = new ValidationContext(group); if (!Validator.TryValidateObject(group, context, results, true)) { foreach (var error in results) { MessageBox.Show(error.ErrorMessage); } } else { try { dbContext.CatalogGroupManagers.Add(group); dbContext.SaveChanges(); } catch { MessageBox.Show("Ошибка"); } } if (Validator.TryValidateObject(group, context, results, true)) { this.Close(); } } }
public Delete(BD.CatalogGroupManagers cg) { InitializeComponent(); del_obj = cg; }