public HttpResponseMessage Subject(int school_id, int cat_id, int user_id) { try { using (Entities entities = new Entities()) { List <NewsClass> newsList = new List <NewsClass>(); UserPrivateInfoClass user = new UserPrivateInfoClass(user_id); if (user != null) { foreach (var _subject in user.subjects) { var rowNews = entities.NEWS_ACL_SUBJECTS.Where(n => n.SUBJECT_ID == _subject.id).ToList(); foreach (var news in rowNews.Where(n => n.NEWS.NEWS_SUB_CATS.NEWS_CAT_ID == cat_id)) { if (news.NEWS.APPROVED == 1) { newsList.Add(NewsView.GetNews(news.NEWS, PrivateNewsType.Subject)); } } } } if (newsList.Count == 0) { return(Request.CreateResponse(HttpStatusCode.OK, new Result() { statusCode = 404, totalPage = newsList.Count, status = "There are not news", results = newsList })); } return(Request.CreateResponse(HttpStatusCode.OK, new Result() { statusCode = 200, totalPage = newsList.Count, numResult = newsList.Count, page = 1, status = "Success", results = newsList })); } } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.OK, new Result() { statusCode = 400, status = ex.Message })); } }
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 })); } }