public async Task <IActionResult> PutObsticale([FromRoute] long id, [FromBody] Obsticale obsticale) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != obsticale.id) { return(BadRequest()); } _context.Entry(obsticale).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ObsticaleExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PostObsticale([FromBody] Obsticale obsticale) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Obsticale.Add(obsticale); await _context.SaveChangesAsync(); return(CreatedAtAction("GetObsticale", new { id = obsticale.id }, obsticale)); }
public async Task <Uri> CreateObstacleAsync(Obsticale obstacle) { HttpResponseMessage response = await client.PostAsync("https://localhost:44371/api/obstacles", new StringContent(JsonConvert.SerializeObject(obstacle), Encoding.UTF8, "application/json")); response.EnsureSuccessStatusCode(); // Deserialize the updated product from the response body. await response.Content.ReadAsStringAsync(); // return URI of the created resource. return(response.Headers.Location); }
public void Create_Obsticales(string type) { if (type == "R") { Obsticale temp = ObsFactory.CreateObsticale(type); Assert.AreEqual("Red", temp.Type); Assert.AreEqual(20, temp.Health_points); } else if (type == "G") { Obsticale temp = ObsFactory.CreateObsticale(type); Assert.AreEqual("Green", temp.Type); Assert.AreEqual(30, temp.Health_points); } else { Obsticale temp = ObsFactory.CreateObsticale(type); Assert.AreEqual("Blue", temp.Type); Assert.AreEqual(50, temp.Health_points); } }
public async Task <Uri> addObstacleToDatabase(Obsticale obstacle) { return(await WebClient.CreateObstacleAsync(obstacle)); }