public IHttpActionResult Create([FromBody] ArticleDTO article) { try { if (!ModelState.IsValid) { return(BadRequest()); } var domainArticle = ArticleDTO.ToModel(article); var addedArticle = articleService.Add(domainArticle); var addedArticleDTO = ArticleDTO.ToDTO((Article)addedArticle); return(CreatedAtRoute("DefaultApi", new { id = addedArticle.Id }, addedArticleDTO)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult Get() { try { var entities = articleService.GetAllArticles().Select(x => ArticleDTO.ToDTO((Article)x)); if (entities.Any()) { return(Ok(entities)); } else { return(NotFound()); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
// GET: api/Articles/5 public IHttpActionResult Get(int id) { try { var entity = ArticleDTO.ToDTO((Article)articleService.GetById(id)); if (entity != null) { return(Ok(entity)); } else { return(NotFound()); } } catch (Exception ex) { //return BadRequest(ex.Message); return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex))); } }