public void AddEmployee(EmployeeDTO employee) { using (var context = new TimeCardContext()) { context.Employees.Add(employee.ToDomain(true)); context.SaveChanges(); } }
public static EmployeeDTO ToDTO(this Employee employee, bool mapTimeCards) { if (employee == null) { return null; } var dto = new EmployeeDTO { Id = employee.Id, FirstName = employee.FirstName, LastName = employee.LastName, Title = employee.Title, TimeCards = new List<TimeCardDTO>() }; if (mapTimeCards && employee.TimeCards != null) { dto.TimeCards = employee.TimeCards.Select(tc => tc.ToDTO(true)).ToList(); } return dto; }