Skip to content

Commit 0a0d765

Browse files
committed
Started MVC + React App
1 parent ac1a8b4 commit 0a0d765

26 files changed

+14624
-48
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,3 +286,5 @@ __pycache__/
286286
*.btm.cs
287287
*.odx.cs
288288
*.xsd.cs
289+
290+
node_modules

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"request": "launch",
1111
"preLaunchTask": "build",
1212
// If you have changed target frameworks, make sure to update the program path.
13-
"program": "${workspaceRoot}/bin/Debug/netcoreapp3.1/surveyjs-aspnet-mvc.dll",
13+
"program": "${workspaceRoot}/bin/Debug/net6.0/surveyjs-aspnet-mvc.dll",
1414
"args": [],
1515
"cwd": "${workspaceRoot}",
1616
"stopAtEntry": false,

Controllers/HomeController.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Diagnostics;
2+
using Microsoft.AspNetCore.Mvc;
3+
using surveyjs_aspnet_mvc.Models;
4+
5+
namespace surveyjs_aspnet_mvc.Controllers;
6+
7+
public class HomeController : Controller
8+
{
9+
private readonly ILogger<HomeController> _logger;
10+
11+
public HomeController(ILogger<HomeController> logger)
12+
{
13+
_logger = logger;
14+
}
15+
16+
public IActionResult Index()
17+
{
18+
return View();
19+
}
20+
21+
public IActionResult MySurveys()
22+
{
23+
return View();
24+
}
25+
26+
public IActionResult Privacy()
27+
{
28+
return View();
29+
}
30+
31+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
32+
public IActionResult Error()
33+
{
34+
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
35+
}
36+
}

Models/ErrorViewModel.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace surveyjs_aspnet_mvc.Models;
2+
3+
public class ErrorViewModel
4+
{
5+
public string? RequestId { get; set; }
6+
7+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
8+
}

Program.cs

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,32 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.IO;
4-
using System.Linq;
5-
using System.Threading.Tasks;
6-
using Microsoft.AspNetCore;
7-
using Microsoft.AspNetCore.Hosting;
8-
using Microsoft.Extensions.Configuration;
9-
using Microsoft.Extensions.Logging;
10-
11-
namespace surveyjs_aspnet_mvc
12-
{
13-
public class Program
14-
{
15-
public static void Main(string[] args)
16-
{
17-
BuildWebHost(args).Run();
18-
}
19-
20-
public static IWebHost BuildWebHost(string[] args) =>
21-
WebHost.CreateDefaultBuilder(args)
22-
.UseStartup<Startup>()
23-
.Build();
24-
}
1+
var builder = WebApplication.CreateBuilder(args);
2+
3+
// Add services to the container.
4+
builder.Services.AddControllersWithViews();
5+
6+
builder.Services.AddSession(options => {
7+
options.IdleTimeout = TimeSpan.FromMinutes(30);
8+
});
9+
10+
var app = builder.Build();
11+
12+
// Configure the HTTP request pipeline.
13+
if (!app.Environment.IsDevelopment()) {
14+
app.UseExceptionHandler("/Home/Error");
15+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
16+
app.UseHsts();
2517
}
18+
19+
app.UseHttpsRedirection();
20+
app.UseStaticFiles();
21+
22+
app.UseRouting();
23+
24+
app.UseAuthorization();
25+
26+
app.UseSession();
27+
28+
app.MapControllerRoute(
29+
name: "default",
30+
pattern: "{controller=Home}/{action=Index}/{id?}");
31+
32+
app.Run();

Views/Home/Index.cshtml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@{
2+
ViewData["Title"] = "Home Page";
3+
}
4+
5+
<div class="text-center">
6+
<h1 class="display-4">Welcome</h1>
7+
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
8+
</div>

Views/Home/MySurveys.cshtml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@{
2+
ViewData["Title"] = "My Surveys";
3+
}
4+
5+
<script defer="defer" src="~/static/js/main.7f897b90.js"></script>
6+
<link href="~/static/css/main.d6b899b4.css" rel="stylesheet">
7+
8+
<div class="text-center">
9+
<noscript>You need to enable JavaScript to run this app.</noscript>
10+
<h1 class="display-4">My Surveys</h1>
11+
<div id="root"></div>
12+
</div>

Views/Home/Privacy.cshtml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@{
2+
ViewData["Title"] = "Privacy Policy";
3+
}
4+
<h1>@ViewData["Title"]</h1>
5+
6+
<p>Use this page to detail your site's privacy policy.</p>

Views/Shared/Error.cshtml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@model ErrorViewModel
2+
@{
3+
ViewData["Title"] = "Error";
4+
}
5+
6+
<h1 class="text-danger">Error.</h1>
7+
<h2 class="text-danger">An error occurred while processing your request.</h2>
8+
9+
@if (Model.ShowRequestId)
10+
{
11+
<p>
12+
<strong>Request ID:</strong> <code>@Model.RequestId</code>
13+
</p>
14+
}
15+
16+
<h3>Development Mode</h3>
17+
<p>
18+
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
19+
</p>
20+
<p>
21+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
22+
It can result in displaying sensitive information from exceptions to end users.
23+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
24+
and restarting the app.
25+
</p>

Views/Shared/_Layout.cshtml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<link rel="icon" href="/favicon.ico" />
6+
<meta name="viewport" content="width=device-width,initial-scale=1" />
7+
<meta name="theme-color" content="#000000" />
8+
<meta name="description" content="SurveyJS service demo application with React/Redux" />
9+
<link rel="apple-touch-icon" href="/logo192.png" />
10+
<link rel="manifest" href="/manifest.json" />
11+
<title>@ViewData["Title"] - SurveyJS Service</title>
12+
<link rel="stylesheet" href="~/static/lib/bootstrap/dist/css/bootstrap.min.css" />
13+
<link rel="stylesheet" href="~/static/css/site.css" asp-append-version="true" />
14+
</head>
15+
<body>
16+
<header>
17+
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
18+
<div class="container-fluid">
19+
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">SurveyJS</a>
20+
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
21+
aria-expanded="false" aria-label="Toggle navigation">
22+
<span class="navbar-toggler-icon"></span>
23+
</button>
24+
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
25+
<ul class="navbar-nav flex-grow-1">
26+
<li class="nav-item">
27+
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
28+
</li>
29+
<li class="nav-item">
30+
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="MySurveys">My Surveys</a>
31+
</li>
32+
<li class="nav-item">
33+
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
34+
</li>
35+
</ul>
36+
</div>
37+
</div>
38+
</nav>
39+
</header>
40+
<div class="container">
41+
<main role="main" class="pb-3">
42+
@RenderBody()
43+
</main>
44+
</div>
45+
46+
<footer class="border-top footer text-muted">
47+
<div class="container">
48+
&copy; 2023 - SurveyJS - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
49+
</div>
50+
</footer>
51+
<script src="~/static/js/site.js" asp-append-version="true"></script>
52+
@await RenderSectionAsync("Scripts", required: false)
53+
</body>
54+
</html>

0 commit comments

Comments
 (0)