public void InsertEmployee(Employee employee) { employee.ValidateRules(); Action procedure = () => { if (employee.Address !=null && !string.IsNullOrEmpty(employee.Address.HouseNumber)) { Database.Insert(employee.Address); } if (employee.AdditionalInfo!= null && !string.IsNullOrEmpty(employee.AdditionalInfo.Notes)) { Database.Insert(employee.AdditionalInfo); } Database.Insert(employee); employee.Programs.ForEach(p => { p.EmployeeId = employee.Id; Database.Insert(p); }); }; Database.ExecuteInTransaction(procedure); }
public void UpdateEmployee(Employee employee) { employee.ValidateRules(); Action procedure = () => { Database.Save(employee.Address); Database.Save(employee.FinancialInfo); Database.Save(employee.AdditionalInfo); Database.Update(employee); employee.Programs.ForEach(p => { p.EmployeeId = employee.Id; Database.Save(p); }); }; Database.ExecuteInTransaction(procedure); }