public IActionResult CreateNewsItem([FromBody] NewsItemInputModel body) { if (!ModelState.IsValid) { return(BadRequest("Data was not properly formatted.")); } var newNewsItem = _newsItemService.CreateNewsItem(body); return(CreatedAtRoute("GetNewsItemsById", new { id = newNewsItem.Id }, null)); }
public IActionResult CreateNewsItem([FromBody] NewsItemsInputModel newsItem) { if (!ModelState.IsValid) { throw new ModelFormatException(ModelState.RetrieveErrorString()); } var newsItemDto = _newsItemService.CreateNewsItem(newsItem); return(CreatedAtRoute("CreateNewsItem", new { id = newsItemDto.Id }, null)); }
public IActionResult CreateNewsItem([FromBody] NewsItemInputModel model) { if (Request.Headers["Authorization"] != _authorizationHeader) { return(BadRequest("Authorization required.")); } if (!ModelState.IsValid) { return(BadRequest("Model formatting is invalid")); } var entity = _newsItemService.CreateNewsItem(model); return(CreatedAtRoute("GetNewsItemById", new { id = entity.Id }, entity)); }
public IActionResult CreateNewsItem([FromBody] NewsItemInputModel body) { if (!ModelState.IsValid) { return(StatusCode(412, body)); } var authKey = Request.Headers["Authorization"].ToString(); if (authKey == DataProvider.GetAdminPass()) { var entity = _newsItemService.CreateNewsItem(body); return(CreatedAtRoute("GetNewsById", new { id = entity.Id }, null)); } return(StatusCode(401, "User not authorized")); }