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