public async Task <ComputerWithEmployeeId> PostComputerAndAssignToEmployee(ComputerWithEmployeeId computer) { var insertedComputer = new ComputerWithEmployeeId(await PostComputer(computer)); using (var db = _db.GetConnection()) { var updated = db.Execute(@"UPDATE Employees SET computerId = @ComputerId WHERE id = @EmployeeId", new { ComputerId = insertedComputer.Id, computer.EmployeeId }); if (updated == 1) { insertedComputer.EmployeeId = computer.EmployeeId; } return(insertedComputer); } }
public async Task <ActionResult <Computer> > PostComputer(ComputerWithEmployeeId computer) { return(computer.EmployeeId is null ? Ok(await _computer.PostComputer(computer)) : Ok(await _computer.PostComputerAndAssignToEmployee(computer))); }