// // GET: /Index/Edit/5 public ActionResult Edit(Int32 id) { var page = new EmployeeEditPage(); var employeesAccessor = DataAccessor.CreateInstance<EmployeesAccessor>(); var positions = DataAccessor.CreateInstance<PositionsAccessor>().GetPositions(); var skillsAccessor = DataAccessor.CreateInstance<SkillsAccessor>(); page.Employee = employeesAccessor.GetEmployee(id); page.SelectedPosition = page.Employee.PositionId; page.Skills = employeesAccessor.GetEmployeeSkills(id); page.PossiblePositions = positions .Select(p => new PositionDto { PositionId = p.PositionId, PositionName = p.PositionName, Skills = skillsAccessor.GetSkills(p.PositionId) }) .ToList(); var employeePosition = page.PossiblePositions.Where(p => p.PositionId == page.Employee.PositionId).FirstOrDefault(); foreach (var skill in employeePosition.Skills) { foreach (var empSkill in page.Skills) { if (skill.SkillId == empSkill.SkillId) { skill.Selected = true; break; } else { skill.Selected = false; } } } return View(page); }
public ActionResult Edit(Int32 id, EmployeeEditPage page) { var employeeAccessor = DataAccessor.CreateInstance<EmployeesAccessor>(); var employeeSkills = page.SelectedSkills.Select(s => new EmployeeSkills(page.Employee.EmployeeId, s)).ToList(); employeeAccessor.UpdateEmployee(page.Employee.EmployeeFullName, page.Employee.Age, (Int16)page.Employee.Gender, page.SelectedPosition); employeeAccessor.UpdateEmployeeSkills(page.Employee.EmployeeId, employeeSkills); return RedirectToAction("Index"); }