1- using System ;
2- using System . Collections . Generic ;
3- using System . Configuration ;
4- using System . Net . Http ;
5- using System . Threading . Tasks ;
6- using System . Web . Mvc ;
7- using OneTrueError . App . Configuration ;
8- using OneTrueError . Infrastructure ;
9- using OneTrueError . Infrastructure . Configuration ;
10- using OneTrueError . Web . Areas . Installation . Models ;
11-
12- namespace OneTrueError . Web . Areas . Installation . Controllers
13- {
14- public class SetupController : Controller
15- {
16- [ HttpPost , AllowAnonymous ]
17- public ActionResult Activate ( )
18- {
19- ConfigurationManager . RefreshSection ( "appSettings" ) ;
20- if ( ConfigurationManager . AppSettings [ "Configured" ] != "true" )
21- {
22- return RedirectToAction ( "Completed" , new
23- {
24- displayError = 1
25- } ) ;
26- }
27- return Redirect ( "~/?#/welcome" ) ;
28- }
29-
30- public ActionResult Support ( )
31- {
32- return View ( new SupportViewModel ( ) ) ;
33- }
34-
35- [ HttpPost ]
36- public async Task < ActionResult > Support ( SupportViewModel model )
37- {
38- if ( ! ModelState . IsValid )
39- return View ( model ) ;
40-
41- try
42- {
43- var client = new HttpClient ( ) ;
44- var content =
45- new FormUrlEncodedContent ( new [ ]
46- {
47- new KeyValuePair < string , string > ( "EmailAddress" , model . Email ) ,
48- new KeyValuePair < string , string > ( "CompanyName" , model . CompanyName )
49- } ) ;
50- await client . PostAsync ( "https://onetrueerror.com/support/register/" , content ) ;
51- return Redirect ( Url . GetNextWizardStep ( ) ) ;
52- }
53- catch ( Exception ex )
54- {
55- ModelState . AddModelError ( "" , ex . Message ) ;
56- return View ( model ) ;
57- }
58- }
59-
60- public ActionResult Basics ( )
61- {
62- var model = new BasicsViewModel ( ) ;
63- var config = ConfigurationStore . Instance . Load < BaseConfiguration > ( ) ;
64- if ( config != null )
65- {
66- model . BaseUrl = config . BaseUrl . ToString ( ) ;
67- model . SupportEmail = config . SupportEmail ;
68- }
69- else
70- {
71- model . BaseUrl = Request . Url . ToString ( ) . Replace ( "installation/setup/basics/" , "" ) . Replace ( "localhost" , "yourServerName" ) ;
72- ViewBag . NextLink = "" ;
73- }
74-
75-
76- return View ( model ) ;
77- }
78-
79- [ HttpPost ]
80- public ActionResult Basics ( BasicsViewModel model )
81- {
82- var settings = new BaseConfiguration ( ) ;
83- if ( ! model . BaseUrl . EndsWith ( "/" ) )
84- model . BaseUrl += "/" ;
85-
86- if ( model . BaseUrl . IndexOf ( "localhost" , StringComparison . OrdinalIgnoreCase ) != - 1 )
87- {
88- ModelState . AddModelError ( "BaseUrl" , "Use the servers real DNS name instead of 'localhost'. If you don't the Ajax request wont work as CORS would be enforced by IIS." ) ;
89- return View ( model ) ;
90- }
91- settings . BaseUrl = new Uri ( model . BaseUrl ) ;
92- settings . SupportEmail = model . SupportEmail ;
93- ConfigurationStore . Instance . Store ( settings ) ;
94- return Redirect ( Url . GetNextWizardStep ( ) ) ;
95- }
96-
97-
98- public ActionResult Completed ( string displayError = null )
99- {
100- ViewBag . DisplayError = displayError == "1" ;
101- return View ( ) ;
102- }
103-
104- public ActionResult Errors ( )
105- {
106- var model = new ErrorTrackingViewModel ( ) ;
107- var config = ConfigurationStore . Instance . Load < OneTrueErrorConfigSection > ( ) ;
108- if ( config != null )
109- {
110- model . ActivateTracking = config . ActivateTracking ;
111- model . ContactEmail = config . ContactEmail ;
112- model . InstallationId = config . InstallationId ;
113- }
114- else
115- ViewBag . NextLink = "" ;
116-
117- return View ( "ErrorTracking" , model ) ;
118- }
119-
120- [ HttpPost ]
121- public ActionResult Errors ( ErrorTrackingViewModel model )
122- {
123- if ( ! ModelState . IsValid )
124- return View ( "ErrorTracking" , model ) ;
125-
126- var settings = new OneTrueErrorConfigSection ( ) ;
127- settings . ActivateTracking = model . ActivateTracking ;
128- settings . ContactEmail = model . ContactEmail ;
129- settings . InstallationId = model . InstallationId ;
130- ConfigurationStore . Instance . Store ( settings ) ;
131- return Redirect ( Url . GetNextWizardStep ( ) ) ;
132- }
133-
134- // GET: Installation/Home
135- public ActionResult Index ( )
136- {
137- try
138- {
139- ConnectionFactory . Create ( ) ;
140- }
141- catch
142- {
143- ViewBag . Ready = false ;
144- }
145- return View ( ) ;
146- }
147-
148- protected override void OnActionExecuting ( ActionExecutingContext filterContext )
149- {
150- ViewBag . PrevLink = Url . GetPreviousWizardStepLink ( ) ;
151- ViewBag . NextLink = Url . GetNextWizardStepLink ( ) ;
152- base . OnActionExecuting ( filterContext ) ;
153- }
154- }
1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Configuration ;
4+ using System . Net . Http ;
5+ using System . Threading . Tasks ;
6+ using System . Web . Mvc ;
7+ using OneTrueError . App . Configuration ;
8+ using OneTrueError . Infrastructure ;
9+ using OneTrueError . Infrastructure . Configuration ;
10+ using OneTrueError . Web . Areas . Installation . Models ;
11+
12+ namespace OneTrueError . Web . Areas . Installation . Controllers
13+ {
14+ public class SetupController : Controller
15+ {
16+ [ HttpPost , AllowAnonymous ]
17+ public ActionResult Activate ( )
18+ {
19+ ConfigurationManager . RefreshSection ( "appSettings" ) ;
20+ if ( ConfigurationManager . AppSettings [ "Configured" ] != "true" )
21+ {
22+ return RedirectToAction ( "Completed" , new
23+ {
24+ displayError = 1
25+ } ) ;
26+ }
27+ return Redirect ( "~/?#/welcome" ) ;
28+ }
29+
30+ public ActionResult Support ( )
31+ {
32+ return View ( new SupportViewModel ( ) ) ;
33+ }
34+
35+ [ HttpPost ]
36+ public async Task < ActionResult > Support ( SupportViewModel model )
37+ {
38+ if ( ! ModelState . IsValid )
39+ return View ( model ) ;
40+
41+ try
42+ {
43+ var client = new HttpClient ( ) ;
44+ var content =
45+ new FormUrlEncodedContent ( new [ ]
46+ {
47+ new KeyValuePair < string , string > ( "EmailAddress" , model . Email ) ,
48+ new KeyValuePair < string , string > ( "CompanyName" , model . CompanyName )
49+ } ) ;
50+ await client . PostAsync ( "https://onetrueerror.com/support/register/" , content ) ;
51+ return Redirect ( Url . GetNextWizardStep ( ) ) ;
52+ }
53+ catch ( Exception ex )
54+ {
55+ ModelState . AddModelError ( "" , ex . Message ) ;
56+ return View ( model ) ;
57+ }
58+ }
59+
60+ public ActionResult Basics ( )
61+ {
62+ var model = new BasicsViewModel ( ) ;
63+ var config = ConfigurationStore . Instance . Load < BaseConfiguration > ( ) ;
64+ if ( config != null )
65+ {
66+ model . BaseUrl = config . BaseUrl . ToString ( ) ;
67+ model . SupportEmail = config . SupportEmail ;
68+ }
69+ else
70+ {
71+ model . BaseUrl = Request . Url . ToString ( ) . Replace ( "installation/setup/basics/" , "" ) . Replace ( "localhost" , "yourServerName" ) ;
72+ ViewBag . NextLink = "" ;
73+ }
74+
75+
76+ return View ( model ) ;
77+ }
78+
79+ [ HttpPost ]
80+ public ActionResult Basics ( BasicsViewModel model )
81+ {
82+ var settings = new BaseConfiguration ( ) ;
83+ if ( ! model . BaseUrl . EndsWith ( "/" ) )
84+ model . BaseUrl += "/" ;
85+
86+ if ( model . BaseUrl . IndexOf ( "localhost" , StringComparison . OrdinalIgnoreCase ) != - 1 )
87+ {
88+ ModelState . AddModelError ( "BaseUrl" , "Use the servers real DNS name instead of 'localhost'. If you don't the Ajax request wont work as CORS would be enforced by IIS." ) ;
89+ return View ( model ) ;
90+ }
91+ settings . BaseUrl = new Uri ( model . BaseUrl ) ;
92+ settings . SupportEmail = model . SupportEmail ;
93+ ConfigurationStore . Instance . Store ( settings ) ;
94+ return Redirect ( Url . GetNextWizardStep ( ) ) ;
95+ }
96+
97+
98+ public ActionResult Completed ( string displayError = null )
99+ {
100+ ViewBag . DisplayError = displayError == "1" ;
101+ return View ( ) ;
102+ }
103+
104+ public ActionResult Errors ( )
105+ {
106+ var model = new ErrorTrackingViewModel ( ) ;
107+ var config = ConfigurationStore . Instance . Load < OneTrueErrorConfigSection > ( ) ;
108+ if ( config != null )
109+ {
110+ model . ActivateTracking = config . ActivateTracking ;
111+ model . ContactEmail = config . ContactEmail ;
112+ model . InstallationId = config . InstallationId ;
113+ }
114+ else
115+ ViewBag . NextLink = "" ;
116+
117+ return View ( "ErrorTracking" , model ) ;
118+ }
119+
120+ [ HttpPost ]
121+ public ActionResult Errors ( ErrorTrackingViewModel model )
122+ {
123+ if ( ! ModelState . IsValid )
124+ return View ( "ErrorTracking" , model ) ;
125+
126+ var settings = new OneTrueErrorConfigSection ( ) ;
127+ settings . ActivateTracking = model . ActivateTracking ;
128+ settings . ContactEmail = model . ContactEmail ;
129+ settings . InstallationId = model . InstallationId ;
130+ ConfigurationStore . Instance . Store ( settings ) ;
131+ return Redirect ( Url . GetNextWizardStep ( ) ) ;
132+ }
133+
134+ // GET: Installation/Home
135+ public ActionResult Index ( )
136+ {
137+ try
138+ {
139+ ConnectionFactory . Create ( ) ;
140+ }
141+ catch
142+ {
143+ ViewBag . Ready = false ;
144+ }
145+ return View ( ) ;
146+ }
147+
148+ protected override void OnActionExecuting ( ActionExecutingContext filterContext )
149+ {
150+ ViewBag . PrevLink = Url . GetPreviousWizardStepLink ( ) ;
151+ ViewBag . NextLink = Url . GetNextWizardStepLink ( ) ;
152+ base . OnActionExecuting ( filterContext ) ;
153+ }
154+ }
155155}
0 commit comments