public EmployeeViewModel CreateEmployee(EmployeeWFM inputEmployee) { ApplicationUser user = null; EmployeeViewModel employeeView = null; using (UserManager<ApplicationUser> userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()))) { employeeView = DataMapperView.DoMapping<EmployeeWFM, EmployeeViewModel>(inputEmployee); if (employeeView != null) { if (!String.IsNullOrEmpty(employeeView.IdentityId)) { user = userManager.FindById(employeeView.IdentityId); if (user != null) { employeeView.IdentityFirstName = user.FirstName; employeeView.IdentityLastName = user.LastName; } } } } return employeeView; }
public void SaveEmployee(EmployeeWFM employee, bool saveF = true) { EmployeeDB inputEmployee = null; if (employee != null) { EmployeeDB foundEmployee = dataSource.Employees.GetByID(employee.Id); if (foundEmployee != null) { inputEmployee = DataMapperWFM.DoMapping<EmployeeWFM, EmployeeDB>(employee); dataSource.Employees.Update(inputEmployee); } else { inputEmployee = DataMapperWFM.DoMapping<EmployeeWFM, EmployeeDB>(employee); dataSource.Employees.Create(inputEmployee); } if (saveF) { SaveAllChanges(); } } }