public IHttpActionResult Put(EmployeeViewModel emp) { try { if (emp.Update() == 1) { return Ok("Employee " + emp.Lastname + " updated."); } else if (emp.Update() == -1) { return Ok("Employee " + emp.Lastname + " not updated!"); } else if (emp.Update() == -2) { return Ok("Employee " + emp.Lastname + " not updated due to stale data."); } else { return Ok("Update Failed"); } } catch (Exception ex) { return BadRequest("Update Failed - " + ex.Message); } }
public IHttpActionResult Put(EmployeeViewModel emp) { try { int errorNumber = emp.Update(); switch (errorNumber) { case 1: return Ok("Employee " + emp.Lastname + " updated!"); break; case -1: return Ok("Employee" + emp.Lastname + " not updated!"); break; case -2: return Ok("Data is stale for " + emp.Lastname + ". Employee not updated!"); break; default: return Ok("Employee" + emp.Lastname + " not updated!"); break; } } catch (Exception ex) { return BadRequest("Update failed - " + ex.Message); } }
public void EmployeeVMUpdateShouldReturnTrue() { EmployeeViewModel vm = new EmployeeViewModel(); vm.GetById("56201963f748f2338c59a8c7"); // Smartypants id vm.Phoneno = "555-555-5551"; int rowsUpdated = vm.Update(); Assert.IsTrue(rowsUpdated == 1); }
public void EmployeeVMUpdateTwiceShouldReturnNegative2() { EmployeeViewModel vm1 = new EmployeeViewModel(); EmployeeViewModel vm2 = new EmployeeViewModel(); vm1.GetById("56201963f748f2338c59a8c7"); // Smartypants Id vm2.GetById("56201963f748f2338c59a8c7"); vm1.Phoneno = "555-555-5551"; int rowsUpdated = vm1.Update(); if (rowsUpdated == 1) rowsUpdated = vm2.Update(); Assert.IsTrue(rowsUpdated == -2); }