public void Post([FromBody] Stewardess stewardess) { if (ModelState.IsValid) { service.Create(stewardess); } }
public async Task <IActionResult> Create([FromBody] StewardessDto stewardess) { if (ModelState.IsValid) { await _service.Create(stewardess); return(Ok(stewardess)); } else { return(new BadRequestObjectResult(ModelState)); } }
public IActionResult Post([FromBody] StewardessDto value) { try { return(Ok(service.Create(value))); } catch (ValidationException e) { return(BadRequest(e.Message)); } catch (Exception ex) { return(BadRequest(ex)); } }
public async Task <IActionResult> Post([FromBody] StewardessDto Stewardess) { if (Stewardess == null) { ModelState.AddModelError("", "Не указаны данные для стюардеси"); return(BadRequest(ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await service.Create(Stewardess); return(Created("api/Stewardesses", Stewardess)); }
public IActionResult Post([FromBody] StewardessDto stewardessDto) { if (!ModelState.IsValid) { return(BadRequest(new { Type = "ValidationError", ErrorMessage = "Required fields is empty" })); } StewardessDto resultDto; try { resultDto = stewardessService.Create(stewardessDto); } catch (Exception ex) { return(BadRequest(new { ErrorType = ex.GetType().Name, ex.Message })); } return(Ok(resultDto)); }