public bool AddEmployee(EmployeesRequestDto newEmployee) { try { var employeeToAdd = new Pracownik { Imie = newEmployee.FirstName, Nazwisko = newEmployee.LastName, RokUr = newEmployee.BirthYear, Miasto = newEmployee.City, Stanowisko = newEmployee.Job, Email = newEmployee.Email, NrTel = newEmployee.PhoneNo, TablicaInfo = newEmployee.Info }; context.Pracownik.Add(employeeToAdd); context.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public IActionResult UpdateEmployee(int id, EmployeesRequestDto requestDto) { if (_service.UpdateEmployee(id, requestDto)) { return(Ok($"Employee with id ({id}) has been updated.")); } else { return(BadRequest($"Employee with provided id ({id}) not found")); } }
public IActionResult AddEmployee(EmployeesRequestDto requestDto) { if (_service.AddEmployee(requestDto)) { return(Ok("New employee created")); } else { return(BadRequest("Something went wrong")); } }
public bool UpdateEmployee(int id, EmployeesRequestDto updateEmployee) { var employeeToEdit = context.Pracownik.SingleOrDefault(x => x.Idpracownik == id); if (employeeToEdit == null) { return(false); } else { employeeToEdit.Imie = updateEmployee.FirstName; employeeToEdit.Nazwisko = updateEmployee.LastName; employeeToEdit.RokUr = updateEmployee.BirthYear; employeeToEdit.Miasto = updateEmployee.City; employeeToEdit.Stanowisko = updateEmployee.Job; employeeToEdit.Email = updateEmployee.Email; employeeToEdit.NrTel = updateEmployee.PhoneNo; employeeToEdit.TablicaInfo = updateEmployee.Info; context.SaveChanges(); return(true); } }