From 9d7db7a41be629cd5c177169f6670c71ba644a5a Mon Sep 17 00:00:00 2001 From: DyCTaTOR <125912249+DyCTaTOR@users.noreply.github.com> Date: Mon, 27 May 2024 00:50:40 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD=D0=B0=20?= =?UTF-8?q?=D1=80=D0=B5=D0=B3=D0=B8=D1=81=D1=82=D1=80=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D1=8F=20+=20=D0=B2=D1=85=D0=BE=D0=B4=20+=20=D0=BE=D1=82=D0=BE?= =?UTF-8?q?=D0=B1=D1=80=D0=B0=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BB=D0=B8?= =?UTF-8?q?=D1=87=D0=BD=D1=8B=D1=85=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85?= =?UTF-8?q?=20=D0=B4=D0=BB=D1=8F=20=D0=B2=D0=BE=D1=80=D0=BA=D0=B5=D1=80?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- University/University.sln | 5 +- .../UniversityClientAppWorker/APIClient.cs | 45 ++++++ .../Controllers/HomeController.cs | 137 +++++++++++++++--- .../UniversityClientAppWorker/Program.cs | 5 +- .../UniversityClientAppWorker.csproj | 1 + .../Views/Home/Enter.cshtml | 24 +-- .../Views/Home/Index.cshtml | 66 +++++++-- .../Views/Home/Privacy.cshtml | 28 +++- .../Views/Home/Register.cshtml | 42 ++---- .../Views/Shared/_Layout.cshtml | 16 +- .../appsettings.json | 4 +- .../ViewModels/PlanOfStudyViewModel.cs | 1 - .../UniversityDatabase.cs | 2 +- .../Controllers/PlanOfStudysController.cs | 2 +- 14 files changed, 296 insertions(+), 82 deletions(-) create mode 100644 University/UniversityClientAppWorker/APIClient.cs diff --git a/University/University.sln b/University/University.sln index 9d98589..5e4d697 100644 --- a/University/University.sln +++ b/University/University.sln @@ -15,7 +15,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UniversityRestApi", "Univer EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UniversityClientAppStorekeeper", "UniversityClientApp\UniversityClientAppStorekeeper.csproj", "{65698622-8424-4D8E-BFC9-721BB5252F22}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversityClientAppWorker", "UniversityClientAppWorker\UniversityClientAppWorker.csproj", "{11E2609A-BD4A-4D03-8B71-4EC0DF1CDC88}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UniversityClientAppWorker", "UniversityClientAppWorker\UniversityClientAppWorker.csproj", "{11E2609A-BD4A-4D03-8B71-4EC0DF1CDC88}" + ProjectSection(ProjectDependencies) = postProject + {4F0BB8C6-2BA8-4212-BC86-4E66C1C03816} = {4F0BB8C6-2BA8-4212-BC86-4E66C1C03816} + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/University/UniversityClientAppWorker/APIClient.cs b/University/UniversityClientAppWorker/APIClient.cs new file mode 100644 index 0000000..8446141 --- /dev/null +++ b/University/UniversityClientAppWorker/APIClient.cs @@ -0,0 +1,45 @@ +using Newtonsoft.Json; +using UniversityContracts.ViewModels; +using System.Net.Http.Headers; +using System.Text; + +namespace PlumbingRepairClientApp +{ + public class APIClient + { + private static readonly HttpClient _client = new(); + public static UserViewModel? User { get; set; } = null; + public static void Connect(IConfiguration configuration) + { + _client.BaseAddress = new Uri(configuration["IPAddress"]); + _client.DefaultRequestHeaders.Accept.Clear(); + _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + } + public static T? GetRequest(string requestUrl) + { + var response = _client.GetAsync(requestUrl); + var result = response.Result.Content.ReadAsStringAsync().Result; + if (response.Result.IsSuccessStatusCode) + { + return JsonConvert.DeserializeObject(result); + } + else + { + throw new Exception(result); + } + } + public static void PostRequest(string requestUrl, T model) + { + var json = JsonConvert.SerializeObject(model); + var data = new StringContent(json, Encoding.UTF8, "application/json"); + + var response = _client.PostAsync(requestUrl, data); + + var result = response.Result.Content.ReadAsStringAsync().Result; + if (!response.Result.IsSuccessStatusCode) + { + throw new Exception(result); + } + } + } +} diff --git a/University/UniversityClientAppWorker/Controllers/HomeController.cs b/University/UniversityClientAppWorker/Controllers/HomeController.cs index 07b67dd..9cec5cf 100644 --- a/University/UniversityClientAppWorker/Controllers/HomeController.cs +++ b/University/UniversityClientAppWorker/Controllers/HomeController.cs @@ -1,6 +1,9 @@ using Microsoft.AspNetCore.Mvc; +using PlumbingRepairClientApp; using System.Diagnostics; using UniversityClientAppWorker.Models; +using UniversityContracts.BindingModels; +using UniversityContracts.ViewModels; using UniversityDataModels.Enums; namespace UniversityClientAppWorker.Controllers @@ -13,29 +16,93 @@ namespace UniversityClientAppWorker.Controllers { _logger = logger; } + [HttpGet] + public IActionResult Index() + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/planofstudys/getplanofstudys?userId={APIClient.User.Id}")); + } + [HttpPost] + public void CreatePlanOfStudy(string profile, string formOfStudy) + { + if (APIClient.User == null) + { + throw new Exception(" "); + } + if (string.IsNullOrEmpty(formOfStudy) || string.IsNullOrEmpty(profile)) + { + throw new Exception(" "); + } + APIClient.PostRequest("api/planofstudys/createplanofstudy", new PlanOfStudyBindingModel + { + Profile = profile, + FormOfStudy = formOfStudy, + UserId = APIClient.User.Id + }); + Response.Redirect("Index"); + } + [HttpGet] + public IActionResult Privacy() + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.User); + } + [HttpPost] + public void Privacy(string login, string password, string email) + { + if (APIClient.User == null) + { + throw new Exception(" "); + } + if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(email)) + { + throw new Exception(" , "); + } + APIClient.PostRequest("api/user/updatedata", new UserViewModel + { + Id = APIClient.User.Id, + Email = email, + Login = login, + Password = password + }); - public IActionResult Index() + APIClient.User.Login = login; + APIClient.User.Email = email; + APIClient.User.Password = password; + Response.Redirect("Index"); + } + [HttpGet] + public IActionResult Attestations() + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.AttestationScore = Enum.GetValues(typeof(AttestationScore)).Cast(); + return View(); + } + [HttpGet] + public IActionResult Students() + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + return View(); + } + [HttpGet] + public IActionResult Enter() { return View(); } - - public IActionResult Privacy() - { - return View(); - } - - public IActionResult Attestations() - { - ViewBag.AttestationScore = Enum.GetValues(typeof(AttestationScore)).Cast(); - return View(); - } - - public IActionResult Students() - { - return View(); - } - - public IActionResult PlanOfStudys() + [HttpGet] + public IActionResult Register() { return View(); } @@ -45,5 +112,35 @@ namespace UniversityClientAppWorker.Controllers { return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); } - } + [HttpPost] + public void Enter(string login, string password) + { + if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)) + { + throw new Exception(" "); + } + APIClient.User = APIClient.GetRequest($"api/user/loginworker?login={login}&password={password}"); + if (APIClient.User == null) + { + throw new Exception(" /"); + } + Response.Redirect("Index"); + } + [HttpPost] + public void Register(string login, string password, string email) + { + if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(email)) + { + throw new Exception(" , "); + } + APIClient.PostRequest("api/user/registerworker", new UserBindingModel + { + Email = email, + Login = login, + Password = password + }); + Response.Redirect("Enter"); + return; + } + } } diff --git a/University/UniversityClientAppWorker/Program.cs b/University/UniversityClientAppWorker/Program.cs index 0727468..ae82eb7 100644 --- a/University/UniversityClientAppWorker/Program.cs +++ b/University/UniversityClientAppWorker/Program.cs @@ -1,3 +1,5 @@ +using PlumbingRepairClientApp; + var builder = WebApplication.CreateBuilder(args); // Add services to the container. @@ -5,7 +7,8 @@ builder.Services.AddControllersWithViews(); var app = builder.Build(); -// Configure the HTTP request pipeline. +APIClient.Connect(builder.Configuration); +// Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/Home/Error"); diff --git a/University/UniversityClientAppWorker/UniversityClientAppWorker.csproj b/University/UniversityClientAppWorker/UniversityClientAppWorker.csproj index 63f35df..469fd09 100644 --- a/University/UniversityClientAppWorker/UniversityClientAppWorker.csproj +++ b/University/UniversityClientAppWorker/UniversityClientAppWorker.csproj @@ -11,6 +11,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/University/UniversityClientAppWorker/Views/Home/Enter.cshtml b/University/UniversityClientAppWorker/Views/Home/Enter.cshtml index 7754c3f..e37d486 100644 --- a/University/UniversityClientAppWorker/Views/Home/Enter.cshtml +++ b/University/UniversityClientAppWorker/Views/Home/Enter.cshtml @@ -5,16 +5,16 @@

Вход в приложение

-
-
Логин:
-
-
-
-
Пароль:
-
-
-
-
-
-
+
+
Логин:
+
+
+
+
Пароль:
+
+
+
+
+
+
diff --git a/University/UniversityClientAppWorker/Views/Home/Index.cshtml b/University/UniversityClientAppWorker/Views/Home/Index.cshtml index d7c62d1..7b270d9 100644 --- a/University/UniversityClientAppWorker/Views/Home/Index.cshtml +++ b/University/UniversityClientAppWorker/Views/Home/Index.cshtml @@ -1,15 +1,59 @@ -@{ - ViewData["Title"] = "Home Page"; +@using UniversityContracts.ViewModels +@model List +@{ + ViewData["Title"] = "Управление планами обучений"; }
- - -
- -
+

@ViewData["Title"]

+ +
+
+
Профиль:
+
+ +
+
+
+
Форма обучения:
+
+ +
+
+
+
+
+ +
+
+
+ + + + + + + + + + + @foreach (var planOfStudy in Model) + { + + + + + + + + } + +
ProfileFormOfStudyActions
+ @Html.DisplayFor(modelItem => planOfStudy.Id) + @planOfStudy.FormOfStudy + + Edit + Details + Delete +
diff --git a/University/UniversityClientAppWorker/Views/Home/Privacy.cshtml b/University/UniversityClientAppWorker/Views/Home/Privacy.cshtml index af4fb19..a2fc040 100644 --- a/University/UniversityClientAppWorker/Views/Home/Privacy.cshtml +++ b/University/UniversityClientAppWorker/Views/Home/Privacy.cshtml @@ -1,6 +1,26 @@ -@{ +@using UniversityContracts.ViewModels +@model UserViewModel +@{ ViewData["Title"] = "Privacy Policy"; } -

@ViewData["Title"]

- -

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

+
+

Личные данные

+
+
+
+
Логин:
+
+
+
+
Пароль:
+
+
+
+
E-mail:
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/University/UniversityClientAppWorker/Views/Home/Register.cshtml b/University/UniversityClientAppWorker/Views/Home/Register.cshtml index eb0880b..ee7e3f4 100644 --- a/University/UniversityClientAppWorker/Views/Home/Register.cshtml +++ b/University/UniversityClientAppWorker/Views/Home/Register.cshtml @@ -5,33 +5,21 @@

Регистрация

-
-
Логин:
-
-
-
-
Пароль:
-
-
-
-
Фамилия:
-
-
-
Имя:
-
-
-
-
Отчество:
-
-
-
-
Телефон:
-
+
Логин:
+
+
+
+
Почта:
+
+
+
+
Пароль:
+
+
+
+
+
-
-
-
-
diff --git a/University/UniversityClientAppWorker/Views/Shared/_Layout.cshtml b/University/UniversityClientAppWorker/Views/Shared/_Layout.cshtml index afa1a69..a3f5281 100644 --- a/University/UniversityClientAppWorker/Views/Shared/_Layout.cshtml +++ b/University/UniversityClientAppWorker/Views/Shared/_Layout.cshtml @@ -20,10 +20,22 @@ diff --git a/University/UniversityClientAppWorker/appsettings.json b/University/UniversityClientAppWorker/appsettings.json index 10f68b8..6dc64ab 100644 --- a/University/UniversityClientAppWorker/appsettings.json +++ b/University/UniversityClientAppWorker/appsettings.json @@ -5,5 +5,7 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + + "IPAddress": "http://localhost:5032/" } diff --git a/University/UniversityContracts/ViewModels/PlanOfStudyViewModel.cs b/University/UniversityContracts/ViewModels/PlanOfStudyViewModel.cs index 96f51a9..54f1527 100644 --- a/University/UniversityContracts/ViewModels/PlanOfStudyViewModel.cs +++ b/University/UniversityContracts/ViewModels/PlanOfStudyViewModel.cs @@ -12,7 +12,6 @@ namespace UniversityContracts.ViewModels { public int Id { get; set; } public int UserId { get; set; } - public int WorkerId { get; set; } [DisplayName("Профиль")] public string Profile { get; set; } = string.Empty; [DisplayName("Форма обучения")] diff --git a/University/UniversityDatabaseImplement/UniversityDatabase.cs b/University/UniversityDatabaseImplement/UniversityDatabase.cs index 07213d0..2b73bad 100644 --- a/University/UniversityDatabaseImplement/UniversityDatabase.cs +++ b/University/UniversityDatabaseImplement/UniversityDatabase.cs @@ -11,7 +11,7 @@ namespace UniversityDatabaseImplement if (optionsBuilder.IsConfigured == false) { //Возможно понадобится писать вместо (localdb) название пк, вот пк Егора: DESKTOP-N8BRIPR; other-name: LAPTOP-DYCTATOR; other-name: DyCTaTOR - optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-N8BRIPR\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=DyCTaTOR\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } diff --git a/University/UniversityRestApi/Controllers/PlanOfStudysController.cs b/University/UniversityRestApi/Controllers/PlanOfStudysController.cs index fcb81ab..5a6c831 100644 --- a/University/UniversityRestApi/Controllers/PlanOfStudysController.cs +++ b/University/UniversityRestApi/Controllers/PlanOfStudysController.cs @@ -22,7 +22,7 @@ namespace UniversityRestApi.Controllers { try { - return _logic.ReadList(new PlanOfStudySearchModel { UserId = userId }); + return _logic.ReadList(new PlanOfStudySearchModel { }); } catch (Exception ex) {