diff --git a/ServiceStation/ServiceStation.sln b/ServiceStation/ServiceStation.sln index 87fa72f..05fbb61 100644 --- a/ServiceStation/ServiceStation.sln +++ b/ServiceStation/ServiceStation.sln @@ -11,7 +11,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServiceStationContracts", " EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServiceStationBusinessLogic", "ServiceStationBusinessLogic\ServiceStationBusinessLogic.csproj", "{E3C21F43-152C-4770-88A9-0CF5B182E6AD}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceStationRestAPI", "ServiceStationRestAPI\ServiceStationRestAPI.csproj", "{6EA674DA-F458-4662-BBE5-7F5C45D5AE5C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServiceStationRestAPI", "ServiceStationRestAPI\ServiceStationRestAPI.csproj", "{6EA674DA-F458-4662-BBE5-7F5C45D5AE5C}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServiceSourceExecutorApp", "ServiceStationExecutorApp\ServiceSourceExecutorApp.csproj", "{85655746-80E9-4B8B-A0B6-94DF0B7E9339}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,6 +41,10 @@ Global {6EA674DA-F458-4662-BBE5-7F5C45D5AE5C}.Debug|Any CPU.Build.0 = Debug|Any CPU {6EA674DA-F458-4662-BBE5-7F5C45D5AE5C}.Release|Any CPU.ActiveCfg = Release|Any CPU {6EA674DA-F458-4662-BBE5-7F5C45D5AE5C}.Release|Any CPU.Build.0 = Release|Any CPU + {85655746-80E9-4B8B-A0B6-94DF0B7E9339}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {85655746-80E9-4B8B-A0B6-94DF0B7E9339}.Debug|Any CPU.Build.0 = Debug|Any CPU + {85655746-80E9-4B8B-A0B6-94DF0B7E9339}.Release|Any CPU.ActiveCfg = Release|Any CPU + {85655746-80E9-4B8B-A0B6-94DF0B7E9339}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ServiceStation/ServiceStationClientApp/Controllers/HomeController.cs b/ServiceStation/ServiceStationClientApp/Controllers/HomeController.cs deleted file mode 100644 index 866c7a4..0000000 --- a/ServiceStation/ServiceStationClientApp/Controllers/HomeController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using ServiceSourceClientApp.Models; -using System.Diagnostics; - -namespace ServiceSourceClientApp.Controllers { - public class HomeController : Controller { - private readonly ILogger _logger; - - public HomeController(ILogger logger) { - _logger = logger; - } - - public IActionResult Index() { - return View(); - } - - public IActionResult Privacy() { - return View(); - } - - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] - public IActionResult Error() { - return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); - } - } -} diff --git a/ServiceStation/ServiceStationClientApp/ServiceSourceExecutorApp.csproj b/ServiceStation/ServiceStationClientApp/ServiceSourceExecutorApp.csproj deleted file mode 100644 index 4c2bb77..0000000 --- a/ServiceStation/ServiceStationClientApp/ServiceSourceExecutorApp.csproj +++ /dev/null @@ -1,9 +0,0 @@ - - - - net7.0 - enable - enable - - - diff --git a/ServiceStation/ServiceStationExecutorApp/APIClient.cs b/ServiceStation/ServiceStationExecutorApp/APIClient.cs new file mode 100644 index 0000000..7d1385a --- /dev/null +++ b/ServiceStation/ServiceStationExecutorApp/APIClient.cs @@ -0,0 +1,42 @@ +using Newtonsoft.Json; +using ServiceStationContracts.ViewModels; +using System.Net.Http.Headers; +using System.Text; + +namespace ServiceSourceExecutorApp { + public class APIClient { + private static readonly HttpClient _client = new(); + public static ExecutorViewModel? executor { get; set; } = null; + public static string port { get; set; } = string.Empty; + + public static void Connect(IConfiguration configuration) { + _client.BaseAddress = new Uri(configuration["IPAddress"]); + port = _client.BaseAddress.Port.ToString(); + _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/ServiceStation/ServiceStationExecutorApp/Controllers/HomeController.cs b/ServiceStation/ServiceStationExecutorApp/Controllers/HomeController.cs new file mode 100644 index 0000000..dc6d20d --- /dev/null +++ b/ServiceStation/ServiceStationExecutorApp/Controllers/HomeController.cs @@ -0,0 +1,96 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Formatters; +using ServiceSourceClientApp.Models; +using ServiceSourceExecutorApp; +using ServiceStationContracts.BindingModels; +using ServiceStationContracts.ViewModels; +using System.Diagnostics; + +namespace ServiceSourceClientApp.Controllers { + public class HomeController : Controller { + private readonly ILogger _logger; + + public HomeController(ILogger logger) { + _logger = logger; + } + + [HttpGet] + public IActionResult Index() { + if (APIClient.executor == null) { + return Redirect("~/Home/Enter"); + } + return View(); + } + + [HttpGet] + public IActionResult Enter() { + return View(); + } + + [HttpPost] + public void Enter(string email, string password) { + if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password)) { + throw new Exception(" "); + } + APIClient.executor = APIClient.GetRequest($"api/main/Login?email={email}&password={password}"); + if (APIClient.executor == null) { + throw new Exception(" "); + } + Response.Redirect("Index"); + } + + [HttpGet] + public IActionResult Register() { + return View(); + } + + [HttpPost] + public void Register(string email, string password, string fio) { + if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) { + throw new Exception(" , "); + } + APIClient.PostRequest("api/Main/Register", new ExecutorBindingModel { + Email = email, + Password = password, + FIO = fio + }); + Response.Redirect("Enter"); + return; + } + + [HttpGet] + public IActionResult Privacy() { + if (APIClient.executor == null) { + return Redirect("~/Home/Enter"); + } + return View(APIClient.executor); + } + + [HttpPost] + public void Privacy(string email, string password, string fio) { + if (APIClient.executor == null) { + Response.Redirect("~/Home/Enter"); + return; + } + if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) { + throw new Exception(" , "); + } + APIClient.PostRequest("api/Main/UpdateData", new ExecutorBindingModel { + Id = APIClient.executor.Id, + Email = email, + Password = password, + FIO = fio + }); + + APIClient.executor.FIO = fio; + APIClient.executor.Email = email; + APIClient.executor.Password = password; + Response.Redirect("Index"); + } + + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + public IActionResult Error() { + return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); + } + } +} diff --git a/ServiceStation/ServiceStationClientApp/Models/ErrorViewModel.cs b/ServiceStation/ServiceStationExecutorApp/Models/ErrorViewModel.cs similarity index 100% rename from ServiceStation/ServiceStationClientApp/Models/ErrorViewModel.cs rename to ServiceStation/ServiceStationExecutorApp/Models/ErrorViewModel.cs diff --git a/ServiceStation/ServiceStationClientApp/Program.cs b/ServiceStation/ServiceStationExecutorApp/Program.cs similarity index 91% rename from ServiceStation/ServiceStationClientApp/Program.cs rename to ServiceStation/ServiceStationExecutorApp/Program.cs index 65e1308..aa0f33f 100644 --- a/ServiceStation/ServiceStationClientApp/Program.cs +++ b/ServiceStation/ServiceStationExecutorApp/Program.cs @@ -1,3 +1,5 @@ +using ServiceSourceExecutorApp; + namespace ServiceSourceClientApp { public class Program { public static void Main(string[] args) { @@ -7,6 +9,7 @@ namespace ServiceSourceClientApp { builder.Services.AddControllersWithViews(); var app = builder.Build(); + APIClient.Connect(builder.Configuration); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { diff --git a/ServiceStation/ServiceStationClientApp/Properties/launchSettings.json b/ServiceStation/ServiceStationExecutorApp/Properties/launchSettings.json similarity index 100% rename from ServiceStation/ServiceStationClientApp/Properties/launchSettings.json rename to ServiceStation/ServiceStationExecutorApp/Properties/launchSettings.json diff --git a/ServiceStation/ServiceStationExecutorApp/ServiceSourceExecutorApp.csproj b/ServiceStation/ServiceStationExecutorApp/ServiceSourceExecutorApp.csproj new file mode 100644 index 0000000..75518c4 --- /dev/null +++ b/ServiceStation/ServiceStationExecutorApp/ServiceSourceExecutorApp.csproj @@ -0,0 +1,17 @@ + + + + net7.0 + enable + enable + + + + + + + + + + + diff --git a/ServiceStation/ServiceStationClientApp/Views/Home/CreateWork.cshtml b/ServiceStation/ServiceStationExecutorApp/Views/Home/CreateWork.cshtml similarity index 100% rename from ServiceStation/ServiceStationClientApp/Views/Home/CreateWork.cshtml rename to ServiceStation/ServiceStationExecutorApp/Views/Home/CreateWork.cshtml diff --git a/ServiceStation/ServiceStationExecutorApp/Views/Home/Enter.cshtml b/ServiceStation/ServiceStationExecutorApp/Views/Home/Enter.cshtml new file mode 100644 index 0000000..e5fee87 --- /dev/null +++ b/ServiceStation/ServiceStationExecutorApp/Views/Home/Enter.cshtml @@ -0,0 +1,21 @@ +@{ + ViewData["Title"] = "Enter"; +} + +
+

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

+
+
+
+
Почта:
+
+
+
+
Пароль:
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/ServiceStation/ServiceStationClientApp/Views/Home/Index.cshtml b/ServiceStation/ServiceStationExecutorApp/Views/Home/Index.cshtml similarity index 100% rename from ServiceStation/ServiceStationClientApp/Views/Home/Index.cshtml rename to ServiceStation/ServiceStationExecutorApp/Views/Home/Index.cshtml diff --git a/ServiceStation/ServiceStationClientApp/Views/Home/Privacy.cshtml b/ServiceStation/ServiceStationExecutorApp/Views/Home/Privacy.cshtml similarity index 64% rename from ServiceStation/ServiceStationClientApp/Views/Home/Privacy.cshtml rename to ServiceStation/ServiceStationExecutorApp/Views/Home/Privacy.cshtml index e19241b..956de81 100644 --- a/ServiceStation/ServiceStationClientApp/Views/Home/Privacy.cshtml +++ b/ServiceStation/ServiceStationExecutorApp/Views/Home/Privacy.cshtml @@ -1,25 +1,24 @@ -@{ +@using ServiceStationContracts.ViewModels +@{ ViewData["Title"] = "Privacy Policy"; } +@model ExecutorViewModel +

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

-
Логин:
-
+
Почта:
+
Пароль:
-
Пароль:
-
-
-
-
логин:
-
+
ФИО:
+
diff --git a/ServiceStation/ServiceStationClientApp/Views/Home/Register.cshtml b/ServiceStation/ServiceStationExecutorApp/Views/Home/Register.cshtml similarity index 58% rename from ServiceStation/ServiceStationClientApp/Views/Home/Register.cshtml rename to ServiceStation/ServiceStationExecutorApp/Views/Home/Register.cshtml index 4c4ed45..031f18e 100644 --- a/ServiceStation/ServiceStationClientApp/Views/Home/Register.cshtml +++ b/ServiceStation/ServiceStationExecutorApp/Views/Home/Register.cshtml @@ -7,24 +7,19 @@
-
Логин:
-
+
Почта:
+
Пароль:
-
Имя:
-
+
ФИО:
+
-
-
Фамилия:
-
-
-
-
+ \ No newline at end of file diff --git a/ServiceStation/ServiceStationClientApp/Views/Shared/Error.cshtml b/ServiceStation/ServiceStationExecutorApp/Views/Shared/Error.cshtml similarity index 100% rename from ServiceStation/ServiceStationClientApp/Views/Shared/Error.cshtml rename to ServiceStation/ServiceStationExecutorApp/Views/Shared/Error.cshtml diff --git a/ServiceStation/ServiceStationClientApp/Views/Shared/_Layout.cshtml b/ServiceStation/ServiceStationExecutorApp/Views/Shared/_Layout.cshtml similarity index 97% rename from ServiceStation/ServiceStationClientApp/Views/Shared/_Layout.cshtml rename to ServiceStation/ServiceStationExecutorApp/Views/Shared/_Layout.cshtml index 54baf10..4290970 100644 --- a/ServiceStation/ServiceStationClientApp/Views/Shared/_Layout.cshtml +++ b/ServiceStation/ServiceStationExecutorApp/Views/Shared/_Layout.cshtml @@ -12,7 +12,7 @@