public async Task <HttpResponseMessage> GetNotiNews(int userID, int newsID)
        {
            try
            {
                NotiNews notiNews = new NotiNews();
                NewsDAL  dal      = new NewsDAL();
                NewsInfo data     = await dal.GetNewsByID(userID, newsID);

                notiNews.NewsInfo         = data;
                notiNews.NewsContentInfos = await dal.GetNewsDetail(newsID, userID);

                if (data != null)
                {
                    return(Request.CreateResponse <NotiNews>(HttpStatusCode.OK, notiNews));
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound, Constants.ErrorNotFound));
                }
            }
            catch (DbEntityValidationException ex)
            {
                var    controllerName = ControllerContext.RouteData.Values["controller"].ToString();
                var    actionName     = ControllerContext.RouteData.Values["action"].ToString();
                Logger log            = new Logger();
                log.ErrorLog(ex, controllerName, actionName);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, Constants.ErrorSysError));
            }
        }
Ejemplo n.º 2
0
        public ActionResult NewsDetails(int?id)  // id = news ID
        {
            if (id == null)
            {
                return(BadRequest());
            }

            News news = DAL.GetNewsByID(id);

            if (news != null)
            {
                return(View(news));
            }
            else
            {
                return(View("~/Views/Shared/Error.cshtml"));
            }
        }