private void button_Click(object sender, RoutedEventArgs e) { using (CRMContext dbContext = new CRMContext()) { status.Status = l_id.Text; 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.Entry(status).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); } catch { MessageBox.Show("Ошибка!"); } } if (Validator.TryValidateObject(status, context, results, true)) { this.Close(); } } }
public async Task <IActionResult> Post([FromBody] Customer customer) { if (customer == null) { return(BadRequest()); } _context.Customer.Add(customer); await _context.SaveChangesAsync(); // This loads the nested details object onto the customer object, without it customer.details is null _context.Entry(customer).Reference(c => c.details).Load(); CustomerDTO customerDto = new CustomerDTO() { Id = customer.customer_id, Name = customer.name, Email = customer.email, Phone = customer.phone, Age = customer.age, Details = customer.details }; return(CreatedAtRoute("GetCustomer", new { id = customer.customer_id }, customerDto)); }
public async Task <IActionResult> Post([FromBody] Lead lead) { if (lead == null) { return(BadRequest()); } _context.Lead.Add(lead); await _context.SaveChangesAsync(); _context.Entry(lead).Reference(l => l.status).Load(); _context.Entry(lead).Reference(l => l.priority).Load(); _context.Entry(lead).Reference(l => l.customer).Load(); // _context.Entry(lead).Reference(l => l.customer.details).Load(); <- figure this out, not working throws a 500 _context.Entry(lead).Reference(l => l.employee).Load(); LeadDTO leadDto = new LeadDTO() { Id = lead.lead_id, LastContact = lead.last_contact, Status = lead.status, Priority = lead.priority, Customer = new CustomerDTO() { Id = lead.customer.customer_id, Name = lead.customer.name, Email = lead.customer.email, Phone = lead.customer.phone, Age = lead.customer.age, Details = lead.customer.details }, Employee = new EmployeeDTO() { Id = lead.employee.employee_id, Name = lead.employee.name, Email = lead.employee.email, Phone = lead.employee.phone } }; return(CreatedAtRoute("GetLead", new { id = lead.lead_id }, leadDto)); }
private void button_Click(object sender, RoutedEventArgs e) { using (CRMContext dbContext = new CRMContext()) { del_manager.Name = tb_name.Text; del_manager.Login = tb_login.Text; if (tb_password.Text != null) { del_manager.Password = Hash.EncryptPassword(tb_login.Text, tb_password.Text); } del_manager.Position = cb_position.SelectedItem.ToString(); del_manager.Group = cb_group.SelectedItem.ToString(); del_manager.Address = tb_address.Text; del_manager.Phone = tb_phone.Text; del_manager.Passport = tb_passport.Text; if (del_manager.DateOfBirth >= (DateTime.Today).AddYears(18)) { MessageBox.Show("Некорректный ввод даты рождения"); } else { del_manager.DateOfBirth = d_dateofbirth.SelectedDate; } del_manager.DateRecruitment = d_daterecruitment.SelectedDate; del_manager.Email = tb_email.Text; del_manager.Info = tb_info.Text; var results = new List <System.ComponentModel.DataAnnotations.ValidationResult>(); var context = new ValidationContext(del_manager); if (!Validator.TryValidateObject(del_manager, context, results, true)) { foreach (var error in results) { MessageBox.Show(error.ErrorMessage); } } else { try { dbContext.Entry(del_manager).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); } catch { MessageBox.Show("Ошибка!"); } } if (Validator.TryValidateObject(del_manager, context, results, true)) { this.Close(); } } }
private void Button_Click_1(object sender, RoutedEventArgs e) { using (CRMContext dbContext = new CRMContext()) { foreach (var item in dbContext.Tasks) { dbContext.Entry(item).State = System.Data.Entity.EntityState.Deleted; } foreach (var item in dbContext.Managers) { if (item.Name != "Харсеко Никита Игоревич") { dbContext.Entry(item).State = System.Data.Entity.EntityState.Deleted; } } foreach (var item in dbContext.Clients) { dbContext.Entry(item).State = System.Data.Entity.EntityState.Deleted; } dbContext.SaveChanges(); } }
private void button_Click(object sender, RoutedEventArgs e) { try { if (del_obj != null) { using (CRMContext dbContext = new CRMContext()) { dbContext.Entry(del_obj).State = System.Data.Entity.EntityState.Deleted; dbContext.SaveChanges(); } } this.Close(); } catch (Exception) { MessageBox.Show("Ошибка! Имеются записи, которые зависят от этой записи!"); } }
private void button_Click(object sender, RoutedEventArgs e) { using (CRMContext dbContext = new CRMContext()) { del_client.Name = tb_name.Text; del_client.Address = tb_address.Text; del_client.Phone = tb_phone.Text; del_client.Email = tb_email.Text; del_client.CheckingAccount = tb_checkingAccoubt.Text; del_client.Bank = tb_bank.Text; del_client.Director = tb_director.Text; del_client.Accountant = tb_acccountant.Text; del_client.Info = tb_info.Text; var results = new List <System.ComponentModel.DataAnnotations.ValidationResult>(); var context = new ValidationContext(del_client); if (!Validator.TryValidateObject(del_client, context, results, true)) { foreach (var error in results) { MessageBox.Show(error.ErrorMessage); } } else { try { dbContext.Entry(del_client).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); } catch { MessageBox.Show("Ошибка!"); } } if (Validator.TryValidateObject(del_client, context, results, true)) { this.Close(); } } }
private void button_Click(object sender, RoutedEventArgs e) { using (CRMContext dbContext = new CRMContext()) { del_task.Client = l_client.Text; del_task.Manager = l_manager.Text; del_task.Task = l_task.Text; del_task.Info = l_info.Text; del_task.Status = l_status.Text; del_task.DateStart = d_start.SelectedDate; del_task.DateComplete = d_complete.SelectedDate; var results = new List <System.ComponentModel.DataAnnotations.ValidationResult>(); var context = new ValidationContext(del_task); if (!Validator.TryValidateObject(del_task, context, results, true)) { foreach (var error in results) { MessageBox.Show(error.ErrorMessage); } } else { try { dbContext.Entry(del_task).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); } catch { MessageBox.Show("Ошибка!"); } } if (Validator.TryValidateObject(del_task, context, results, true)) { this.Close(); } } }