コード例 #1
0
        public ActionResult GetArticleTable_getItems()
        {
            var parameters = AjaxModel.GetParameters(HttpContext);
            var art        = new ArticleManager();
            var acim       = new ArticleCatalogImagesManager();

            var items = art.GetItems().AsQueryable();

            #region filter
            if (parameters.filter != null && parameters.filter.Count > 0)
            {
                List <int?> td = new List <int?>();
                if (parameters.filter.ContainsKey("typeID"))
                {
                    td = (parameters.filter["typeID"] as ArrayList).ToArray().Select(x => (int?)RDL.Convert.StrToInt(x.ToString(), 0)).ToList();
                }
                items = items.Where(x => (td.Count == 0 || td.Contains(x.typeID != null ? x.typeID : 0)));
            }
            #endregion

            var sorts      = parameters.sort.Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries);
            var directions = parameters.direction.Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries);
            var sort1      = sorts.Length > 0 ? sorts[0] : "";
            var direction1 = directions.Length > 0 ? directions[0] : "";

            switch (sort1)
            {
            case "created":
                if (direction1 == "up")
                {
                    items = items.OrderBy(x => x.created);
                }
                else
                {
                    items = items.OrderByDescending(x => x.created);
                }
                break;

            case "title":
                if (direction1 == "up")
                {
                    items = items.OrderBy(x => x.title);
                }
                else
                {
                    items = items.OrderByDescending(x => x.title);
                }
                break;

            default:
                if (direction1 == "up")
                {
                    items = items.OrderBy(x => x.created);
                }
                else
                {
                    items = items.OrderByDescending(x => x.created);
                }
                break;
            }

            var total  = items.Count();
            var res    = items.Skip(parameters.pageSize * (parameters.page - 1)).Take(parameters.pageSize).ToList();
            var imgUrl = new FileItemInfo1();

            return(Json(new
            {
                items = res.Select(x => new
                {
                    x.id,
                    created = x.created.GetValueOrDefault().ToString("dd.MM.yyyy"),
                    x.title,
                    imgPath = (imgUrl = Files.GetTargetFiles(x.id, "/uploads/Images/Articles/").Where(s => s.Name.Contains("_mini")).FirstOrDefault()) == null
                        ? "<div class='myUsUploadImage' data-imgPath=''></div>"
                        : String.Format("<div class='myUsUploadImage' data-imgPath='" + "/uploads/Images/Articles/" + x.id + "/" + imgUrl.Name + "'></div>"),
                    x.anouns,
                    x.text,
                    typeID = x.typeID != null ? art.GetItemType((int)x.typeID).name : "",
                }),
                total = items.Count()
            }, JsonRequestBehavior.AllowGet));
        }
コード例 #2
0
        public ActionResult GetArticleTypeTable_getItems()
        {
            var parameters = AjaxModel.GetParameters(HttpContext);
            var art        = new ArticleManager();
            var acim       = new ArticleCatalogImagesManager();

            var items = art.GetItemsType().AsQueryable();

            //#region filter
            //if (parameters.filter != null && parameters.filter.Count > 0)
            //{
            //    List<int?> td = new List<int?>();
            //    if (parameters.filter.ContainsKey("typeID"))
            //    {
            //        td = (parameters.filter["typeID"] as ArrayList).ToArray().Select(x => (int?)RDL.Convert.StrToInt(x.ToString(), 0)).ToList();
            //    }
            //    items = items.Where(x => (td.Count == 0 || td.Contains(x.typeID != null ? x.typeID : 0)));
            //}
            //#endregion

            var sorts      = parameters.sort.Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries);
            var directions = parameters.direction.Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries);
            var sort1      = sorts.Length > 0 ? sorts[0] : "";
            var direction1 = directions.Length > 0 ? directions[0] : "";

            switch (sort1)
            {
            case "name":
                if (direction1 == "up")
                {
                    items = items.OrderBy(x => x.name);
                }
                else
                {
                    items = items.OrderByDescending(x => x.name);
                }
                break;

            case "code":
                if (direction1 == "up")
                {
                    items = items.OrderBy(x => x.code);
                }
                else
                {
                    items = items.OrderByDescending(x => x.code);
                }
                break;

            default:
                if (direction1 == "up")
                {
                    items = items.OrderBy(x => x.code);
                }
                else
                {
                    items = items.OrderByDescending(x => x.code);
                }
                break;
            }

            var total  = items.Count();
            var res    = items.Skip(parameters.pageSize * (parameters.page - 1)).Take(parameters.pageSize).ToList();
            var imgUrl = new FileItemInfo1();

            return(Json(new
            {
                items = res.Select(x => new
                {
                    x.id,
                    x.name,
                    x.code,
                }),
                total = items.Count()
            }, JsonRequestBehavior.AllowGet));
        }