public IActionResult Edit(EditEmployeeBindingModel bm, int id) { var employee = EmployeeServices.GetEmployeeById(id); var expLevels = new[] { "A", "B", "C", "D" }; if (bm.ExperinceLevel != null && !expLevels.Contains(bm.ExperinceLevel)) { ModelState.AddModelError("ExperinceLevel", "Experince Level must be \"A\", \"B\", \"C\", \"D\""); var dtoComp = CompanyServices.GetAllCompanies(); var dto = new EditEmployeeDto() { Companies = dtoComp, Employee = employee }; return(this.View(dto)); } EditEmployee(bm, employee); this.EmployeeServices.UpdateEmployee(employee); var companies = this.CompanyServices.GetAllCompanies(); employee = EmployeeServices.GetEmployeeById(id); var employeeDto = new EditEmployeeDto() { Employee = employee, Companies = companies }; this.ViewData["edit"] = "You have successfully edited this employee!"; return(this.View(employeeDto)); }
private static void EditEmployee(EditEmployeeBindingModel bm, Employee employee) { if (bm.ExperinceLevel != null) { employee.ExperinceLevel = bm.ExperinceLevel; } if (bm.Name != null) { employee.Name = bm.Name; } if (bm.CompanyId != null) { employee.CompanyId = bm.CompanyId.Value; } if (bm.PictureUrl != null) { employee.PictureUrl = bm.PictureUrl; } if (bm.Salary != null) { employee.Salary = bm.Salary.Value; } if (bm.StartDate != null) { employee.StartDate = bm.StartDate.Value; } if (bm.VacationDays != null) { employee.VacationDays = bm.VacationDays.Value; } }