/// <summary> /// Get dump truck by id /// </summary> /// <param name="id">id of DumpTruck to fetch</param> /// <response code="200">OK</response> /// <response code="404">DumpTruck not found</response> public virtual IActionResult DumptrucksIdGetAsync(int id) { bool exists = _context.DumpTrucks.Any(a => a.Id == id); if (exists) { DumpTruck result = _context.DumpTrucks.First(a => a.Id == id); return(new ObjectResult(new HetsResponse(result))); } // record not found return(new ObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration)))); }
/// <summary> /// Update dump truck /// </summary> /// <param name="id">id of DumpTruck to fetch</param> /// <param name="item"></param> /// <response code="200">OK</response> /// <response code="404">DumpTruck not found</response> public virtual IActionResult DumptrucksIdPutAsync(int id, DumpTruck item) { bool exists = _context.DumpTrucks.Any(a => a.Id == id); if (exists && id == item.Id) { _context.DumpTrucks.Update(item); // Save the changes _context.SaveChanges(); return(new ObjectResult(new HetsResponse(item))); } // record not found return(new ObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration)))); }
/// <summary> /// /// </summary> /// <param name="item"></param> /// <response code="201">DumpTruck created</response> public virtual IActionResult DumptrucksPostAsync(DumpTruck item) { var exists = _context.DumpTrucks.Any(a => a.Id == item.Id); if (exists) { _context.DumpTrucks.Update(item); } else { // record not found _context.DumpTrucks.Add(item); } // Save the changes _context.SaveChanges(); return(new ObjectResult(item)); }
/// <summary> /// /// </summary> /// <param name="id">id of DumpTruck to fetch</param> /// <param name="item"></param> /// <response code="200">OK</response> /// <response code="404">DumpTruck not found</response> public virtual IActionResult DumptrucksIdPutAsync(int id, DumpTruck item) { var exists = _context.DumpTrucks.Any(a => a.Id == id); if (exists && id == item.Id) { _context.DumpTrucks.Update(item); // Save the changes _context.SaveChanges(); return(new ObjectResult(item)); } else { // record not found return(new StatusCodeResult(404)); } }
/// <summary> /// Delete dump truck /// </summary> /// <param name="id">id of DumpTruck to delete</param> /// <response code="200">OK</response> /// <response code="404">DumpTruck not found</response> public virtual IActionResult DumptrucksIdDeletePostAsync(int id) { bool exists = _context.DumpTrucks.Any(a => a.Id == id); if (exists) { DumpTruck item = _context.DumpTrucks.First(a => a.Id == id); if (item != null) { _context.DumpTrucks.Remove(item); // Save the changes _context.SaveChanges(); } return(new ObjectResult(new HetsResponse(item))); } // record not found return(new ObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration)))); }
/// <summary> /// Setup the test. /// </summary> public DumpTruckModelTests() { instance = new DumpTruck(); }
/// <summary> /// Basic Integration test for DumpTrucks /// </summary> public async void TestDumpTrucksBasic() { string initialName = "InitialName"; string changedName = "ChangedName"; // first test the POST. var request = new HttpRequestMessage(HttpMethod.Post, "/api/dumptrucks"); // create a new object. DumpTruck dumptruck = new DumpTruck(); dumptruck.BoxCapacity = initialName; string jsonString = dumptruck.ToJson(); request.Content = new StringContent(jsonString, Encoding.UTF8, "application/json"); var response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); // parse as JSON. jsonString = await response.Content.ReadAsStringAsync(); dumptruck = JsonConvert.DeserializeObject <DumpTruck>(jsonString); // get the id var id = dumptruck.Id; // change the name dumptruck.BoxCapacity = changedName; // now do an update. request = new HttpRequestMessage(HttpMethod.Put, "/api/dumptrucks/" + id); request.Content = new StringContent(dumptruck.ToJson(), Encoding.UTF8, "application/json"); response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); // do a get. request = new HttpRequestMessage(HttpMethod.Get, "/api/dumptrucks/" + id); response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); // parse as JSON. jsonString = await response.Content.ReadAsStringAsync(); dumptruck = JsonConvert.DeserializeObject <DumpTruck>(jsonString); // verify the change went through. Assert.Equal(dumptruck.BoxCapacity, changedName); // do a delete. request = new HttpRequestMessage(HttpMethod.Post, "/api/dumptrucks/" + id + "/delete"); response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); // should get a 404 if we try a get now. request = new HttpRequestMessage(HttpMethod.Get, "/api/dumptrucks/" + id); response = await _client.SendAsync(request); Assert.Equal(response.StatusCode, HttpStatusCode.NotFound); }
public DumpTruckBuilder() { Car = new DumpTruck(); RandomCarName(); }
private void Awake() { Instance = this; }
/// <summary> /// /// </summary> /// <param name="id">id of DumpTruck to fetch</param> /// <param name="item"></param> /// <response code="200">OK</response> /// <response code="404">DumpTruck not found</response> public virtual IActionResult DumptrucksIdPutAsync(int id, DumpTruck item) { var result = ""; return(new ObjectResult(result)); }
/// <summary> /// /// </summary> /// <param name="item"></param> /// <response code="201">DumpTruck created</response> public virtual IActionResult DumptrucksPostAsync(DumpTruck item) { var result = ""; return(new ObjectResult(result)); }
public virtual IActionResult DumptrucksIdPut([FromRoute]int id, [FromBody]DumpTruck item) { return _service.DumptrucksIdPutAsync(id, item); }
public virtual IActionResult DumptrucksPost([FromBody]DumpTruck item) { return _service.DumptrucksPostAsync(item); }