From 6073dbda35197f6c43734da9034331f58f5916bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BA=20=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Mon, 22 May 2023 22:44:51 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D0=BE=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D1=8B=20=D1=81=20=D0=B2=D0=B5=D0=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ReportLogic.cs | 2 +- .../Implements/WorkStorage.cs | 2 +- .../CarServiceWebApp/CarServiceWebApp.csproj | 11 ++++++++ .../Controllers/HomeController.cs | 20 +++++++++++--- .../CarServiceWebApp/Models/CurrentUser.cs | 7 +++++ CarService/CarServiceWebApp/Program.cs | 9 +++++++ .../Views/Home/Privacy.cshtml | 6 ----- .../CarServiceWebApp/Views/Home/Works.cshtml | 26 +++++++++++++++++++ .../Views/Shared/_Layout.cshtml | 2 +- CarService/CarServiceWebApp/log4net.config | 16 ++++++++++++ 10 files changed, 89 insertions(+), 12 deletions(-) create mode 100644 CarService/CarServiceWebApp/Models/CurrentUser.cs delete mode 100644 CarService/CarServiceWebApp/Views/Home/Privacy.cshtml create mode 100644 CarService/CarServiceWebApp/Views/Home/Works.cshtml create mode 100644 CarService/CarServiceWebApp/log4net.config diff --git a/CarService/CarServiceBusinessLogic/BusinessLogics/ReportLogic.cs b/CarService/CarServiceBusinessLogic/BusinessLogics/ReportLogic.cs index 58fe03f..ea1c933 100644 --- a/CarService/CarServiceBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/CarService/CarServiceBusinessLogic/BusinessLogics/ReportLogic.cs @@ -25,7 +25,7 @@ namespace CarServiceBusinessLogic.BusinessLogics public List GetPayments(ReportBindingModel model) { _logger.LogInformation("Reading payments by works in requests"); - return _workPaymentStorage.GetPaymentsByWorks(new() {DateFrom = model.DateFrom, DateTo = model.DateTo }); + return _workPaymentStorage.GetPaymentsByWorks(new() { DateFrom = model.DateFrom, DateTo = model.DateTo }); } public void SaveComponentsToWordFile(ReportBindingModel model) { diff --git a/CarService/CarServiceDatabase/Implements/WorkStorage.cs b/CarService/CarServiceDatabase/Implements/WorkStorage.cs index 96a9d09..ae460cf 100644 --- a/CarService/CarServiceDatabase/Implements/WorkStorage.cs +++ b/CarService/CarServiceDatabase/Implements/WorkStorage.cs @@ -21,7 +21,7 @@ namespace CarServiceDatabase.Implements { using var context = new CarServiceDbContext(); return context.Works - .Where(x => x.Id == model.Id) + .Where(x => x.WorkerId == model.Id) .Include(x => x.Worker) .Select(x => x.GetViewModel) .ToList(); diff --git a/CarService/CarServiceWebApp/CarServiceWebApp.csproj b/CarService/CarServiceWebApp/CarServiceWebApp.csproj index c78c9c7..b6cf70f 100644 --- a/CarService/CarServiceWebApp/CarServiceWebApp.csproj +++ b/CarService/CarServiceWebApp/CarServiceWebApp.csproj @@ -6,4 +6,15 @@ enable + + + + + + + + + + + diff --git a/CarService/CarServiceWebApp/Controllers/HomeController.cs b/CarService/CarServiceWebApp/Controllers/HomeController.cs index 0f78e44..6e70cb8 100644 --- a/CarService/CarServiceWebApp/Controllers/HomeController.cs +++ b/CarService/CarServiceWebApp/Controllers/HomeController.cs @@ -1,4 +1,6 @@ -using CarServiceWebApp.Models; +using CarServiceBusinessLogic.BusinessLogics; +using CarServiceContracts.BusinessLogicsContracts; +using CarServiceWebApp.Models; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; @@ -7,22 +9,34 @@ namespace CarServiceWebApp.Controllers public class HomeController : Controller { private readonly ILogger _logger; + private readonly IWorkLogic _workLogic; - public HomeController(ILogger logger) + public HomeController(ILogger logger, IWorkLogic workLogic) { _logger = logger; + _workLogic = workLogic; } public IActionResult Index() { + if (CurrentUser.UserId < 1) + { + return Redirect("~/Home/Enter"); + } return View(); } - public IActionResult Privacy() + public IActionResult Enter() { return View(); } + public IActionResult Works() + { + ViewBag.Works = _workLogic.ReadList(new() { Id = 1 }); + return View(); + } + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { diff --git a/CarService/CarServiceWebApp/Models/CurrentUser.cs b/CarService/CarServiceWebApp/Models/CurrentUser.cs new file mode 100644 index 0000000..8e2bec8 --- /dev/null +++ b/CarService/CarServiceWebApp/Models/CurrentUser.cs @@ -0,0 +1,7 @@ +namespace CarServiceWebApp.Models +{ + public static class CurrentUser + { + public static int UserId = 0; + } +} \ No newline at end of file diff --git a/CarService/CarServiceWebApp/Program.cs b/CarService/CarServiceWebApp/Program.cs index 559dd3a..05a02e7 100644 --- a/CarService/CarServiceWebApp/Program.cs +++ b/CarService/CarServiceWebApp/Program.cs @@ -1,7 +1,16 @@ +using CarServiceBusinessLogic.BusinessLogics; +using CarServiceContracts.BusinessLogicsContracts; +using CarServiceContracts.StorageContracts; +using CarServiceDatabase.Implements; + var builder = WebApplication.CreateBuilder(args); // Add services to the container. +builder.Logging.SetMinimumLevel(LogLevel.Trace); +builder.Logging.AddLog4Net("log4net.config"); builder.Services.AddControllersWithViews(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); var app = builder.Build(); diff --git a/CarService/CarServiceWebApp/Views/Home/Privacy.cshtml b/CarService/CarServiceWebApp/Views/Home/Privacy.cshtml deleted file mode 100644 index af4fb19..0000000 --- a/CarService/CarServiceWebApp/Views/Home/Privacy.cshtml +++ /dev/null @@ -1,6 +0,0 @@ -@{ - ViewData["Title"] = "Privacy Policy"; -} -

@ViewData["Title"]

- -

Use this page to detail your site's privacy policy.

diff --git a/CarService/CarServiceWebApp/Views/Home/Works.cshtml b/CarService/CarServiceWebApp/Views/Home/Works.cshtml new file mode 100644 index 0000000..be1ff42 --- /dev/null +++ b/CarService/CarServiceWebApp/Views/Home/Works.cshtml @@ -0,0 +1,26 @@ +@{ + ViewData["Title"] = "Работы"; +} + +
+

Работы

+ + + + + + + + + + @foreach (var work in ViewBag.Works) + { + + + + + + } + +
НазваниеЦена (в рублях)Длительность (в часах)
@work.Name@work.Price@work.Duration
+
\ No newline at end of file diff --git a/CarService/CarServiceWebApp/Views/Shared/_Layout.cshtml b/CarService/CarServiceWebApp/Views/Shared/_Layout.cshtml index a3242a5..97e4673 100644 --- a/CarService/CarServiceWebApp/Views/Shared/_Layout.cshtml +++ b/CarService/CarServiceWebApp/Views/Shared/_Layout.cshtml @@ -20,7 +20,7 @@