From 0ac51f8d1dd8a7108e9fefe664298d17754331c0 Mon Sep 17 00:00:00 2001 From: OlegBakulin Date: Fri, 16 Oct 2020 20:36:27 +0300 Subject: [PATCH 1/6] =?UTF-8?q?=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/BaseController.cs | 1 + .../Controllers/EmployeeController.cs | 36 +++++------ .../Infrastructure/EmployeeWork.cs | 23 +++++++ .../Interfaces/IEmployeeService.cs | 21 +++++++ .../Services/InMemoryEmployeeServices.cs | 61 +++++++++++++++++++ .../Infrastructure/SimpleActionFilter.cs | 22 +++++++ WebStoreCoreApplication/Startup.cs | 10 +++ 7 files changed, 152 insertions(+), 22 deletions(-) create mode 100644 WebStoreCoreApplication/Controllers/Infrastructure/EmployeeWork.cs create mode 100644 WebStoreCoreApplication/Controllers/Infrastructure/Interfaces/IEmployeeService.cs create mode 100644 WebStoreCoreApplication/Controllers/Infrastructure/Services/InMemoryEmployeeServices.cs create mode 100644 WebStoreCoreApplication/Controllers/Infrastructure/SimpleActionFilter.cs diff --git a/WebStoreCoreApplication/Controllers/BaseController.cs b/WebStoreCoreApplication/Controllers/BaseController.cs index 8d294da..8b32c72 100644 --- a/WebStoreCoreApplication/Controllers/BaseController.cs +++ b/WebStoreCoreApplication/Controllers/BaseController.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; +using WebStoreCoreApplication.Controllers.Infrastructure; namespace WebStoreCoreApplication.Controllers { diff --git a/WebStoreCoreApplication/Controllers/EmployeeController.cs b/WebStoreCoreApplication/Controllers/EmployeeController.cs index 55c3ce3..3a9bd47 100644 --- a/WebStoreCoreApplication/Controllers/EmployeeController.cs +++ b/WebStoreCoreApplication/Controllers/EmployeeController.cs @@ -4,45 +4,37 @@ using System.Net.Cache; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; +using WebStoreCoreApplication.Controllers.Infrastructure.Interfaces; using WebStoreCoreApplication.ViewModels; namespace WebStoreCoreApplication.Controllers { + [Route("peoples" + + "")] public class EmployeeController : Controller { - private readonly List _employees = new List + private readonly IEmployeeService employeeService; + + public EmployeeController(IEmployeeService employeeService) { - new EmployeeViewModel - { - Id = 1, - Name = "Петр", - SName = "Петров", - FName = "Петрович", - Age = 33, - Position ="BOSS" - }, - new EmployeeViewModel - { - Id = 2, - Name = "Фёдр", - SName = "Фёдоров", - FName = "Фёдорович", - Age = 25, - Position ="Программист"} - }; + this.employeeService = employeeService; + } + + [Route("idx")] public IActionResult Index() { return View(); } + [Route("all")] public IActionResult Employees() { - return View(_employees); + return View(employeeService.GetAll()); } - + [Route("{id}")] public IActionResult EmployeeDetails(int id) { - var employeeviewmodel = _employees.FirstOrDefault(x => x.Id == id); + var employeeviewmodel = employeeService.GetByID(id); if (employeeviewmodel == null) return NotFound(); return View(employeeviewmodel); } diff --git a/WebStoreCoreApplication/Controllers/Infrastructure/EmployeeWork.cs b/WebStoreCoreApplication/Controllers/Infrastructure/EmployeeWork.cs new file mode 100644 index 0000000..b412053 --- /dev/null +++ b/WebStoreCoreApplication/Controllers/Infrastructure/EmployeeWork.cs @@ -0,0 +1,23 @@ +using Microsoft.AspNetCore.Http; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace WebStoreCoreApplication.Controllers.Infrastructure +{ + public class EmployeeWork + { + public RequestDelegate Next { get; } + + public EmployeeWork(RequestDelegate next) + { + Next = next; + } + + public async Task InvokeAsync(HttpContext context) + { + + } + } +} diff --git a/WebStoreCoreApplication/Controllers/Infrastructure/Interfaces/IEmployeeService.cs b/WebStoreCoreApplication/Controllers/Infrastructure/Interfaces/IEmployeeService.cs new file mode 100644 index 0000000..1c63759 --- /dev/null +++ b/WebStoreCoreApplication/Controllers/Infrastructure/Interfaces/IEmployeeService.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using WebStoreCoreApplication.ViewModels; + +namespace WebStoreCoreApplication.Controllers.Infrastructure.Interfaces +{ + public interface IEmployeeService + { + IEnumerable GetAll(); + + EmployeeViewModel GetByID(int id); + + void Commit(); + + void AddNew(EmployeeViewModel newmodel); + + void Delete(int id); + } +} diff --git a/WebStoreCoreApplication/Controllers/Infrastructure/Services/InMemoryEmployeeServices.cs b/WebStoreCoreApplication/Controllers/Infrastructure/Services/InMemoryEmployeeServices.cs new file mode 100644 index 0000000..402d431 --- /dev/null +++ b/WebStoreCoreApplication/Controllers/Infrastructure/Services/InMemoryEmployeeServices.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using WebStoreCoreApplication.Controllers.Infrastructure.Interfaces; +using WebStoreCoreApplication.ViewModels; + +namespace WebStoreCoreApplication.Controllers.Infrastructure.Services +{ + public class InMemoryEmployeeServices : IEmployeeService + { + 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 void AddNew(EmployeeViewModel newmodel) + { + newmodel.Id = _employees.Max(e => e.Id) + 1; + _employees.Add(newmodel); + } + + public void Commit() + { + // + } + + public void Delete(int id) + { + var employee = GetByID(id); + if (employee is null) return; + _employees.Remove(employee); + } + + public IEnumerable GetAll() + { + return _employees; + } + + public EmployeeViewModel GetByID(int id) + { + return _employees.FirstOrDefault(e => e.Id.Equals(id)); + } + } +} diff --git a/WebStoreCoreApplication/Controllers/Infrastructure/SimpleActionFilter.cs b/WebStoreCoreApplication/Controllers/Infrastructure/SimpleActionFilter.cs new file mode 100644 index 0000000..afa2eed --- /dev/null +++ b/WebStoreCoreApplication/Controllers/Infrastructure/SimpleActionFilter.cs @@ -0,0 +1,22 @@ +using Microsoft.AspNetCore.Mvc.Filters; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace WebStoreCoreApplication.Controllers.Infrastructure +{ + public class SimpleActionFilter : Attribute, IActionFilter + { + public void OnActionExecuting(ActionExecutingContext context) + { + throw new NotImplementedException(); + } + + public void OnActionExecuted(ActionExecutedContext context) + { + throw new NotImplementedException(); + } + + } +} diff --git a/WebStoreCoreApplication/Startup.cs b/WebStoreCoreApplication/Startup.cs index e13d0da..a6a4f01 100644 --- a/WebStoreCoreApplication/Startup.cs +++ b/WebStoreCoreApplication/Startup.cs @@ -5,9 +5,13 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; +using Microsoft.CodeAnalysis.Options; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using WebStoreCoreApplication.Controllers.Infrastructure; +using WebStoreCoreApplication.Controllers.Infrastructure.Interfaces; +using WebStoreCoreApplication.Controllers.Infrastructure.Services; namespace WebStoreCoreApplication { @@ -23,6 +27,12 @@ public Startup(IConfiguration configuration) public void ConfigureServices(IServiceCollection services) { services.AddMvc(); + services.AddMvc(option => + { + option.Filters.Add(typeof(SimpleActionFilter)); + }); + + services.AddSingleton(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. From 7512d20b6c879a8ae6505b31f45607ce1bcefd03 Mon Sep 17 00:00:00 2001 From: OlegBakulin Date: Fri, 16 Oct 2020 23:03:50 +0300 Subject: [PATCH 2/6] =?UTF-8?q?=D0=A0=D0=B0=D0=B7=D0=B1=D0=BE=D1=80=D0=BA?= =?UTF-8?q?=D0=B0=20=D1=82=D0=BE=D0=BA=D0=B5=D0=BD=D0=BE=D0=B2=20=D0=B8=20?= =?UTF-8?q?=D0=BD=D0=B5=20=D0=BF=D0=BE=D0=BD=D0=B8=D0=BC=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BF=D0=BE=D1=87=D0=B5=D0=BC=D1=83=20=D0=BD=D0=B5=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B6=D0=B0=D0=B5=D1=82=D1=81?= =?UTF-8?q?=D1=8F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/BaseController.cs | 2 +- .../Controllers/EmployeeController.cs | 24 ++++++++++++----- .../Infrastructure/EmployeeWork.cs | 16 ++++++++++++ WebStoreCoreApplication/Startup.cs | 26 +++++++++++++++++++ .../Views/Base/Index.cshtml | 2 +- .../Base/{_404.cshtml => NotPage.cshtml} | 0 .../Views/Base/Partial/LeftBar.cshtml | 8 +++--- .../Views/Shared/Header/HeadBot.cshtml | 2 +- 8 files changed, 67 insertions(+), 13 deletions(-) rename WebStoreCoreApplication/Views/Base/{_404.cshtml => NotPage.cshtml} (100%) diff --git a/WebStoreCoreApplication/Controllers/BaseController.cs b/WebStoreCoreApplication/Controllers/BaseController.cs index 8b32c72..6d2daa5 100644 --- a/WebStoreCoreApplication/Controllers/BaseController.cs +++ b/WebStoreCoreApplication/Controllers/BaseController.cs @@ -14,7 +14,7 @@ public IActionResult Index() return View(); } - public IActionResult _404() + public IActionResult NotPage() { return View(); } diff --git a/WebStoreCoreApplication/Controllers/EmployeeController.cs b/WebStoreCoreApplication/Controllers/EmployeeController.cs index 3a9bd47..9abddd2 100644 --- a/WebStoreCoreApplication/Controllers/EmployeeController.cs +++ b/WebStoreCoreApplication/Controllers/EmployeeController.cs @@ -3,21 +3,21 @@ using System.Linq; using System.Net.Cache; using System.Threading.Tasks; +using AspNetCore; using Microsoft.AspNetCore.Mvc; using WebStoreCoreApplication.Controllers.Infrastructure.Interfaces; using WebStoreCoreApplication.ViewModels; namespace WebStoreCoreApplication.Controllers { - [Route("peoples" + - "")] + [Route("peoples")] public class EmployeeController : Controller { - private readonly IEmployeeService employeeService; + private readonly IEmployeeService _employeeService; public EmployeeController(IEmployeeService employeeService) { - this.employeeService = employeeService; + _employeeService = employeeService; } [Route("idx")] @@ -29,14 +29,26 @@ public IActionResult Index() [Route("all")] public IActionResult Employees() { - return View(employeeService.GetAll()); + return View(_employeeService.GetAll()); } [Route("{id}")] public IActionResult EmployeeDetails(int id) { - var employeeviewmodel = employeeService.GetByID(id); + var employeeviewmodel = _employeeService.GetByID(id); if (employeeviewmodel == null) return NotFound(); return View(employeeviewmodel); } + + [HttpGet] + [Route("edit/{id?}")] + public IActionResult Editor (int? id) + { + if (!id.HasValue) + return View(new EmployeeViewModel()); + var model = _employeeService.GetByID(id.Value); + if (model == null) + return NotFound(); + return View(model); + } } } \ No newline at end of file diff --git a/WebStoreCoreApplication/Controllers/Infrastructure/EmployeeWork.cs b/WebStoreCoreApplication/Controllers/Infrastructure/EmployeeWork.cs index b412053..640d12e 100644 --- a/WebStoreCoreApplication/Controllers/Infrastructure/EmployeeWork.cs +++ b/WebStoreCoreApplication/Controllers/Infrastructure/EmployeeWork.cs @@ -8,6 +8,7 @@ namespace WebStoreCoreApplication.Controllers.Infrastructure { public class EmployeeWork { + private const string correct = "1234"; public RequestDelegate Next { get; } public EmployeeWork(RequestDelegate next) @@ -17,7 +18,22 @@ public EmployeeWork(RequestDelegate next) public async Task InvokeAsync(HttpContext context) { + var token = context.Request.Query["token"]; + if (string.IsNullOrEmpty(token)) + { + await Next.Invoke(context); + return; + } + if (token == correct) + { + await Next.Invoke(context); + } + else + { + await context.Response.WriteAsync("BAAAADDDD!!!!"); + } } + } } diff --git a/WebStoreCoreApplication/Startup.cs b/WebStoreCoreApplication/Startup.cs index a6a4f01..eaa90d9 100644 --- a/WebStoreCoreApplication/Startup.cs +++ b/WebStoreCoreApplication/Startup.cs @@ -47,6 +47,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) var hello = _configuration["CustomeHelloWorld"]; + //app.Map("/Index", CustomIndexHandler); + app.UseRouting(); app.UseEndpoints(endpoints => @@ -62,6 +64,30 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) */ }); } + + private void CustomIndexHandler(IApplicationBuilder app) + { + app.Run(async context => + { + await context.Response.WriteAsync("Index Custom!!!"); + }); + } + + private void UseMiddlewareSample(IApplicationBuilder app) + { + app.Use(async (context, next) => + { + bool isError = false; + if (isError) + { + await context.Response.WriteAsync("Errrrrrrrooooooorrrrr!!!!"); + } + else + { + await next.Invoke(); + } + }); + } } } diff --git a/WebStoreCoreApplication/Views/Base/Index.cshtml b/WebStoreCoreApplication/Views/Base/Index.cshtml index cfb3d41..26dabfc 100644 --- a/WebStoreCoreApplication/Views/Base/Index.cshtml +++ b/WebStoreCoreApplication/Views/Base/Index.cshtml @@ -70,7 +70,7 @@
- @Html.Partial("Partial/LeftBar") + @await Html.PartialAsync("Partial/LeftBar")
diff --git a/WebStoreCoreApplication/Views/Base/_404.cshtml b/WebStoreCoreApplication/Views/Base/NotPage.cshtml similarity index 100% rename from WebStoreCoreApplication/Views/Base/_404.cshtml rename to WebStoreCoreApplication/Views/Base/NotPage.cshtml diff --git a/WebStoreCoreApplication/Views/Base/Partial/LeftBar.cshtml b/WebStoreCoreApplication/Views/Base/Partial/LeftBar.cshtml index d8aa391..49bd609 100644 --- a/WebStoreCoreApplication/Views/Base/Partial/LeftBar.cshtml +++ b/WebStoreCoreApplication/Views/Base/Partial/LeftBar.cshtml @@ -1,12 +1,12 @@ 
\ No newline at end of file diff --git a/WebStoreCoreApplication/Views/Shared/Header/HeadBot.cshtml b/WebStoreCoreApplication/Views/Shared/Header/HeadBot.cshtml index dd17490..c084f55 100644 --- a/WebStoreCoreApplication/Views/Shared/Header/HeadBot.cshtml +++ b/WebStoreCoreApplication/Views/Shared/Header/HeadBot.cshtml @@ -33,7 +33,7 @@
  • Blog Single
  • -
  • 404
  • +
  • 404
  • Contact
  • Employee
  • From 89d9c5c167ddfefdfcd7119daf2c7f00d23c1f62 Mon Sep 17 00:00:00 2001 From: OlegBakulin Date: Sat, 17 Oct 2020 20:29:08 +0300 Subject: [PATCH 3/6] =?UTF-8?q?=D0=9D=D0=B5=20=D0=BE=D1=82=D0=BE=D0=B1?= =?UTF-8?q?=D1=80=D0=B0=D0=B6=D0=B0=D0=B5=D0=BC=D0=B0=D1=8F=20=D0=BE=D1=88?= =?UTF-8?q?=D0=B8=D0=B1=D0=BA=D0=B0=20=D0=BD=D0=B5=20=D0=B8=D1=81=D1=87?= =?UTF-8?q?=D0=B5=D0=B7=D0=BB=D0=B0.=20=D0=90=D0=B2=D1=82=D0=BE=D1=81?= =?UTF-8?q?=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BF=D1=80=D0=B5?= =?UTF-8?q?=D0=B4=D1=81=D1=82=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D1=83=D1=85=D0=BE=D0=B4=D0=B8=D1=82=20=D0=B2=20=D0=BE=D1=88?= =?UTF-8?q?=D0=B8=D0=B1=D0=BA=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WebStoreCoreApplication.sln | 2 -- .../Controllers/BaseController.cs | 1 + .../Controllers/EmployeeController.cs | 13 ++++++++++--- .../Controllers/Infrastructure/EmployeeWork.cs | 4 ++-- .../Services/InMemoryEmployeeServices.cs | 4 +++- .../Infrastructure/SimpleActionFilter.cs | 6 ++++-- WebStoreCoreApplication/Startup.cs | 11 ++++++++--- .../ViewModels/EmployeeViewModel.cs | 4 ++-- .../Views/Employee/EmployeeDetails.cshtml | 6 +++--- .../Views/Employee/Employees.cshtml | 4 ++-- 10 files changed, 35 insertions(+), 20 deletions(-) diff --git a/WebStoreCoreApplication.sln b/WebStoreCoreApplication.sln index d68fbcf..03f594e 100644 --- a/WebStoreCoreApplication.sln +++ b/WebStoreCoreApplication.sln @@ -18,9 +18,7 @@ Global {581700BA-91A1-4244-A194-0EF45BB2C613}.Release|Any CPU.ActiveCfg = Release|Any CPU {581700BA-91A1-4244-A194-0EF45BB2C613}.Release|Any CPU.Build.0 = Release|Any CPU {A927D081-0956-4C16-8F5A-10F933B3A19B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A927D081-0956-4C16-8F5A-10F933B3A19B}.Debug|Any CPU.Build.0 = Debug|Any CPU {A927D081-0956-4C16-8F5A-10F933B3A19B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A927D081-0956-4C16-8F5A-10F933B3A19B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/WebStoreCoreApplication/Controllers/BaseController.cs b/WebStoreCoreApplication/Controllers/BaseController.cs index 6d2daa5..6d7a82f 100644 --- a/WebStoreCoreApplication/Controllers/BaseController.cs +++ b/WebStoreCoreApplication/Controllers/BaseController.cs @@ -9,6 +9,7 @@ namespace WebStoreCoreApplication.Controllers { public class BaseController : Controller { + [SimpleActionFilter] public IActionResult Index() { return View(); diff --git a/WebStoreCoreApplication/Controllers/EmployeeController.cs b/WebStoreCoreApplication/Controllers/EmployeeController.cs index 9abddd2..f9fb595 100644 --- a/WebStoreCoreApplication/Controllers/EmployeeController.cs +++ b/WebStoreCoreApplication/Controllers/EmployeeController.cs @@ -7,12 +7,14 @@ using Microsoft.AspNetCore.Mvc; using WebStoreCoreApplication.Controllers.Infrastructure.Interfaces; using WebStoreCoreApplication.ViewModels; +using WebStoreCoreApplication.Controllers; namespace WebStoreCoreApplication.Controllers { [Route("peoples")] public class EmployeeController : Controller { + private readonly IEmployeeService _employeeService; public EmployeeController(IEmployeeService employeeService) @@ -35,19 +37,24 @@ public IActionResult Employees() public IActionResult EmployeeDetails(int id) { var employeeviewmodel = _employeeService.GetByID(id); - if (employeeviewmodel == null) return NotFound(); + + if (employeeviewmodel == null) + return NotFound(); + return View(employeeviewmodel); } - [HttpGet] [Route("edit/{id?}")] - public IActionResult Editor (int? id) + public IActionResult Edit (int? id) { if (!id.HasValue) return View(new EmployeeViewModel()); + var model = _employeeService.GetByID(id.Value); + if (model == null) return NotFound(); + return View(model); } } diff --git a/WebStoreCoreApplication/Controllers/Infrastructure/EmployeeWork.cs b/WebStoreCoreApplication/Controllers/Infrastructure/EmployeeWork.cs index 640d12e..c171f7f 100644 --- a/WebStoreCoreApplication/Controllers/Infrastructure/EmployeeWork.cs +++ b/WebStoreCoreApplication/Controllers/Infrastructure/EmployeeWork.cs @@ -8,7 +8,7 @@ namespace WebStoreCoreApplication.Controllers.Infrastructure { public class EmployeeWork { - private const string correct = "1234"; + private const string correct = "qqq1234"; public RequestDelegate Next { get; } public EmployeeWork(RequestDelegate next) @@ -18,7 +18,7 @@ public EmployeeWork(RequestDelegate next) public async Task InvokeAsync(HttpContext context) { - var token = context.Request.Query["token"]; + var token = context.Request.Query["usertoken"]; if (string.IsNullOrEmpty(token)) { diff --git a/WebStoreCoreApplication/Controllers/Infrastructure/Services/InMemoryEmployeeServices.cs b/WebStoreCoreApplication/Controllers/Infrastructure/Services/InMemoryEmployeeServices.cs index 402d431..c553051 100644 --- a/WebStoreCoreApplication/Controllers/Infrastructure/Services/InMemoryEmployeeServices.cs +++ b/WebStoreCoreApplication/Controllers/Infrastructure/Services/InMemoryEmployeeServices.cs @@ -44,7 +44,9 @@ public void Commit() public void Delete(int id) { var employee = GetByID(id); - if (employee is null) return; + if (employee is null) + return; + _employees.Remove(employee); } diff --git a/WebStoreCoreApplication/Controllers/Infrastructure/SimpleActionFilter.cs b/WebStoreCoreApplication/Controllers/Infrastructure/SimpleActionFilter.cs index afa2eed..cd62e90 100644 --- a/WebStoreCoreApplication/Controllers/Infrastructure/SimpleActionFilter.cs +++ b/WebStoreCoreApplication/Controllers/Infrastructure/SimpleActionFilter.cs @@ -10,12 +10,14 @@ public class SimpleActionFilter : Attribute, IActionFilter { public void OnActionExecuting(ActionExecutingContext context) { - throw new NotImplementedException(); + // throw new NotImplementedException(); + return; } public void OnActionExecuted(ActionExecutedContext context) { - throw new NotImplementedException(); + // throw new NotImplementedException(); + return; } } diff --git a/WebStoreCoreApplication/Startup.cs b/WebStoreCoreApplication/Startup.cs index eaa90d9..a29af5d 100644 --- a/WebStoreCoreApplication/Startup.cs +++ b/WebStoreCoreApplication/Startup.cs @@ -27,10 +27,13 @@ public Startup(IConfiguration configuration) public void ConfigureServices(IServiceCollection services) { services.AddMvc(); - services.AddMvc(option => + + /* + services.AddMvc(options => { - option.Filters.Add(typeof(SimpleActionFilter)); + options.Filters.Add(typeof(SimpleActionFilter)); }); + */ services.AddSingleton(); } @@ -48,6 +51,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) var hello = _configuration["CustomeHelloWorld"]; //app.Map("/Index", CustomIndexHandler); + app.UseMiddleware(); app.UseRouting(); @@ -64,7 +68,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) */ }); } - + /* private void CustomIndexHandler(IApplicationBuilder app) { app.Run(async context => @@ -88,6 +92,7 @@ private void UseMiddlewareSample(IApplicationBuilder app) } }); } + */ } } diff --git a/WebStoreCoreApplication/ViewModels/EmployeeViewModel.cs b/WebStoreCoreApplication/ViewModels/EmployeeViewModel.cs index 2b563d1..440bc3d 100644 --- a/WebStoreCoreApplication/ViewModels/EmployeeViewModel.cs +++ b/WebStoreCoreApplication/ViewModels/EmployeeViewModel.cs @@ -8,9 +8,9 @@ namespace WebStoreCoreApplication.ViewModels public class EmployeeViewModel { public int Id { get; set; } - public string Name { get; set;} - public string SName { get; set;} + public string IName { get; set;} public string FName { get; set;} + public string OName { get; set;} public int Age { get; set;} public string Position { get; set;} } diff --git a/WebStoreCoreApplication/Views/Employee/EmployeeDetails.cshtml b/WebStoreCoreApplication/Views/Employee/EmployeeDetails.cshtml index 32c8621..ebee50d 100644 --- a/WebStoreCoreApplication/Views/Employee/EmployeeDetails.cshtml +++ b/WebStoreCoreApplication/Views/Employee/EmployeeDetails.cshtml @@ -15,15 +15,15 @@ Имя - @Model.Name + @Model.IName Фамилия - @Model.SName + @Model.FName Отчество - @Model.FName + @Model.OName Возраст diff --git a/WebStoreCoreApplication/Views/Employee/Employees.cshtml b/WebStoreCoreApplication/Views/Employee/Employees.cshtml index 420f2f4..896fb1e 100644 --- a/WebStoreCoreApplication/Views/Employee/Employees.cshtml +++ b/WebStoreCoreApplication/Views/Employee/Employees.cshtml @@ -12,9 +12,9 @@ @foreach (var item in Model) { - @item.Name - @item.SName + @item.IName @item.FName + @item.OName @Html.ActionLink("Детали", "EmployeeDetails", new { id=item.Id}) From cb7a474b02ef0015b4f94d5c2512a9d5a75c9987 Mon Sep 17 00:00:00 2001 From: OlegBakulin Date: Sat, 17 Oct 2020 20:50:00 +0300 Subject: [PATCH 4/6] =?UTF-8?q?=D0=A0=D1=83=D1=87=D0=BD=D0=BE=D0=B5=20?= =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?Edit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Views/Employee/Edit.cshtml | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 WebStoreCoreApplication/Views/Employee/Edit.cshtml diff --git a/WebStoreCoreApplication/Views/Employee/Edit.cshtml b/WebStoreCoreApplication/Views/Employee/Edit.cshtml new file mode 100644 index 0000000..5b21d61 --- /dev/null +++ b/WebStoreCoreApplication/Views/Employee/Edit.cshtml @@ -0,0 +1,61 @@ +@model WebStoreCoreApplication.ViewModels.EmployeeViewModel + +@{ + // Layout = null +} + + + + + + + Redactor + + +

    EmployViewModel


    +
    +
    +
    +
    + +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + +
    +
    +
    +
    + + + \ No newline at end of file From 5389220365e86b5ebb1d21530a885bb19be32e8a Mon Sep 17 00:00:00 2001 From: OlegBakulin Date: Sat, 17 Oct 2020 21:17:22 +0300 Subject: [PATCH 5/6] =?UTF-8?q?=D0=A0=D0=B5=D0=B4=D0=B0=D0=BA=D1=82=D0=B8?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D1=81=D0=BE=D1=82?= =?UTF-8?q?=D1=80=D1=83=D0=B4=D0=BD=D0=B8=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/EmployeeController.cs | 23 ++++++++++++++++++- .../Views/Employee/Edit.cshtml | 20 +++++----------- .../Views/Employee/Employees.cshtml | 1 + .../Views/Shared/_Layout.cshtml | 6 +++-- 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/WebStoreCoreApplication/Controllers/EmployeeController.cs b/WebStoreCoreApplication/Controllers/EmployeeController.cs index f9fb595..7f51f04 100644 --- a/WebStoreCoreApplication/Controllers/EmployeeController.cs +++ b/WebStoreCoreApplication/Controllers/EmployeeController.cs @@ -44,9 +44,29 @@ public IActionResult EmployeeDetails(int id) return View(employeeviewmodel); } + [HttpPost] [Route("edit/{id?}")] - public IActionResult Edit (int? id) + public IActionResult Edit (EmployeeViewModel employeemodel) //int? id) { + if (employeemodel.Id > 0) + { + var dbitem = _employeeService.GetByID(employeemodel.Id); + + if (ReferenceEquals(dbitem, null)) + return NotFound(); + dbitem.IName = employeemodel.IName; + dbitem.FName = employeemodel.FName; + dbitem.OName = employeemodel.OName; + dbitem.Age = employeemodel.Age; + dbitem.Position = employeemodel.Position; + } + else + { + _employeeService.AddNew(employeemodel); + } + _employeeService.Commit(); + return RedirectToAction(nameof(Employees)); + /* if (!id.HasValue) return View(new EmployeeViewModel()); @@ -56,6 +76,7 @@ public IActionResult Edit (int? id) return NotFound(); return View(model); + */ } } } \ No newline at end of file diff --git a/WebStoreCoreApplication/Views/Employee/Edit.cshtml b/WebStoreCoreApplication/Views/Employee/Edit.cshtml index 5b21d61..fff7923 100644 --- a/WebStoreCoreApplication/Views/Employee/Edit.cshtml +++ b/WebStoreCoreApplication/Views/Employee/Edit.cshtml @@ -1,18 +1,12 @@ @model WebStoreCoreApplication.ViewModels.EmployeeViewModel @{ - // Layout = null + ViewData["Title"] = "Edit"; + Layout = "~/Views/Shared/_Layout.cshtml"; } - - - - - - Redactor - - -

    EmployViewModel


    +

    Redactor

    +

    EmployViewModel


    @@ -49,13 +43,11 @@
    - +
    - - \ No newline at end of file diff --git a/WebStoreCoreApplication/Views/Employee/Employees.cshtml b/WebStoreCoreApplication/Views/Employee/Employees.cshtml index 896fb1e..e279408 100644 --- a/WebStoreCoreApplication/Views/Employee/Employees.cshtml +++ b/WebStoreCoreApplication/Views/Employee/Employees.cshtml @@ -18,6 +18,7 @@ @Html.ActionLink("Детали", "EmployeeDetails", new { id=item.Id}) + } diff --git a/WebStoreCoreApplication/Views/Shared/_Layout.cshtml b/WebStoreCoreApplication/Views/Shared/_Layout.cshtml index ebfc52d..e9f5bb1 100644 --- a/WebStoreCoreApplication/Views/Shared/_Layout.cshtml +++ b/WebStoreCoreApplication/Views/Shared/_Layout.cshtml @@ -3,8 +3,10 @@ @Html.Partial("Head") - - @RenderBody() + +
    + @RenderBody() +
    @Html.Partial("Foot") From fea48c363f0da8190f8b46b9c42392477910d7b3 Mon Sep 17 00:00:00 2001 From: OlegBakulin Date: Sat, 17 Oct 2020 22:16:13 +0300 Subject: [PATCH 6/6] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=20Delete,=20=D1=82=D0=BE=20=D0=B6=D0=B5=20=D0=B2?= =?UTF-8?q?=20=D1=80=D1=83=D1=87=D0=BD=D1=83=D1=8E.=20=D0=9D=D0=B5=20?= =?UTF-8?q?=D0=BC=D0=BE=D0=B3=D1=83=20=D0=BD=D0=B0=D0=B9=D1=82=D0=B8=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B1=D0=BB=D0=B5=D0=BC=D1=83=20=D0=B8=D0=B7?= =?UTF-8?q?-=D0=B7=D0=B0=20=D0=BA=D0=BE=D1=82=D0=BE=D1=80=D0=BE=D0=B9=20?= =?UTF-8?q?=D0=BD=D0=B5=20=D1=85=D0=BE=D1=87=D0=B5=D1=82=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=BF=D1=83=D1=81=D0=BA=D0=B0=D1=82=D1=8C=D1=81=D1=8F=20=D0=BE?= =?UTF-8?q?=D1=82=D0=BB=D0=B0=D0=B4=D0=BA=D0=B0=20=D0=B8=20=D0=B0=D0=B2?= =?UTF-8?q?=D1=82=D0=BE=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=B2=D0=B0=D1=82?= =?UTF-8?q?=D1=8C=20=D0=BF=D1=80=D0=B5=D0=B4=D1=81=D1=82=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/EmployeeController.cs | 16 ++++++++++ .../Services/InMemoryEmployeeServices.cs | 12 +++---- .../Views/Employee/Delete.cshtml | 31 +++++++++++++++++++ .../Views/Employee/Employees.cshtml | 2 ++ 4 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 WebStoreCoreApplication/Views/Employee/Delete.cshtml diff --git a/WebStoreCoreApplication/Controllers/EmployeeController.cs b/WebStoreCoreApplication/Controllers/EmployeeController.cs index 7f51f04..9fdd08f 100644 --- a/WebStoreCoreApplication/Controllers/EmployeeController.cs +++ b/WebStoreCoreApplication/Controllers/EmployeeController.cs @@ -33,6 +33,7 @@ public IActionResult Employees() { return View(_employeeService.GetAll()); } + [Route("{id}")] public IActionResult EmployeeDetails(int id) { @@ -78,5 +79,20 @@ public IActionResult Edit (EmployeeViewModel employeemodel) //int? id) return View(model); */ } + + [Route("delete/{id?}")] + public IActionResult Delete (int id) + { + var deluser = _employeeService.GetByID(id); + if (deluser.Id > 0 & (!ReferenceEquals(deluser, null))) + { + _employeeService.Delete(id); + } + return RedirectToAction(nameof(Employees)); + } + + + + } } \ No newline at end of file diff --git a/WebStoreCoreApplication/Controllers/Infrastructure/Services/InMemoryEmployeeServices.cs b/WebStoreCoreApplication/Controllers/Infrastructure/Services/InMemoryEmployeeServices.cs index c553051..4cac53d 100644 --- a/WebStoreCoreApplication/Controllers/Infrastructure/Services/InMemoryEmployeeServices.cs +++ b/WebStoreCoreApplication/Controllers/Infrastructure/Services/InMemoryEmployeeServices.cs @@ -14,18 +14,18 @@ public class InMemoryEmployeeServices : IEmployeeService new EmployeeViewModel { Id = 1, - Name = "Петр", - SName = "Петров", - FName = "Петрович", + IName = "Петр", + FName = "Петров", + OName = "Петрович", Age = 33, Position ="BOSS" }, new EmployeeViewModel { Id = 2, - Name = "Фёдр", - SName = "Фёдоров", - FName = "Фёдорович", + IName = "Фёдр", + FName = "Фёдоров", + OName = "Фёдорович", Age = 25, Position ="Программист"} }; diff --git a/WebStoreCoreApplication/Views/Employee/Delete.cshtml b/WebStoreCoreApplication/Views/Employee/Delete.cshtml new file mode 100644 index 0000000..1cf9a4b --- /dev/null +++ b/WebStoreCoreApplication/Views/Employee/Delete.cshtml @@ -0,0 +1,31 @@ +@model WebStoreCoreApplication.ViewModels.EmployeeViewModel +@{ + ViewData["Title"] = "Delete"; + Layout = "~/Views/Shared/_Layout.cshtml"; +} + +

    Delete

    + + +

    Id

    +
    +
    +
    +
    +
    + +
    + + + +
    + +
    + +
    +
    +
    +
    + diff --git a/WebStoreCoreApplication/Views/Employee/Employees.cshtml b/WebStoreCoreApplication/Views/Employee/Employees.cshtml index e279408..58186c3 100644 --- a/WebStoreCoreApplication/Views/Employee/Employees.cshtml +++ b/WebStoreCoreApplication/Views/Employee/Employees.cshtml @@ -8,9 +8,11 @@ Employees + Новый сотрудник @foreach (var item in Model) { +
    @item.IName @item.FName