-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathHomeController.cs
More file actions
80 lines (62 loc) · 2.01 KB
/
HomeController.cs
File metadata and controls
80 lines (62 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using JavaScriptEngineSwitcher.Sample.Logic.Models;
using JavaScriptEngineSwitcher.Sample.Logic.Services;
namespace JavaScriptEngineSwitcher.Sample.AspNetCore1Full.Mvc1.Controllers
{
public class HomeController : Controller
{
private readonly FileContentService _fileContentService;
private readonly JsEvaluationService _jsEvaluationService;
public HomeController(
IConfigurationRoot configuration,
IHostingEnvironment hostingEnvironment,
JsEvaluationService jsEvaluationService)
{
string textContentDirectoryPath = configuration
.GetSection("jsengineswitcher")
.GetSection("Samples")["TextContentDirectoryPath"]
;
_fileContentService = new FileContentService(textContentDirectoryPath, hostingEnvironment);
_jsEvaluationService = jsEvaluationService;
}
[ResponseCache(CacheProfileName = "CacheCompressedContent5Minutes")]
public IActionResult Index()
{
ViewBag.Body = new HtmlString(_fileContentService.GetFileContent("index.html"));
return View();
}
[HttpGet]
[ResponseCache(CacheProfileName = "CacheCompressedContent5Minutes")]
public IActionResult Demo()
{
var model = _jsEvaluationService.GetInitializationData();
return View(model);
}
[HttpPost]
public async Task<IActionResult> Demo(JsEvaluationViewModel editedModel)
{
var model = _jsEvaluationService.GetInitializationData();
await TryUpdateModelAsync(model, string.Empty, m => m.EngineName, m=> m.Expression);
if (ModelState.IsValid)
{
model = _jsEvaluationService.Evaluate(model);
ModelState.Clear();
}
return View(model);
}
[ResponseCache(CacheProfileName = "CacheCompressedContent5Minutes")]
public IActionResult Contact()
{
ViewBag.Body = new HtmlString(_fileContentService.GetFileContent("contact.html"));
return View();
}
public IActionResult Error()
{
return View();
}
}
}