public HttpResponseMessage Add(int school_id, [FromBody] NewsClass news) { try { using (Entities entities = new Entities()) { if (entities.ALLOWED_CATS.FirstOrDefault(a => a.NEWS_SUB_CAT_ID == news.subcategory.id && a.USER_ID == news.userId) == null) { return(Request.CreateResponse(HttpStatusCode.OK, new Result() { statusCode = 400, status = "You do not have permission to add news to this subcategory, please request permission from the administrator" })); } NEWS _News = NewsView.CreateNews(entities, news); _News.SCHOOL_ID = school_id; entities.NEWS.Add(_News); entities.SaveChanges(); NewsClass newNews = NewsView.GetNews(entities.NEWS.FirstOrDefault(n => n.NEWS_ID == _News.NEWS_ID)); return(Request.CreateResponse(HttpStatusCode.OK, new Result() { statusCode = 200, status = "Done", results = new List <NewsClass> { newNews } })); } } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.OK, new Result() { statusCode = 400, status = ex.Message })); } }