コード例 #1
0
        public async Task <ActionResult> Toggle(int id)
        {
            var b = await LinksService.GetQuery(m => m.Id == id).UpdateFromQueryAsync(m => new Links()
            {
                Status = m.Status == Status.Unavailable ? Status.Available : Status.Unavailable
            }) > 0;

            return(ResultData(null, b, b ? "切换成功!" : "切换失败!"));
        }
コード例 #2
0
        public async Task <ActionResult> ToggleRecommend(int id)
        {
            var b = await LinksService.GetQuery(m => m.Id == id).UpdateFromQueryAsync(m => new Links()
            {
                Recommend = !m.Recommend
            }) > 0;

            return(ResultData(null, b, b ? "切换成功!" : "切换失败!"));
        }
コード例 #3
0
        public async Task <ActionResult> ToggleWhitelist(int id)
        {
            var b = await LinksService.GetQuery(m => m.Id == id).UpdateFromQueryAsync(m => new Links()
            {
                Except = !m.Except
            }) > 0;

            return(ResultData(null, b, b ? "切换成功!" : "切换失败!"));
        }
コード例 #4
0
        public async Task <ActionResult> Edit(Links model)
        {
            var b = await LinksService.GetQuery(m => m.Id == model.Id).UpdateFromQueryAsync(m => new Links()
            {
                Name = model.Name,
                Url  = model.Url
            }) > 0;

            return(ResultData(null, b, b ? "保存成功" : "保存失败"));
        }
コード例 #5
0
 /// <summary>在调用操作方法后调用。</summary>
 /// <param name="filterContext">有关当前请求和操作的信息。</param>
 public override void OnActionExecuted(ActionExecutedContext filterContext)
 {
     if (filterContext.Result is ViewResult)
     {
         ViewBag.menus = MenuService.GetQueryFromCache(m => m.ParentId == null && m.Status == Status.Available).OrderBy(m => m.Sort).ToList(); //菜单
         var model = new PageFootViewModel                                                                                                     //页脚
         {
             Links = LinksService.GetQuery(l => l.Status == Status.Available).OrderByDescending(l => l.Recommend).ThenByDescending(l => l.Loopbacks.Count).Take(30).ProjectTo <LinksDto>(MapperConfig).Cacheable().ToList()
         };
         ViewBag.Footer = model;
     }
 }
コード例 #6
0
        /// <summary>在调用操作方法后调用。</summary>
        /// <param name="filterContext">有关当前请求和操作的信息。</param>
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            base.OnActionExecuted(filterContext);
            if (filterContext.HttpContext.Request.Method.Equals("POST", StringComparison.InvariantCultureIgnoreCase))
            {
                if (filterContext.Result is ViewResult)
                {
                    filterContext.Result = ResultData(null, false, "该URL仅支持Get请求方式", false, HttpStatusCode.MethodNotAllowed);
                }
                return;
            }

            #region 准备页面数据模型

            ViewBag.menus = MenuService.GetQueryFromCache <MenuOutputDto>(m => m.Status == Status.Available).OrderBy(m => m.Sort).ToList(); //菜单
            PageFootViewModel model = new PageFootViewModel                                                                                 //页脚
            {
                Links = LinksService.GetQuery(l => l.Status == Status.Available, l => l.Recommend, false).ThenByDescending(l => l.Weight).ThenByDescending(l => new Random().Next()).Take(40).ProjectTo <LinksOutputDto>(MapperConfig).Cacheable().ToList()
            };
            ViewBag.Footer = model;

            #endregion
        }