From 648a139ca7da2f69d2d12ceb06b3c77cd4eab3bf Mon Sep 17 00:00:00 2001 From: revengel66 Date: Wed, 22 May 2024 01:01:59 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B0=D0=BB=D0=B0=20=D0=B2=D1=81=D1=91=20=D0=BD=D0=B0=D1=84?= =?UTF-8?q?=D0=B8=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Pizzeria/Pizzeria.sln | 23 +- Pizzeria/Pizzeria/FormMain.cs | 1 + .../BusinessLogic/ClientLogic.cs | 204 ++++++------- Pizzeria/PizzeriaClientApp/ApiClient.cs | 84 +++--- .../Controllers/HomeController.cs | 281 +++++++++--------- .../Models/ErrorViewModel.cs | 10 +- .../PizzeriaClientApp.csproj | 4 +- Pizzeria/PizzeriaClientApp/Program.cs | 7 +- .../Properties/launchSettings.json | 6 +- .../Views/Home/Create.cshtml | 24 +- .../PizzeriaClientApp/Views/Home/Enter.cshtml | 5 +- .../PizzeriaClientApp/Views/Home/Index.cshtml | 8 +- .../Views/Home/Privacy.cshtml | 20 +- .../Views/Home/Register.cshtml | 7 +- .../Views/Shared/_Layout.cshtml | 16 +- .../Views/Shared/_Layout.cshtml.css | 41 +-- Pizzeria/PizzeriaClientApp/appsettings.json | 16 +- .../BindingModels/ClientBindingModel.cs | 3 +- .../BusinessLogicsContracts/IClientLogic.cs | 5 +- .../SearchModels/ClientSearchModel.cs | 3 + .../ViewModels/OrderViewModel.cs | 1 + .../PizzeriaDataModels/Models/IClientModel.cs | 2 + .../Implements/ClientStorage.cs | 34 ++- .../Implements/OrderStorage.cs | 98 ++---- .../Models/Client.cs | 26 +- .../PizzeriaDatabaseImplement/Models/Order.cs | 44 ++- .../PizzeriaDatabaseImplement/Models/Pizza.cs | 2 + .../Controllers/ClientController.cs | 114 +++---- .../Controllers/MainController.cs | 28 +- .../PizzeriaRestApi/PizzeriaRestApi.csproj | 4 +- Pizzeria/PizzeriaRestApi/Program.cs | 18 +- .../PizzeriaRestApi/Properties/Resources.resx | 101 +++++++ .../Properties/launchSettings.json | 10 +- .../appsettings.Development.json | 2 +- Pizzeria/PizzeriaRestApi/appsettings.json | 2 +- Pizzeria/PizzeriaRestApi/log4net.config | 4 +- 36 files changed, 682 insertions(+), 576 deletions(-) create mode 100644 Pizzeria/PizzeriaRestApi/Properties/Resources.resx diff --git a/Pizzeria/Pizzeria.sln b/Pizzeria/Pizzeria.sln index 5538f3c..9ff6ab5 100644 --- a/Pizzeria/Pizzeria.sln +++ b/Pizzeria/Pizzeria.sln @@ -17,12 +17,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaFileImplement", "Pi EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaDatabaseImplement", "PizzeriaDatabaseImplement\PizzeriaDatabaseImplement.csproj", "{31FC8CAC-BED8-4DF0-8B57-20917DC66A5C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaClientApp", "PizzeriaClientApp\PizzeriaClientApp.csproj", "{431FCB4B-6315-4FC3-A88A-9ECFBF1D3763}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaRestApi", "PizzeriaRestApi\PizzeriaRestApi.csproj", "{82A572AA-ADBB-4D09-ACD0-5DFFC796A7E0}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaRestApi", "PizzeriaRestApi2\PizzeriaRestApi.csproj", "{DB5EBCD0-2BBF-4EDB-A59F-CA2F0496C56F}" - ProjectSection(ProjectDependencies) = postProject - {31FC8CAC-BED8-4DF0-8B57-20917DC66A5C} = {31FC8CAC-BED8-4DF0-8B57-20917DC66A5C} - EndProjectSection +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaClientApp", "PizzeriaClientApp\PizzeriaClientApp.csproj", "{355A354A-BF2C-4478-A889-1FDA57F12FBC}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -58,14 +55,14 @@ Global {31FC8CAC-BED8-4DF0-8B57-20917DC66A5C}.Debug|Any CPU.Build.0 = Debug|Any CPU {31FC8CAC-BED8-4DF0-8B57-20917DC66A5C}.Release|Any CPU.ActiveCfg = Release|Any CPU {31FC8CAC-BED8-4DF0-8B57-20917DC66A5C}.Release|Any CPU.Build.0 = Release|Any CPU - {431FCB4B-6315-4FC3-A88A-9ECFBF1D3763}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {431FCB4B-6315-4FC3-A88A-9ECFBF1D3763}.Debug|Any CPU.Build.0 = Debug|Any CPU - {431FCB4B-6315-4FC3-A88A-9ECFBF1D3763}.Release|Any CPU.ActiveCfg = Release|Any CPU - {431FCB4B-6315-4FC3-A88A-9ECFBF1D3763}.Release|Any CPU.Build.0 = Release|Any CPU - {DB5EBCD0-2BBF-4EDB-A59F-CA2F0496C56F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {DB5EBCD0-2BBF-4EDB-A59F-CA2F0496C56F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {DB5EBCD0-2BBF-4EDB-A59F-CA2F0496C56F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {DB5EBCD0-2BBF-4EDB-A59F-CA2F0496C56F}.Release|Any CPU.Build.0 = Release|Any CPU + {82A572AA-ADBB-4D09-ACD0-5DFFC796A7E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {82A572AA-ADBB-4D09-ACD0-5DFFC796A7E0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {82A572AA-ADBB-4D09-ACD0-5DFFC796A7E0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {82A572AA-ADBB-4D09-ACD0-5DFFC796A7E0}.Release|Any CPU.Build.0 = Release|Any CPU + {355A354A-BF2C-4478-A889-1FDA57F12FBC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {355A354A-BF2C-4478-A889-1FDA57F12FBC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {355A354A-BF2C-4478-A889-1FDA57F12FBC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {355A354A-BF2C-4478-A889-1FDA57F12FBC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Pizzeria/Pizzeria/FormMain.cs b/Pizzeria/Pizzeria/FormMain.cs index ab6ff74..0d702f5 100644 --- a/Pizzeria/Pizzeria/FormMain.cs +++ b/Pizzeria/Pizzeria/FormMain.cs @@ -28,6 +28,7 @@ namespace Pizzeria { dataGridView.DataSource = list; dataGridView.Columns["PizzaId"].Visible = false; + dataGridView.Columns["ClientId"].Visible = false; dataGridView.Columns["PizzaName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation("Загрузка заказов"); diff --git a/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/ClientLogic.cs b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/ClientLogic.cs index fa66472..1a17ce3 100644 --- a/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/ClientLogic.cs +++ b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/ClientLogic.cs @@ -7,113 +7,113 @@ using PizzeriaContracts.ViewModels; namespace PizzeriaBusinessLogic.BusinessLogic { - public class ClientLogic : IClientLogic - { - private readonly ILogger _logger; + public class ClientLogic : IClientLogic + { + private readonly ILogger _logger; + private readonly IClientStorage _clientStorage; - private readonly IClientStorage _clientStorage; + public ClientLogic(ILogger logger, IClientStorage clientStorage) + { + _logger = logger; + _clientStorage = clientStorage; + } - public ClientLogic(ILogger logger, IClientStorage clientStorage) - { - _logger = logger; - _clientStorage = clientStorage; - } + public List? ReadList(ClientSearchModel? model) + { + _logger.LogInformation("ReadList. ClientId:{Id}", model?.Id); + var list = model == null ? _clientStorage.GetFullList() : _clientStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } - public List? ReadList(ClientSearchModel? model) - { - _logger.LogInformation("ReadList. Email: {Email}. Id: {Id} ", model?.Email, model?.Id); - var list = (model == null) ? _clientStorage.GetFullList() : _clientStorage.GetFilteredList(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return null; - } - _logger.LogInformation("ReadList. Count: {Count}", list.Count); - return list; - } + public ClientViewModel? ReadElement(ClientSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ClientFio:{ClientFio}.Id:{ Id}", model.ClientFIO, model.Id); + var element = _clientStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } - public ClientViewModel? ReadElement(ClientSearchModel model) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - _logger.LogInformation("ReadElement. Client email: {Email}. Client id: {Id}", model.Email, model.Id); - var element = _clientStorage.GetElement(model); - if (element == null) - { - _logger.LogWarning("ReadElement element not found"); - return null; - } - _logger.LogInformation("ReadElement find. Id: {Id}", element.Id); - return element; - } + public bool Create(ClientBindingModel model) + { + CheckModel(model); + if (_clientStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } - public bool Create(ClientBindingModel model) - { - CheckModel(model); - if (_clientStorage.Insert(model) == null) - { - _logger.LogWarning("Insert operation failed"); - return false; - } - return true; - } + public bool Update(ClientBindingModel model) + { + CheckModel(model); + if (_clientStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } - public bool Update(ClientBindingModel model) - { - CheckModel(model); - if (_clientStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - return false; - } - return true; - } + public bool Delete(ClientBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_clientStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } - public bool Delete(ClientBindingModel model) - { - CheckModel(model, false); - _logger.LogInformation("Delete. Id: {Id}", model.Id); - if (_clientStorage.Delete(model) == null) - { - _logger.LogWarning("Delete operation failed"); - return false; - } - return true; - } - - private void CheckModel(ClientBindingModel model, bool withParams = true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (string.IsNullOrEmpty(model.ClientFIO)) - { - throw new ArgumentNullException("Нет ФИО клиента", nameof(model.ClientFIO)); - } - if (string.IsNullOrEmpty(model.Email)) - { - throw new ArgumentNullException("Нет логина(почты) клиента", nameof(model.Email)); - } - if (string.IsNullOrEmpty(model.Password)) - { - throw new ArgumentNullException("Нет пароля клиента", nameof(model.Password)); - } - _logger.LogInformation("Client. Id: {id}, FIO: {fio}, email: {email}, password: {password}", model.Id, model.ClientFIO, model.Email, model.Password); - var element = _clientStorage.GetElement(new ClientSearchModel - { - Email = model.Email - }); - if (element != null && element.Id != model.Id) - { - throw new InvalidOperationException("Клиент с таким логином(почтой) уже есть"); - } - } - } + private void CheckModel(ClientBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ClientFIO)) + { + throw new ArgumentNullException("Нет ФИО пользователя", nameof(model.ClientFIO)); + } + if (string.IsNullOrEmpty(model.Email)) + { + throw new ArgumentNullException("Нет почты пользователя", nameof(model.Email)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля пользователя", nameof(model.Password)); + } + _logger.LogInformation("Client. ClientFIO:{ClientFIO}.Email:{Email}.Password:{Password}.Id:{Id}", + model.ClientFIO, model.Email, model.Password, model.Id); + var element = _clientStorage.GetElement(new ClientSearchModel + { + ClientFIO = model.ClientFIO + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Клиент с таким именем уже есть"); + } + } + } } diff --git a/Pizzeria/PizzeriaClientApp/ApiClient.cs b/Pizzeria/PizzeriaClientApp/ApiClient.cs index 374302c..a929777 100644 --- a/Pizzeria/PizzeriaClientApp/ApiClient.cs +++ b/Pizzeria/PizzeriaClientApp/ApiClient.cs @@ -1,47 +1,49 @@ -using System.Net.Http.Headers; -using System.Text; -using Newtonsoft.Json; +using Newtonsoft.Json; using PizzeriaContracts.ViewModels; +using System.Net.Http.Headers; +using System.Text; namespace PizzeriaClientApp { - public static class APIClient - { - private static readonly HttpClient _client = new(); - public static ClientViewModel? Client { 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); - } - } - - } + public class APIClient + { + private static readonly HttpClient _client = new(); + public static ClientViewModel? Client { 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/Pizzeria/PizzeriaClientApp/Controllers/HomeController.cs b/Pizzeria/PizzeriaClientApp/Controllers/HomeController.cs index 99c98da..fd3c121 100644 --- a/Pizzeria/PizzeriaClientApp/Controllers/HomeController.cs +++ b/Pizzeria/PizzeriaClientApp/Controllers/HomeController.cs @@ -1,150 +1,147 @@ -using System.Diagnostics; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using PizzeriaClientApp.Models; using PizzeriaContracts.BindingModels; using PizzeriaContracts.ViewModels; +using System.Diagnostics; namespace PizzeriaClientApp.Controllers { - public class HomeController : Controller - { - private readonly ILogger _logger; - public HomeController(ILogger logger) - { - _logger = logger; - } - public IActionResult Index() - { - if (APIClient.Client == null) - { - return Redirect("~/Home/Enter"); - } - return - View(APIClient.GetRequest>($"api/main/getorders?clientId={APIClient.Client.Id}")); - } - [HttpGet] - public IActionResult Privacy() - { - if (APIClient.Client == null) - { - return Redirect("~/Home/Enter"); - } - return View(APIClient.Client); - } - [HttpPost] - public void Privacy(string login, string password, string fio) - { - if (APIClient.Client == null) - { - throw new Exception("Вы как суда попали? Суда вход только авторизованным"); - } - if (string.IsNullOrEmpty(login) || - string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) - { - throw new Exception("Введите логин, пароль и ФИО"); - } - APIClient.PostRequest("api/client/updatedata", new - ClientBindingModel - { - Id = APIClient.Client.Id, - ClientFIO = fio, - Email = login, - Password = password - }); - APIClient.Client.ClientFIO = fio; - APIClient.Client.Email = login; - APIClient.Client.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 - }); - } - [HttpGet] - public IActionResult Enter() - { - return View(); - } - [HttpPost] - public void Enter(string login, string password) - { - if (string.IsNullOrEmpty(login) || - string.IsNullOrEmpty(password)) - { - throw new Exception("Введите логин и пароль"); - } - APIClient.Client = - APIClient.GetRequest($"api/client/login?login={login}&password={password}"); - if (APIClient.Client == null) - { - throw new Exception("Неверный логин/пароль"); - } - Response.Redirect("Index"); - } - [HttpGet] - public IActionResult Register() - { - return View(); - } - [HttpPost] - public void Register(string login, string password, string fio) - { - if (string.IsNullOrEmpty(login) || - string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) - { - throw new Exception("Введите логин, пароль и ФИО"); - } - APIClient.PostRequest("api/client/register", new ClientBindingModel - { - ClientFIO = fio, - Email = login, - Password = password - }); - Response.Redirect("Enter"); - return; - } - [HttpGet] - public IActionResult Create() - { - ViewBag.Pizzas = - APIClient.GetRequest>("api/main/getproductlist"); - return View(); - } - [HttpPost] - public void Create(int product, int count) - { - if (APIClient.Client == null) - { - throw new Exception("Вы как суда попали? Суда вход только авторизованным"); - } - if (count <= 0) - { - throw new Exception("Количество и сумма должны быть больше 0"); - } - APIClient.PostRequest("api/main/createorder", new - OrderBindingModel - { - ClientId = APIClient.Client.Id, - PizzaId = product, - Count = count, - Sum = Calc(count, product) - }); - Response.Redirect("Index"); - } - [HttpPost] - public double Calc(int count, int product) - { - var prod = - APIClient.GetRequest($"api/main/getproduct?productId={product}" - ); - return count * (prod?.Price ?? 1); - } - } + public class HomeController : Controller + { + private readonly ILogger _logger; + public HomeController(ILogger logger) + { + _logger = logger; + } + + public IActionResult Index() + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/main/getorders?clientId={APIClient.Client.Id}")); + } + + [HttpGet] + public IActionResult Privacy() + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.Client); + } + + [HttpPost] + public void Privacy(string login, string password, string fio) + { + if (APIClient.Client == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) + { + throw new Exception("Введите логин, пароль и ФИО"); + } + APIClient.PostRequest("api/client/updatedata", new ClientBindingModel + { + Id = APIClient.Client.Id, + ClientFIO = fio, + Email = login, + Password = password + }); + + APIClient.Client.ClientFIO = fio; + APIClient.Client.Email = login; + APIClient.Client.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 }); + } + + [HttpGet] + public IActionResult Enter() + { + return View(); + } + + [HttpPost] + public void Enter(string login, string password) + { + if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)) + { + throw new Exception("Введите логин и пароль"); + } + APIClient.Client = APIClient.GetRequest($"api/client/login?login={login}&password={password}"); + if (APIClient.Client == null) + { + throw new Exception("Неверный логин/пароль"); + } + Response.Redirect("Index"); + } + + [HttpGet] + public IActionResult Register() + { + return View(); + } + + [HttpPost] + public void Register(string login, string password, string fio) + { + if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) + { + throw new Exception("Введите логин, пароль и ФИО"); + } + APIClient.PostRequest("api/client/register", new ClientBindingModel + { + ClientFIO = fio, + Email = login, + Password = password + }); + Response.Redirect("Enter"); + return; + } + + [HttpGet] + public IActionResult Create() + { + ViewBag.Pizzas = APIClient.GetRequest>("api/main/getpizzalist"); + return View(); + } + + [HttpPost] + public void Create(int pizza, int count) + { + if (APIClient.Client == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + if (count <= 0) + { + throw new Exception("Количество и сумма должны быть больше 0"); + } + APIClient.PostRequest("api/main/createorder", new OrderBindingModel + { + ClientId = APIClient.Client.Id, + PizzaId = pizza, + Count = count, + Sum = Calc(count, pizza) + }); + Response.Redirect("Index"); + } + + [HttpPost] + public double Calc(int count, int pizza) + { + var piz = APIClient.GetRequest($"api/main/getpizza?pizzaId={pizza}"); + return count * (piz?.Price ?? 1); + } + } } diff --git a/Pizzeria/PizzeriaClientApp/Models/ErrorViewModel.cs b/Pizzeria/PizzeriaClientApp/Models/ErrorViewModel.cs index 5fcce25..4d61c8f 100644 --- a/Pizzeria/PizzeriaClientApp/Models/ErrorViewModel.cs +++ b/Pizzeria/PizzeriaClientApp/Models/ErrorViewModel.cs @@ -1,9 +1,9 @@ namespace PizzeriaClientApp.Models { - public class ErrorViewModel - { - public string? RequestId { get; set; } + public class ErrorViewModel + { + public string? RequestId { get; set; } - public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); - } + public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); + } } diff --git a/Pizzeria/PizzeriaClientApp/PizzeriaClientApp.csproj b/Pizzeria/PizzeriaClientApp/PizzeriaClientApp.csproj index 4f83ff7..6eb2ec2 100644 --- a/Pizzeria/PizzeriaClientApp/PizzeriaClientApp.csproj +++ b/Pizzeria/PizzeriaClientApp/PizzeriaClientApp.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -7,7 +7,7 @@ - + diff --git a/Pizzeria/PizzeriaClientApp/Program.cs b/Pizzeria/PizzeriaClientApp/Program.cs index 0727468..1d4be63 100644 --- a/Pizzeria/PizzeriaClientApp/Program.cs +++ b/Pizzeria/PizzeriaClientApp/Program.cs @@ -1,3 +1,5 @@ +using PizzeriaClientApp; + var builder = WebApplication.CreateBuilder(args); // Add services to the container. @@ -5,6 +7,8 @@ builder.Services.AddControllersWithViews(); var app = builder.Build(); +APIClient.Connect(builder.Configuration); + // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { @@ -14,6 +18,7 @@ if (!app.Environment.IsDevelopment()) } app.UseHttpsRedirection(); + app.UseStaticFiles(); app.UseRouting(); @@ -24,4 +29,4 @@ app.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); -app.Run(); +app.Run(); \ No newline at end of file diff --git a/Pizzeria/PizzeriaClientApp/Properties/launchSettings.json b/Pizzeria/PizzeriaClientApp/Properties/launchSettings.json index 86c6585..fff8835 100644 --- a/Pizzeria/PizzeriaClientApp/Properties/launchSettings.json +++ b/Pizzeria/PizzeriaClientApp/Properties/launchSettings.json @@ -3,8 +3,8 @@ "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { - "applicationUrl": "http://localhost:24003", - "sslPort": 44310 + "applicationUrl": "http://localhost:36182", + "sslPort": 44316 } }, "profiles": { @@ -12,7 +12,7 @@ "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, - "applicationUrl": "https://localhost:7112;http://localhost:5283", + "applicationUrl": "https://localhost:7098;http://localhost:5179", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/Pizzeria/PizzeriaClientApp/Views/Home/Create.cshtml b/Pizzeria/PizzeriaClientApp/Views/Home/Create.cshtml index 126f6a0..28b68d2 100644 --- a/Pizzeria/PizzeriaClientApp/Views/Home/Create.cshtml +++ b/Pizzeria/PizzeriaClientApp/Views/Home/Create.cshtml @@ -8,43 +8,39 @@
Изделие:
- +
Количество:
-
- -
+
Сумма:
-
- -
+
-
- -
+
+ diff --git a/Pizzeria/PizzeriaClientApp/Views/Shared/_Layout.cshtml.css b/Pizzeria/PizzeriaClientApp/Views/Shared/_Layout.cshtml.css index a72cbea..947d5b5 100644 --- a/Pizzeria/PizzeriaClientApp/Views/Shared/_Layout.cshtml.css +++ b/Pizzeria/PizzeriaClientApp/Views/Shared/_Layout.cshtml.css @@ -2,47 +2,48 @@ for details on configuring this project to bundle and minify static web assets. */ a.navbar-brand { - white-space: normal; - text-align: center; - word-break: break-all; + white-space: normal; + text-align: center; + word-break: break-all; } a { - color: #0077cc; + color: #0077cc; } .btn-primary { - color: #fff; - background-color: #1b6ec2; - border-color: #1861ac; + color: #fff; + background-color: #1b6ec2; + border-color: #1861ac; } .nav-pills .nav-link.active, .nav-pills .show > .nav-link { - color: #fff; - background-color: #1b6ec2; - border-color: #1861ac; + color: #fff; + background-color: #1b6ec2; + border-color: #1861ac; } .border-top { - border-top: 1px solid #e5e5e5; + border-top: 1px solid #e5e5e5; } + .border-bottom { - border-bottom: 1px solid #e5e5e5; + border-bottom: 1px solid #e5e5e5; } .box-shadow { - box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05); + box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05); } button.accept-policy { - font-size: 1rem; - line-height: inherit; + font-size: 1rem; + line-height: inherit; } .footer { - position: absolute; - bottom: 0; - width: 100%; - white-space: nowrap; - line-height: 60px; + position: absolute; + bottom: 0; + width: 100%; + white-space: nowrap; + line-height: 60px; } diff --git a/Pizzeria/PizzeriaClientApp/appsettings.json b/Pizzeria/PizzeriaClientApp/appsettings.json index 7066d5e..a31eb08 100644 --- a/Pizzeria/PizzeriaClientApp/appsettings.json +++ b/Pizzeria/PizzeriaClientApp/appsettings.json @@ -1,10 +1,10 @@ { - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - }, - "AllowedHosts": "*", - "IPAddress": "http://localhost:5283/" + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*", + "IPAddress": "http://localhost:5175/" } diff --git a/Pizzeria/PizzeriaContracts/BindingModels/ClientBindingModel.cs b/Pizzeria/PizzeriaContracts/BindingModels/ClientBindingModel.cs index 32b782b..913e1ac 100644 --- a/Pizzeria/PizzeriaContracts/BindingModels/ClientBindingModel.cs +++ b/Pizzeria/PizzeriaContracts/BindingModels/ClientBindingModel.cs @@ -9,4 +9,5 @@ namespace PizzeriaContracts.BindingModels public string Email { get; set; } = string.Empty; public string Password { get; set; } = string.Empty; } -} + +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IClientLogic.cs b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IClientLogic.cs index f706990..46f8676 100644 --- a/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IClientLogic.cs +++ b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IClientLogic.cs @@ -1,6 +1,7 @@ using PizzeriaContracts.BindingModels; -using PizzeriaContracts.SearchModels; using PizzeriaContracts.ViewModels; +using PizzeriaContracts.SearchModels; + namespace PizzeriaContracts.BusinessLogicsContracts { public interface IClientLogic @@ -11,4 +12,4 @@ namespace PizzeriaContracts.BusinessLogicsContracts bool Update(ClientBindingModel model); bool Delete(ClientBindingModel model); } -} +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaContracts/SearchModels/ClientSearchModel.cs b/Pizzeria/PizzeriaContracts/SearchModels/ClientSearchModel.cs index 476f30b..41def71 100644 --- a/Pizzeria/PizzeriaContracts/SearchModels/ClientSearchModel.cs +++ b/Pizzeria/PizzeriaContracts/SearchModels/ClientSearchModel.cs @@ -3,8 +3,11 @@ public class ClientSearchModel { public int? Id { get; set; } + public string? ClientFIO { get; set; } + public string? Email { get; set; } + public string? Password { get; set; } } } diff --git a/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs index 9d62c5b..64d9592 100644 --- a/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs +++ b/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs @@ -12,6 +12,7 @@ namespace PizzeriaContracts.ViewModels [DisplayName("Пицца")] public string PizzaName { get; set; } = string.Empty; + public int ClientId { get; set; } [DisplayName("ФИО клиента")] diff --git a/Pizzeria/PizzeriaDataModels/Models/IClientModel.cs b/Pizzeria/PizzeriaDataModels/Models/IClientModel.cs index a81aa6d..0b39186 100644 --- a/Pizzeria/PizzeriaDataModels/Models/IClientModel.cs +++ b/Pizzeria/PizzeriaDataModels/Models/IClientModel.cs @@ -3,7 +3,9 @@ public interface IClientModel : IId { string ClientFIO { get; } + string Email { get; } + string Password { get; } } diff --git a/Pizzeria/PizzeriaDatabaseImplement/Implements/ClientStorage.cs b/Pizzeria/PizzeriaDatabaseImplement/Implements/ClientStorage.cs index bd9a510..a65a17d 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/Implements/ClientStorage.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/Implements/ClientStorage.cs @@ -1,10 +1,11 @@ -using PizzeriaContracts.BindingModels; +using System.Collections.Generic; +using System.Linq; +using PizzeriaContracts.BindingModels; using PizzeriaContracts.SearchModels; using PizzeriaContracts.StorageContracts; using PizzeriaContracts.ViewModels; using PizzeriaDatabaseImplement.Models; - namespace PizzeriaDatabaseImplement.Implements { public class ClientStorage : IClientStorage @@ -17,12 +18,12 @@ namespace PizzeriaDatabaseImplement.Implements public List GetFilteredList(ClientSearchModel model) { - if (string.IsNullOrEmpty(model.Email)) + if (string.IsNullOrEmpty(model.ClientFIO)) { return new(); } using var context = new PizzeriaDatabase(); - return context.Clients.Where(x => x.Email.Contains(model.Email)).Select(x => x.GetViewModel).ToList(); + return context.Clients.Where(x => x.ClientFIO.Contains(model.ClientFIO)).Select(x => x.GetViewModel).ToList(); } public ClientViewModel? GetElement(ClientSearchModel model) @@ -33,40 +34,41 @@ namespace PizzeriaDatabaseImplement.Implements } using var context = new PizzeriaDatabase(); return context.Clients.FirstOrDefault(x => - (!string.IsNullOrEmpty(model.Email) && x.Email == model.Email && !string.IsNullOrEmpty(model.Password) && x.Password == model.Password) - || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + (!string.IsNullOrEmpty(model.Email) && x.Email == model.Email && !string.IsNullOrEmpty(model.Password) && x.Password == model.Password) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; } public ClientViewModel? Insert(ClientBindingModel model) { - var newClient = Client.Create(model); - if (newClient == null) + var newComponent = Client.Create(model); + if (newComponent == null) { return null; } using var context = new PizzeriaDatabase(); - context.Clients.Add(newClient); + context.Clients.Add(newComponent); context.SaveChanges(); - return newClient.GetViewModel; + return newComponent.GetViewModel; } public ClientViewModel? Update(ClientBindingModel model) { using var context = new PizzeriaDatabase(); - var client = context.Clients.FirstOrDefault(x => x.Id == model.Id); - if (client == null) + var component = context.Clients.FirstOrDefault(x => x.Id == model.Id); + if (component == null) { return null; } - client.Update(model); + component.Update(model); context.SaveChanges(); - return client.GetViewModel; + return component.GetViewModel; } public ClientViewModel? Delete(ClientBindingModel model) { using var context = new PizzeriaDatabase(); - var element = context.Clients.FirstOrDefault(x => x.Id == model.Id); + var element = context.Clients.FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { context.Clients.Remove(element); @@ -76,4 +78,4 @@ namespace PizzeriaDatabaseImplement.Implements return null; } } -} +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaDatabaseImplement/Implements/OrderStorage.cs b/Pizzeria/PizzeriaDatabaseImplement/Implements/OrderStorage.cs index 0460657..0fd2a4f 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/Implements/OrderStorage.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/Implements/OrderStorage.cs @@ -1,87 +1,59 @@ -using Microsoft.EntityFrameworkCore; -using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BindingModels; using PizzeriaContracts.SearchModels; -using PizzeriaContracts.StorageContracts; using PizzeriaContracts.ViewModels; using PizzeriaDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; +using PizzeriaContracts.StorageContracts; +using System.Collections.Generic; +using System.Linq; + namespace PizzeriaDatabaseImplement.Implements { public class OrderStorage : IOrderStorage { - - public OrderViewModel? GetElement(OrderSearchModel model) + public List GetFullList() { - if (!model.Id.HasValue) - { - return null; - } using var context = new PizzeriaDatabase(); - return context.Orders - .Include(x => x.Pizza) - .Include(x => x.Client) - .FirstOrDefault(x => x.Id == model.Id) - ?.GetViewModel; + return context.Orders.Include(x => x.Pizza).Include(x => x.Client).Select(x => x.GetViewModel).ToList(); } public List GetFilteredList(OrderSearchModel model) { using var context = new PizzeriaDatabase(); - if (model.Id.HasValue) + if (model.DateFrom.HasValue) { - return context.Orders - .Include(x => x.Pizza) - .Include(x => x.Client) - .Where(x => x.Id == model.Id) - .Select(x => x.GetViewModel) - .ToList(); + return context.Orders.Include(x => x.Pizza).Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo).Select(x => x.GetViewModel).ToList(); } - else if (model.DateFrom != null && model.DateTo != null) + if (model.ClientId.HasValue) { - return context.Orders - .Include(x => x.Pizza) - .Include(x => x.Client) - .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) - .Select(x => x.GetViewModel) - .ToList(); + return context.Orders.Include(x => x.Pizza).Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList(); } - else if (model.ClientId.HasValue) - { - return context.Orders - .Include(x => x.Pizza) - .Include(x => x.Client) - .Where(x => x.ClientId == model.ClientId) - .Select(x => x.GetViewModel) - .ToList(); - } - return new(); + return context.Orders.Include(x => x.Pizza).Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList(); } - public List GetFullList() + public OrderViewModel? GetElement(OrderSearchModel model) { + if (!model.Id.HasValue) + { + return new(); + } using var context = new PizzeriaDatabase(); - return context.Orders - .Include(x => x.Pizza) - .Include(x => x.Client) - .Select(x => x.GetViewModel) - .ToList(); + return context.Orders.Include(x => x.Pizza).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; } - public OrderViewModel? Insert(OrderBindingModel model) { - var newOrder = Order.Create(model); + using var context = new PizzeriaDatabase(); + if (model == null) + return null; + var newOrder = Order.Create(context, model); if (newOrder == null) { return null; } - using var context = new PizzeriaDatabase(); context.Orders.Add(newOrder); context.SaveChanges(); - return context.Orders - .Include(x => x.Pizza) - .Include(x => x.Client) - .FirstOrDefault(x => x.Id == newOrder.Id) - ?.GetViewModel; + return newOrder.GetViewModel; } public OrderViewModel? Update(OrderBindingModel model) @@ -94,28 +66,20 @@ namespace PizzeriaDatabaseImplement.Implements } order.Update(model); context.SaveChanges(); - return context.Orders - .Include(x => x.Pizza) - .Include(x => x.Client) - .FirstOrDefault(x => x.Id == model.Id) - ?.GetViewModel; + return order.GetViewModel; } + public OrderViewModel? Delete(OrderBindingModel model) { using var context = new PizzeriaDatabase(); - var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id); - if (element != null) + var order = context.Orders.FirstOrDefault(rec => rec.Id == model.Id); + if (order != null) { - var deletedElement = context.Orders - .Include(x => x.Pizza) - .Include(x => x.Client) - .FirstOrDefault(x => x.Id == model.Id) - ?.GetViewModel; - context.Orders.Remove(element); + context.Orders.Remove(order); context.SaveChanges(); - return deletedElement; + return order.GetViewModel; } return null; } } -} +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaDatabaseImplement/Models/Client.cs b/Pizzeria/PizzeriaDatabaseImplement/Models/Client.cs index 56ea826..8d45f06 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/Models/Client.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/Models/Client.cs @@ -1,8 +1,9 @@ using PizzeriaContracts.BindingModels; using PizzeriaContracts.ViewModels; using PizzeriaDataModels.Models; -using System.ComponentModel.DataAnnotations.Schema; +using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; namespace PizzeriaDatabaseImplement.Models { @@ -11,13 +12,11 @@ namespace PizzeriaDatabaseImplement.Models public int Id { get; private set; } [Required] - public string ClientFIO { get; private set; } = string.Empty; - + public string ClientFIO { get; set; } = string.Empty; [Required] - public string Email { get; private set; } = string.Empty; - + public string Email { get; set; } = string.Empty; [Required] - public string Password { get; private set; } = string.Empty; + public string Password { get; set; } = string.Empty; [ForeignKey("ClientId")] public virtual List Orders { get; set; } = new(); @@ -28,7 +27,18 @@ namespace PizzeriaDatabaseImplement.Models { return null; } - return new() + return new Client() + { + Id = model.Id, + ClientFIO = model.ClientFIO, + Email = model.Email, + Password = model.Password + }; + } + + public static Client Create(ClientViewModel model) + { + return new Client { Id = model.Id, ClientFIO = model.ClientFIO, @@ -56,4 +66,4 @@ namespace PizzeriaDatabaseImplement.Models Password = Password }; } -} +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaDatabaseImplement/Models/Order.cs b/Pizzeria/PizzeriaDatabaseImplement/Models/Order.cs index e565677..b319b00 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/Models/Order.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/Models/Order.cs @@ -2,67 +2,79 @@ using PizzeriaContracts.ViewModels; using PizzeriaDataModels.Enums; using PizzeriaDataModels.Models; +using System; using System.ComponentModel.DataAnnotations; +using System.Linq; namespace PizzeriaDatabaseImplement.Models { public class Order : IOrderModel { public int Id { get; private set; } + + [Required] + public int ClientId { get; private set; } + + public virtual Client Client { get; private set; } = new(); + [Required] public int PizzaId { get; private set; } - [Required] - public int ClientId { get; set; } + + public virtual Pizza Pizza { get; set; } = new(); + [Required] public int Count { get; private set; } + [Required] public double Sum { get; private set; } + [Required] - public OrderStatus Status { get; private set; } + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + [Required] - public DateTime DateCreate { get; private set; } + public DateTime DateCreate { get; private set; } = DateTime.Now; + public DateTime? DateImplement { get; private set; } - public virtual Pizza Pizza { get; set; } - public virtual Client Client { get; set; } - public static Order? Create(OrderBindingModel? model) + + public static Order Create(PizzeriaDatabase context, OrderBindingModel model) { - if (model == null) - { - return null; - } return new Order() { Id = model.Id, - PizzaId = model.PizzaId, ClientId = model.ClientId, + Client = context.Clients.First(x => x.Id == model.ClientId), + PizzaId = model.PizzaId, + Pizza = context.Pizzas.First(x => x.Id == model.PizzaId), Count = model.Count, Sum = model.Sum, Status = model.Status, DateCreate = model.DateCreate, - DateImplement = model.DateImplement + DateImplement = model.DateImplement, }; } + public void Update(OrderBindingModel? model) { if (model == null) { return; } - Status = model.Status; DateImplement = model.DateImplement; } + public OrderViewModel GetViewModel => new() { Id = Id, - PizzaId = PizzaId, ClientId = ClientId, + ClientFIO = Client.ClientFIO, + PizzaId = PizzaId, + PizzaName = Pizza.PizzaName, Count = Count, Sum = Sum, Status = Status, DateCreate = DateCreate, DateImplement = DateImplement, - PizzaName = Pizza.PizzaName }; } } diff --git a/Pizzeria/PizzeriaDatabaseImplement/Models/Pizza.cs b/Pizzeria/PizzeriaDatabaseImplement/Models/Pizza.cs index 9b14d96..3835703 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/Models/Pizza.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/Models/Pizza.cs @@ -3,6 +3,8 @@ using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations; using PizzeriaContracts.BindingModels; using PizzeriaContracts.ViewModels; +using System.Collections.Generic; +using System.Linq; namespace PizzeriaDatabaseImplement.Models { diff --git a/Pizzeria/PizzeriaRestApi/Controllers/ClientController.cs b/Pizzeria/PizzeriaRestApi/Controllers/ClientController.cs index d8a5f21..51fdd6a 100644 --- a/Pizzeria/PizzeriaRestApi/Controllers/ClientController.cs +++ b/Pizzeria/PizzeriaRestApi/Controllers/ClientController.cs @@ -6,62 +6,64 @@ using PizzeriaContracts.ViewModels; namespace PizzeriaRestApi.Controllers { + [Route("api/[controller]/[action]")] + [ApiController] + public class ClientController : Controller + { + private readonly ILogger _logger; - [Route("api/[controller]/[action]")] - [ApiController] - public class ClientController : Controller - { - private readonly ILogger _logger; - private readonly IClientLogic _logic; - public ClientController(IClientLogic logic, ILogger - logger) - { - _logger = logger; - _logic = logic; - } - [HttpGet] - public ClientViewModel? Login(string login, string password) - { - try - { - return _logic.ReadElement(new ClientSearchModel - { - Email = login, - Password = password - }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка входа в систему"); - throw; - } - } - [HttpPost] - public void Register(ClientBindingModel model) - { - try - { - _logic.Create(model); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка регистрации"); - throw; - } - } - [HttpPost] - public void UpdateData(ClientBindingModel model) - { - try - { - _logic.Update(model); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка обновления данных"); - throw; - } - } - } + private readonly IClientLogic _logic; + public ClientController(IClientLogic logic, ILogger logger) + { + _logger = logger; + _logic = logic; + } + + [HttpGet] + public ClientViewModel? Login(string login, string password) + { + try + { + return _logic.ReadElement(new ClientSearchModel + { + Email = login, + Password = password + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка входа в систему"); + throw; + } + } + + [HttpPost] + public void Register(ClientBindingModel model) + { + try + { + _logic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка регистрации"); + throw; + } + } + + [HttpPost] + public void UpdateData(ClientBindingModel model) + { + try + { + _logic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления данных"); + throw; + } + } + } } diff --git a/Pizzeria/PizzeriaRestApi/Controllers/MainController.cs b/Pizzeria/PizzeriaRestApi/Controllers/MainController.cs index 218c582..132e092 100644 --- a/Pizzeria/PizzeriaRestApi/Controllers/MainController.cs +++ b/Pizzeria/PizzeriaRestApi/Controllers/MainController.cs @@ -1,5 +1,4 @@ -using DocumentFormat.OpenXml.Office2010.Excel; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using PizzeriaContracts.BindingModels; using PizzeriaContracts.BusinessLogicsContracts; using PizzeriaContracts.SearchModels; @@ -12,14 +11,18 @@ namespace PizzeriaRestApi.Controllers public class MainController : Controller { private readonly ILogger _logger; + private readonly IOrderLogic _order; + private readonly IPizzaLogic _pizza; + public MainController(ILogger logger, IOrderLogic order, IPizzaLogic pizza) { _logger = logger; _order = order; _pizza = pizza; } + [HttpGet] public List? GetPizzaList() { @@ -33,40 +36,35 @@ namespace PizzeriaRestApi.Controllers throw; } } + [HttpGet] public PizzaViewModel? GetPizza(int pizzaId) { try { - return _pizza.ReadElement(new PizzaSearchModel - { - Id = - pizzaId - }); + return _pizza.ReadElement(new PizzaSearchModel { Id = pizzaId }); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка получения продукта по id={Id}", - pizzaId); + _logger.LogError(ex, "Ошибка получения продукта по id={Id}", pizzaId); throw; } } + [HttpGet] public List? GetOrders(int clientId) { try { - return _order.ReadList(new OrderSearchModel - { - ClientId = clientId - }); + return _order.ReadList(new OrderSearchModel { ClientId = clientId }); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка получения списка заказов клиента id ={ Id}", clientId); - throw; + _logger.LogError(ex, "Ошибка получения списка заказов клиента id={Id}", clientId); + throw; } } + [HttpPost] public void CreateOrder(OrderBindingModel model) { diff --git a/Pizzeria/PizzeriaRestApi/PizzeriaRestApi.csproj b/Pizzeria/PizzeriaRestApi/PizzeriaRestApi.csproj index bb046f5..6ec075f 100644 --- a/Pizzeria/PizzeriaRestApi/PizzeriaRestApi.csproj +++ b/Pizzeria/PizzeriaRestApi/PizzeriaRestApi.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/Pizzeria/PizzeriaRestApi/Program.cs b/Pizzeria/PizzeriaRestApi/Program.cs index b7636b6..004702c 100644 --- a/Pizzeria/PizzeriaRestApi/Program.cs +++ b/Pizzeria/PizzeriaRestApi/Program.cs @@ -1,19 +1,23 @@ -using PizzeriaContracts.BusinessLogicsContracts; -using PizzeriaDatabaseImplement.Implements; -using PizzeriaContracts.StorageContracts; using PizzeriaBusinessLogic.BusinessLogic; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.StorageContracts; +using PizzeriaDatabaseImplement.Implements; using Microsoft.OpenApi.Models; var builder = WebApplication.CreateBuilder(args); + builder.Logging.SetMinimumLevel(LogLevel.Trace); builder.Logging.AddLog4Net("log4net.config"); + // Add services to the container. builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); + builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); + builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); @@ -21,16 +25,20 @@ builder.Services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "PizzeriaRestApi", Version = "v1" }); }); + var app = builder.Build(); + // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "PizzeriaRestApi v1")); } + app.UseHttpsRedirection(); + app.UseAuthorization(); + app.MapControllers(); -app.Run(); - +app.Run(); \ No newline at end of file diff --git a/Pizzeria/PizzeriaRestApi/Properties/Resources.resx b/Pizzeria/PizzeriaRestApi/Properties/Resources.resx new file mode 100644 index 0000000..4fdb1b6 --- /dev/null +++ b/Pizzeria/PizzeriaRestApi/Properties/Resources.resx @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Pizzeria/PizzeriaRestApi/Properties/launchSettings.json b/Pizzeria/PizzeriaRestApi/Properties/launchSettings.json index b07365d..dd92080 100644 --- a/Pizzeria/PizzeriaRestApi/Properties/launchSettings.json +++ b/Pizzeria/PizzeriaRestApi/Properties/launchSettings.json @@ -4,17 +4,17 @@ "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { - "applicationUrl": "http://localhost:37303", - "sslPort": 44315 + "applicationUrl": "http://localhost:38846", + "sslPort": 44358 } }, "profiles": { - "PizzeriaRestApi2": { + "PizzeriaRestApi": { "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, "launchUrl": "swagger", - "applicationUrl": "https://localhost:7291;http://localhost:5166", + "applicationUrl": "https://localhost:7175;http://localhost:5175", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } @@ -28,4 +28,4 @@ } } } -} +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaRestApi/appsettings.Development.json b/Pizzeria/PizzeriaRestApi/appsettings.Development.json index 0c208ae..1b2d3ba 100644 --- a/Pizzeria/PizzeriaRestApi/appsettings.Development.json +++ b/Pizzeria/PizzeriaRestApi/appsettings.Development.json @@ -5,4 +5,4 @@ "Microsoft.AspNetCore": "Warning" } } -} +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaRestApi/appsettings.json b/Pizzeria/PizzeriaRestApi/appsettings.json index 10f68b8..ec04bc1 100644 --- a/Pizzeria/PizzeriaRestApi/appsettings.json +++ b/Pizzeria/PizzeriaRestApi/appsettings.json @@ -6,4 +6,4 @@ } }, "AllowedHosts": "*" -} +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaRestApi/log4net.config b/Pizzeria/PizzeriaRestApi/log4net.config index 8f1290c..fbbf5db 100644 --- a/Pizzeria/PizzeriaRestApi/log4net.config +++ b/Pizzeria/PizzeriaRestApi/log4net.config @@ -1,7 +1,7 @@ - + - +