public async Task Post_WhenInvalidAircraft_ReturnCreatedResult() { AircraftDto aircraft = new AircraftDto() { AircraftName = "Test", TypeAircraftId = 10 }; A.CallTo(() => service.Create(aircraft)).Returns(aircraft); IActionResult result = await aircraftsController.Post(aircraft); Assert.True(result is CreatedResult); }
public IActionResult Post([FromBody] AircraftDto Aircraft) { if (Aircraft == null) { ModelState.AddModelError("", "Не указаны данные для cамолёта"); return(BadRequest(ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } service.Create(Aircraft); return(Created("api/Aircrafts", Aircraft)); }
public ActionResult <Aircraft> Post([FromBody] Aircraft aircraft) { try { if (ModelState.IsValid) { AircraftService.Create(aircraft); return(CreatedAtAction(nameof(Get), new { model = aircraft.Model }, aircraft)); } else { logger.LogError(1, "Invalid or missing parameters"); return(BadRequest(ModelState)); } } catch (Exception ex) { logger.LogError(ex, "Post aircraft"); return(NotFound(ex.Message)); } }
public async Task <ActionResult> Create([FromBody] AircraftModel model) { await _aircraftService.Create(model); return(Ok()); }