|
5 | 5 | using System.Linq;
|
6 | 6 | using System.Linq.Expressions;
|
7 | 7 | using System.Reflection;
|
| 8 | +using System.Web; |
8 | 9 | using System.Web.Helpers;
|
9 | 10 | using System.Web.Mvc;
|
10 | 11 |
|
11 | 12 | namespace Griddly.Mvc
|
12 | 13 | {
|
13 | 14 | public abstract class GriddlyResult : ActionResult
|
14 | 15 | {
|
| 16 | + public SortField[] GetSortFields(NameValueCollection items) |
| 17 | + { |
| 18 | + return items.AllKeys |
| 19 | + .Where(x => x.StartsWith("sortFields[")) |
| 20 | + .Select(x => |
| 21 | + { |
| 22 | + int pos = x.IndexOf(']', "sortFields[".Length); |
15 | 23 |
|
| 24 | + return new |
| 25 | + { |
| 26 | + Index = int.Parse(x.Substring("sortFields[".Length, pos - "sortFields[".Length)), |
| 27 | + Field = x.Substring(pos + 2, x.Length - pos - 2 - 1), |
| 28 | + Direction = (SortDirection)Enum.Parse(typeof(SortDirection), items[x]) |
| 29 | + }; |
| 30 | + |
| 31 | + }) |
| 32 | + .OrderBy(x => x.Index) |
| 33 | + .Select(x => new SortField() |
| 34 | + { |
| 35 | + Field = x.Field, |
| 36 | + Direction = x.Direction |
| 37 | + }) |
| 38 | + .ToArray(); |
| 39 | + } |
16 | 40 | }
|
17 | 41 |
|
18 | 42 | public class GriddlyResult<T> : GriddlyResult
|
@@ -41,34 +65,16 @@ public override void ExecuteResult(ControllerContext context)
|
41 | 65 |
|
42 | 66 | if (!int.TryParse(items["pageNumber"], out pageNumber))
|
43 | 67 | pageNumber = 0;
|
| 68 | + |
44 | 69 | if (!int.TryParse(items["pageSize"], out pageSize))
|
45 | 70 | pageSize = 20;
|
| 71 | + |
46 | 72 | if (Enum.TryParse(items["exportFormat"], true, out exportFormatValue))
|
47 | 73 | exportFormat = exportFormatValue;
|
48 | 74 | else
|
49 | 75 | exportFormat = null;
|
50 | 76 |
|
51 |
| - sortFields = items.AllKeys |
52 |
| - .Where(x => x.StartsWith("sortFields[")) |
53 |
| - .Select(x => |
54 |
| - { |
55 |
| - int pos = x.IndexOf(']', "sortFields[".Length); |
56 |
| - |
57 |
| - return new |
58 |
| - { |
59 |
| - Index = int.Parse(x.Substring("sortFields[".Length, pos - "sortFields[".Length)), |
60 |
| - Field = x.Substring(pos + 2, x.Length - pos - 2 - 1), |
61 |
| - Direction = (SortDirection)Enum.Parse(typeof(SortDirection), items[x]) |
62 |
| - }; |
63 |
| - |
64 |
| - }) |
65 |
| - .OrderBy(x => x.Index) |
66 |
| - .Select(x => new SortField() |
67 |
| - { |
68 |
| - Field = x.Field, |
69 |
| - Direction = x.Direction |
70 |
| - }) |
71 |
| - .ToArray(); |
| 77 | + sortFields = GetSortFields(items); |
72 | 78 |
|
73 | 79 | GriddlySettings settings = null;
|
74 | 80 |
|
|
0 commit comments