Example #1
0
        public ActionResult GetItems()
        {
            var parameters = AjaxModel.GetParameters(HttpContext);
            var msg        = "";

            var items = mng.GetAllTemplates(out msg);

            if (parameters.filter != null && parameters.filter.Count > 0)
            {
                var code = parameters.filter.ContainsKey("code") ? parameters.filter["code"].ToString() : "";

                items = items.Where(x => x.code.Contains(code));
            }

            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 "from":
                if (direction1 == "up")
                {
                    items = items.OrderBy(x => x.code);
                }
                else
                {
                    items = items.OrderByDescending(x => x.code);
                }
                break;

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

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

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

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

            default:
            case "code":
                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();


            return(Json(new
            {
                result = items == null,
                items = res,
                total,
                msg
            }));
        }