public object ModifyEmployee(int?id, EmployeeDepartmentModel employee) { try { if (id == 0 && employee.EmployeeId == 0 || id == null) { return(BadRequest("Employee ID mismatch")); } if (ModelState.IsValid) { //Kindly refer SQLEmployeeRepository for logic var employeeToUpdate = employeeRepository.UpdateEmployee(employee); if (employeeToUpdate == null) { return(NotFound($"Employee with Id = {id} not found")); } } return(StatusCode(StatusCodes.Status200OK, "Employee modified successfully")); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, "Error updating data")); } }
public object CreateEmployee(EmployeeDepartmentModel employee) { try { if (employee == null) { return(BadRequest()); } if (ModelState.IsValid) { //Kindly refer SQLEmployeeRepository for logic var createdEmployee = employeeRepository.AddEmployee(employee); } return(StatusCode(StatusCodes.Status201Created, "Employee created successfully")); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, "Error creating new employee record")); } }