public async Task <HttpResponseMessage> GetTopNews(int userID) { try { NewsDAL dal = new NewsDAL(); TopNewsInfo data = await dal.GetTopNews(userID); if (data != null) { return(Request.CreateResponse <TopNewsInfo>(HttpStatusCode.OK, data)); } 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)); } }
public void StartLoadToNews() { string tag = __tag + "[StartLoadToNews]"; try { var result = NewsDAL.GetTopNews(10); if (result.Code < 0) { LogHelpers.WriteError(tag, result.ErrorMessage); return; } lvHomeNews.DataSource = result.Data; lvHomeNews.DataBind(); } catch (Exception ex) { LogHelpers.WriteException(tag, ex.ToString()); } }