public async Task <IActionResult> Edit(EmployeeEditBindingModel model) { if (ModelState.IsValid) { EmployeeEditServiceModel employeeEditServiceModel = new EmployeeEditServiceModel() { Id = model.Id, FirstName = model.FirstName, LastName = model.LastName, StartingDate = model.StartingDate, Salary = model.Salary, ExperienceLevel = model.ExperienceLevel, VacationDays = model.VacationDays, }; bool result = await this._employeeServices.UpdateAsync(employeeEditServiceModel); if (!result) { return(RedirectToAction("Error", "Home")); } return(RedirectToAction("Details", new { id = model.Id })); } return(View(model)); }
public async Task <bool> UpdateAsync(EmployeeEditServiceModel employee) { Employee dbEmployee = await this._context.Employees.FirstOrDefaultAsync(e => e.EmployeeId == employee.Id); if (dbEmployee == null) { return(false); } dbEmployee.ExperienceLevel = employee.ExperienceLevel; dbEmployee.FirstName = employee.FirstName; dbEmployee.LastName = employee.LastName; dbEmployee.Salary = employee.Salary; dbEmployee.VacationDays = employee.VacationDays; dbEmployee.StartingDate = employee.StartingDate; var employeeToUpdate = _context.Employees.Attach(dbEmployee); employeeToUpdate.State = EntityState.Modified; int result = await _context.SaveChangesAsync(); if (result > 0) { return(true); } return(false); }