public static void UpdateData <T>(T obj) where T : class, IObjectDB { using (MyDBContext context = new MyDBContext()) { T objDb = context.Set <T>().Where(c => c.Id == obj.Id).First <T>(); HandlingObjects.CopyValueProperties <T>(objDb, obj); context.SaveChanges(); } }
public VMEmployeeWindow(Employee employee, Action action, EmployeeWindow employeeWindow, bool isnNew = false) { IsNew = isnNew; Positions = DataQueries.SelectPositions(); Departments = DataQueries.SelectDepartments(); Salaries = DataQueries.SelectSalaries(); UpdateInfo = action; oldEmployee = employee; NewEmployee = new Employee(); if (!IsNew) { HandlingObjects.CopyValueProperties(NewEmployee, employee); SelectedPosition = Positions.Where(c => c.Id == employee.Position.Id).First(); SelectedDepartment = Departments.Where(c => c.Id == employee.Department.Id).First(); SelectedSalary = Salaries.Where(c => c.Id == employee.Salary.Id).First(); } EmployeeWindow = employeeWindow; }
private void SaveEmployeeMethod(Object obj) { if (obj is Employee) { HandlingObjects.CopyValueProperties <Employee>(oldEmployee, NewEmployee); UpdateInfo?.Invoke(); if (IsNew) { Person person = new Person(); HandlingObjects.CopyValueProperties <Person>(person, (Person)oldEmployee); DataQueries.AddData <Person>(person); oldEmployee.FillPerson(person); oldEmployee.Position_id = oldEmployee.Position.Id; oldEmployee.Department_id = oldEmployee.Department.Id; oldEmployee.Salary_id = oldEmployee.Salary.Id; DataQueries.AddData <Employee>(oldEmployee); } } }