diff --git a/WebStoreCoreApplication/Controler/BaseController.cs b/WebStoreCoreApplication/Controler/BaseController.cs deleted file mode 100644 index 576ac85..0000000 --- a/WebStoreCoreApplication/Controler/BaseController.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; - -namespace WebStoreCoreApplication.Controler -{ - public class BaseController : Controller - { - public IActionResult Index() - { - return View(); - } - } -} \ No newline at end of file diff --git a/WebStoreCoreApplication/Controllers/BaseController.cs b/WebStoreCoreApplication/Controllers/BaseController.cs new file mode 100644 index 0000000..096b6b1 --- /dev/null +++ b/WebStoreCoreApplication/Controllers/BaseController.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Cache; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using WebStoreCoreApplication.ViewModels; + +namespace WebStoreCoreApplication.Controllers +{ + public class BaseController : Controller + { + private readonly List _employees = new List + { + new EmployeeViewModel + { + Id = 1, + Name = "Петр", + SName = "Петров", + FName = "Петрович", + Age = 33, + Position ="BOSS" + }, + new EmployeeViewModel + { + Id = 2, + Name = "Фёдр", + SName = "Фёдоров", + FName = "Фёдорович", + Age = 25, + Position ="Программист"} + }; + public IActionResult Index() + { + return View(); + } + + public IActionResult Employees() + { + return View(_employees); + } + + public IActionResult EmployeeDetails(int id) + { + var employeeviewmodel = _employees.FirstOrDefault(x => x.Id == id); + if (employeeviewmodel == null) return NotFound(); + return View(employeeviewmodel); + } + } +} \ No newline at end of file diff --git a/WebStoreCoreApplication/Startup.cs b/WebStoreCoreApplication/Startup.cs index eb1b1a0..16e1861 100644 --- a/WebStoreCoreApplication/Startup.cs +++ b/WebStoreCoreApplication/Startup.cs @@ -14,10 +14,15 @@ namespace WebStoreCoreApplication public class Startup { private readonly IConfiguration _configuration; + public Startup(IConfiguration configuration) + { + _configuration = configuration; + } // This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { + services.AddMvc(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. @@ -35,8 +40,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( - name: "Indes", - pattern: "New") ; + name: "default", + pattern: "{controller=Base}/{action=Index}/{id?}"); endpoints.MapGet("/", async context => { await context.Response.WriteAsync(hello); diff --git a/WebStoreCoreApplication/ViewModels/EmployeeViewModel.cs b/WebStoreCoreApplication/ViewModels/EmployeeViewModel.cs new file mode 100644 index 0000000..2b563d1 --- /dev/null +++ b/WebStoreCoreApplication/ViewModels/EmployeeViewModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace WebStoreCoreApplication.ViewModels +{ + public class EmployeeViewModel + { + public int Id { get; set; } + public string Name { get; set;} + public string SName { get; set;} + public string FName { get; set;} + public int Age { get; set;} + public string Position { get; set;} + } +} diff --git a/WebStoreCoreApplication/Views/Base/EmployeeDetails.cshtml b/WebStoreCoreApplication/Views/Base/EmployeeDetails.cshtml new file mode 100644 index 0000000..fe887aa --- /dev/null +++ b/WebStoreCoreApplication/Views/Base/EmployeeDetails.cshtml @@ -0,0 +1,44 @@ +@model WebStoreCoreApplication.ViewModels.EmployeeViewModel +@{ + Layout = null; +} + + + + + + + EmployeeDetails + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ID@Model.Id
Имя@Model.Name
Фамилия@Model.SName
Отчество@Model.FName
Возраст@Model.Age
Должность@Model.Position
+ @Html.ActionLink("К списку", "Employees", new {}) +
+ + diff --git a/WebStoreCoreApplication/Views/Base/Employees.cshtml b/WebStoreCoreApplication/Views/Base/Employees.cshtml new file mode 100644 index 0000000..3925bb3 --- /dev/null +++ b/WebStoreCoreApplication/Views/Base/Employees.cshtml @@ -0,0 +1,29 @@ +@model IEnumerable + +@{ + Layout = null; +} + + + + + + + Employees + + + + @foreach (var item in Model) + { + + + + + + + } +
@item.Name@item.SName@item.FName + @Html.ActionLink("Детали", "EmployeeDetails", new { id=item.Id}) +
+ + diff --git a/WebStoreCoreApplication/Views/Base/Index.cshtml b/WebStoreCoreApplication/Views/Base/Index.cshtml new file mode 100644 index 0000000..4d77038 --- /dev/null +++ b/WebStoreCoreApplication/Views/Base/Index.cshtml @@ -0,0 +1,17 @@ + +@{ + Layout = null; +} + + + + + + + Index + + + +

Привет от вью

+ + diff --git a/WebStoreCoreApplication/appsettings.Production.json b/WebStoreCoreApplication/appsettings.Production.json new file mode 100644 index 0000000..8983e0f --- /dev/null +++ b/WebStoreCoreApplication/appsettings.Production.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +}