1+ using Faker ;
2+ using Griddly . Models ;
3+ using Microsoft . AspNetCore . Mvc ;
4+ using System ;
5+ using System . Collections . Generic ;
6+ using System . Linq ;
7+
8+ namespace Griddly . Controllers
9+ {
10+ public partial class ExampleController : Controller
11+ {
12+ public IActionResult Columns ( )
13+ {
14+ return View ( "Example" , new ExampleModel ( _env )
15+ {
16+ Title = "Columns Example" ,
17+ GridAction = "ColumnsGrid" ,
18+ ParentView = "Columns.cshtml" ,
19+ GridView = "ColumnsGrid.cshtml" ,
20+ Description = "Griddly column helpers offer several ways to quickly define your table structure."
21+ } ) ;
22+ }
23+
24+ public IActionResult Buttons ( string lastName = null )
25+ {
26+ ViewBag . LastName = lastName ;
27+
28+ return View ( "Example" , new ExampleModel ( _env )
29+ {
30+ Title = "Buttons Example" ,
31+ GridAction = "ButtonsGrid" ,
32+ ParentView = "Buttons.cshtml" ,
33+ GridView = "ButtonsGrid.cshtml" ,
34+ Description = ""
35+ } ) ;
36+ }
37+
38+ public IActionResult Filters ( )
39+ {
40+ return View ( "Example" , new ExampleModel ( _env )
41+ {
42+ Title = "Filters Example" ,
43+ GridAction = "FiltersGrid" ,
44+ ParentView = "Filters.cshtml" ,
45+ GridView = "FiltersGrid.cshtml" ,
46+ Description = "There are several filter helpers built into Griddly. Click the \" Filter\" button to play with these."
47+ } ) ;
48+ }
49+
50+ public IActionResult FilterDefaults ( )
51+ {
52+ return View ( "Example" , new ExampleModel ( _env )
53+ {
54+ Title = "Filter Defaults Example" ,
55+ GridAction = "FilterDefaultsGrid" ,
56+ ParentView = "FilterDefaults.cshtml" ,
57+ GridView = "FilterDefaultsGrid.cshtml" ,
58+ Description = "Filter default values may be set using the ControllerBase.SetGriddlyDefault() extension method."
59+ } ) ;
60+ }
61+
62+ public IActionResult Parameters ( )
63+ {
64+ return View ( "Example" , new ExampleModel ( _env )
65+ {
66+ Title = "Additional Parameters Example" ,
67+ GridAction = "ParametersGrid" ,
68+ ParentView = "Parameters.cshtml" ,
69+ GridView = "ParametersGrid.cshtml" ,
70+ Description = "Non-filter parameters may be passed from the parent view to the grid action on every refresh request."
71+ } ) ;
72+ }
73+
74+ #region Test Data
75+
76+ static readonly IList < TestGridItem > _testData = BuildTestData ( ) ;
77+
78+ static List < TestGridItem > BuildTestData ( int rows = 1000 )
79+ {
80+ List < TestGridItem > items = new List < TestGridItem > ( ) ;
81+ Random r = new Random ( ) ;
82+
83+ for ( int i = 0 ; i < rows ; i ++ )
84+ {
85+ items . Add ( new TestGridItem ( )
86+ {
87+ Id = ( long ) i ,
88+ FirstName = Name . First ( ) ,
89+ LastName = Name . Last ( ) ,
90+ Company = Company . Name ( ) ,
91+ Address = r . Next ( short . MaxValue ) + " " + Address . StreetName ( ) ,
92+ City = Address . City ( ) ,
93+ State = Address . UsState ( ) ,
94+ PostalCode = Address . ZipCode ( ) ,
95+ Quantity = 1 + r . Next ( 10 ) ,
96+ Total = 1 + ( decimal ) ( r . NextDouble ( ) * 10000 ) ,
97+ IsApproved = r . Next ( 10 ) > 3 ,
98+ Date = GetRandomDate ( r , DateTime . Today . AddYears ( - 10 ) , DateTime . Today . AddYears ( 10 ) ) ,
99+ Item = "Item" + ( 1 + r . Next ( 9 ) ) ,
100+
101+ Test = ( decimal ) ( r . NextDouble ( ) * 10000 ) ,
102+ NullThing = ( string ) null ,
103+ } ) ;
104+ }
105+
106+ return items ;
107+ }
108+
109+ static DateTime GetRandomDate ( Random r , DateTime from , DateTime to )
110+ {
111+ var range = to - from ;
112+
113+ var randTimeSpan = new TimeSpan ( ( long ) ( r . NextDouble ( ) * range . Ticks ) ) ;
114+
115+ return from + randTimeSpan ;
116+ }
117+
118+ #endregion
119+ }
120+ }
0 commit comments