public void ComprehensiveVMTests() { CallViewModel cvm = new CallViewModel(); EmployeeViewModel evm = new EmployeeViewModel(); ProblemViewModel pvm = new ProblemViewModel(); cvm.DateOpened = DateTime.Now; cvm.DateClosed = null; cvm.OpenStatus = true; evm.Lastname = "Jarocki"; evm.GetByLastname(); cvm.EmployeeId = evm.Id; evm.Lastname = "Burner"; evm.GetByLastname(); cvm.TechId = evm.Id; pvm.Description = "Memory Upgrade"; pvm.GetByDescription(); cvm.ProblemId = pvm.Id; cvm.Notes = "Kevin has bad RAM, Burner to fix it"; cvm.Add(); Console.WriteLine("New Call Generated - Id = " + cvm.Id); int id = cvm.Id; //need id for delete later cvm.GetById(); cvm.Notes += "\n Ordered new RAM!"; if (cvm.Update() == 1) { Console.WriteLine("Call was updated " + cvm.Notes); } else { Console.WriteLine("Call was not updated!"); } cvm.Notes = "Another change to comments that should not work"; if (cvm.Update() == -2) { Console.WriteLine("Call was not updated data was stale"); } cvm = new CallViewModel(); cvm.Id = id; cvm.GetById(); if (cvm.Delete() == 1) { Console.WriteLine("Call was deleted!"); } else { Console.WriteLine("Call was not deleted"); } cvm.GetById(); }
public void Call_ComprehensiveVMTest() { CallViewModel cvm = new CallViewModel(); EmployeeViewModel evm = new EmployeeViewModel(); ProblemViewModel pvm = new ProblemViewModel(); cvm.DateOpened = DateTime.Now; //cvm.DateClosed = null; cvm.OpenStatus = true; evm.Email = "*****@*****.**"; evm.GetByEmail(); cvm.EmployeeId = evm.Id; //evm.Lastname = "Park"; evm.Email = "*****@*****.**"; evm.GetByEmail(); cvm.TechId = evm.Id; pvm.Description = "Memory Upgrade"; pvm.GetByDescription(); cvm.ProblemId = pvm.Id; cvm.Notes = "Jimin has bad RAM, Burner to fix it"; cvm.Add(); output.WriteLine("New Call Generated - Id = " + cvm.Id); int id = cvm.Id; cvm.GetById(); cvm.Notes += "\n Ordered new RAM!!"; if (cvm.Update() == 1) { output.WriteLine("Call was updated " + cvm.Notes); } else { output.WriteLine("Call was not updated!"); } //cvm.Notes = "Another change to comments that should not works"; //if (cvm.Update() == -2) { // output.WriteLine("Call was not updated data was stale"); //} //cvm = new CallViewModel(); //cvm.Id = id; //cvm.GetById(); //if (cvm.Delete() == 1) //{ // output.WriteLine("Call was deleted!"); //} //else { // output.WriteLine("Call was not deleted!"); //} //Exception ex = Assert.Throws<NullReferenceException>(() => cvm.GetById()); //Assert.Equal("Object reference not set to an instance of an object.", ex.Message); }
public void ComprehensiveVMTests() { CallViewModel cvm = new CallViewModel(); EmployeeViewModel evm = new EmployeeViewModel(); ProblemViewModel pvm = new ProblemViewModel(); cvm.DateOpened = DateTime.Now; cvm.DateClosed = null; cvm.OpenStatus = true; evm.Lastname = "Pollock"; evm.GetByLastname(); cvm.EmployeeId = evm.Id; evm.Lastname = "Burner"; evm.GetByLastname(); cvm.TechId = evm.Id; pvm.Description = "Memory Upgrade"; pvm.GetByDescription(); cvm.ProblemId = pvm.Id; cvm.Notes = "Chris has bad RAM, Burner to fix it"; cvm.Add(); Console.WriteLine("New Call Generated - Id = " + cvm.Id); int id = cvm.Id; // need Id for delete later cvm.GetById(); cvm.Notes += "\n Ordered new RAM!"; if (cvm.Update() == 1) { Console.WriteLine("Call was updated " + cvm.Notes); } else { Console.WriteLine("Call was NOT updated!"); } cvm.Notes = "Another change to comments that should not work."; if (cvm.Update() == -2) { Console.WriteLine("Call was NOT updated, data was stale."); } cvm = new CallViewModel(); // need to reset because of Concurrency cvm.Id = id; cvm.GetById(); if (cvm.Delete() == 1) { Console.WriteLine("Call was deleted!"); } else { Console.WriteLine("Call was NOT deleted!"); } cvm.GetById(); // should throw expected exception }
public void Call_ComprehensiveVMTest() { CallViewModel cvm = new CallViewModel(); EmployeeViewModel evm = new EmployeeViewModel(); ProblemViewModel pvm = new ProblemViewModel(); cvm.DateOpened = DateTime.Now; cvm.DateClosed = null; cvm.OpenStatus = true; evm.Email = "*****@*****.**"; evm.GetByEmail(); cvm.EmployeeId = evm.Id; evm.Lastname = "*****@*****.**"; evm.GetByEmail(); cvm.EmployeeName = evm.Lastname; cvm.TechId = evm.Id; pvm.Description = "Memory Upgrade"; pvm.GetByDescription(); cvm.ProblemId = pvm.Id; cvm.Notes = "Sonia has bad RAM, Burner to fix it"; cvm.Add(); output.WriteLine("New Call Generated - Id = " + cvm.Id); int id = cvm.Id; cvm.GetById(); cvm.Notes += "\n Ordered new RAM!"; if (cvm.Update() == 1) { output.WriteLine("Call was updated " + cvm.Notes); } else { output.WriteLine("Call was not updated!"); } cvm.Notes = "Another change to comments that should not work"; if (cvm.Update() == -2) { output.WriteLine("Call was not updated data was stale"); } cvm = new CallViewModel();// need to reset because of concureency error cvm.Id = id; cvm.GetById(); if (cvm.Delete() == 1) { output.WriteLine("Call was deleted"); } else { output.WriteLine("Call was not deleted"); } Exception ex = Assert.Throws <NullReferenceException>(() => cvm.GetById()); // should throw expected exception Assert.Equal("Object reference not set to an instance of an object.", ex.Message); }
public IActionResult Post(CallViewModel viewModel) { try { viewModel.Add(); return(viewModel.Id > 1 ? Ok(new { msg = "Call " + viewModel.Id + " added!" }) : Ok(new { msg = "Call " + viewModel.Id + " not added!" })); } catch (Exception ex) { _logger.LogError("Problem in " + GetType().Name + " " + MethodBase.GetCurrentMethod().Name + " " + ex.Message); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public IHttpActionResult Post(CallViewModel call) { try { call.Add(); if (call.Id > 0) { return(Ok("Call " + call.Id + " logged!")); } else { return(Ok("Call " + call.Id + " not added!")); } } catch (Exception e) { return(BadRequest("Creation failed - Contact Tech Support")); } }
//Add an employee information to the database. return a result to represent if the addition is successful public IHttpActionResult Post(CallViewModel cal) { try { cal.Add(); if (cal.Id > 0) { return(Ok("Call added!")); } else { return(Ok("Call not added")); } } catch (Exception ex) { return(BadRequest("Retrieve failed - " + ex.Message)); } }
public IHttpActionResult Post(CallViewModel call) { try { //Use the CallViewModel's add method to add a new call to the database call.Add(); if (call.Id > 0) { return(Ok("Call added!")); } else { return(Ok("Call not added!")); } } catch (Exception ex) { return(BadRequest("Creation failed - Contact Tech Support")); } }
// 'POST' method that adds a call to the database public IHttpActionResult Post(CallViewModel call) { try { // Calls the EmployeeViewModel Add() function to add the required // employee data call.Add(); // If an call has been successfully added then display message saying // the add was successful, otherwise display that it was unsuccessful if (call.Id > 0) { return(Ok("Call " + call.Id + " added!")); } else { return(Ok("Call " + call.Id + " not added!")); } } catch (Exception ex) { return(BadRequest("Creating failed - Contact Tech Support")); } }