From 80027002c2b4a0db567a3f001510ab8e83e873bb Mon Sep 17 00:00:00 2001 From: DeerElk Date: Wed, 8 May 2024 11:57:33 +0400 Subject: [PATCH] lab5 --- .../Confectionery/FormClients.Designer.cs | 81 +++++++++++ Confectionery/Confectionery/FormClients.cs | 78 +++++++++++ Confectionery/Confectionery/FormClients.resx | 120 ++++++++++++++++ .../Confectionery/FormCreateOrder.Designer.cs | 38 ++++- .../Confectionery/FormCreateOrder.cs | 34 ++++- .../Confectionery/FormMain.Designer.cs | 13 +- Confectionery/Confectionery/FormMain.cs | 12 ++ Confectionery/Confectionery/Program.cs | 3 + ...LogicsContracts.IComponentLogic.datasource | 0 .../ConfectioneryClientApp.csproj | 10 ++ .../Controllers/HomeController.cs | 132 ++++++++++++++++-- .../Models/ErrorViewModel.cs | 1 - .../ConfectioneryClientApp/Program.cs | 6 +- .../Properties/launchSettings.json | 11 +- .../Views/Home/Create.cshtml | 56 ++++++++ .../Views/Home/Enter.cshtml | 21 +++ .../Views/Home/Index.cshtml | 77 +++++++++- .../Views/Home/Privacy.cshtml | 39 +++++- .../Views/Home/Register.cshtml | 26 ++++ .../Views/Shared/Error.cshtml | 2 +- .../Views/Shared/_Layout.cshtml | 34 +++-- .../ConfectioneryClientApp/appsettings.json | 2 +- .../Implements/ClientStorage.cs | 32 ++--- ... 20240508053013_InitialCreate.Designer.cs} | 47 ++++++- ...ate.cs => 20240508053013_InitialCreate.cs} | 32 ++++- .../ConfectioneryDatabaseModelSnapshot.cs | 45 +++++- .../Models/Order.cs | 2 +- .../Implements/OrderStorage.cs | 5 +- .../Models/Client.cs | 3 +- .../Implements/OrderStorage.cs | 3 +- .../ConfectioneryRestApi.csproj | 1 + .../ConfectioneryRestApi.http | 6 - .../Controllers/MainController.cs | 9 +- Confectionery/ConfectioneryRestApi/Program.cs | 6 +- .../Properties/launchSettings.json | 12 +- .../ConfectioneryRestApi/log4net.config | 2 +- 36 files changed, 891 insertions(+), 110 deletions(-) create mode 100644 Confectionery/Confectionery/FormClients.Designer.cs create mode 100644 Confectionery/Confectionery/FormClients.cs create mode 100644 Confectionery/Confectionery/FormClients.resx rename Confectionery/Confectionery/{ => Properties}/DataSources/ConfectioneryContracts.BusinessLogicsContracts.IComponentLogic.datasource (100%) create mode 100644 Confectionery/ConfectioneryClientApp/Views/Home/Create.cshtml create mode 100644 Confectionery/ConfectioneryClientApp/Views/Home/Enter.cshtml create mode 100644 Confectionery/ConfectioneryClientApp/Views/Home/Register.cshtml rename Confectionery/ConfectioneryDatabaseImplement/Migrations/{20240410062130_InitialCreate.Designer.cs => 20240508053013_InitialCreate.Designer.cs} (78%) rename Confectionery/ConfectioneryDatabaseImplement/Migrations/{20240410062130_InitialCreate.cs => 20240508053013_InitialCreate.cs} (79%) delete mode 100644 Confectionery/ConfectioneryRestApi/ConfectioneryRestApi.http diff --git a/Confectionery/Confectionery/FormClients.Designer.cs b/Confectionery/Confectionery/FormClients.Designer.cs new file mode 100644 index 0000000..f0e5ffb --- /dev/null +++ b/Confectionery/Confectionery/FormClients.Designer.cs @@ -0,0 +1,81 @@ +namespace ConfectioneryView +{ + partial class FormClients + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer Clients = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (Clients != null)) + { + Clients.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + buttonDel = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // DataGridView + // + dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridView.BackgroundColor = SystemColors.Window; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 0); + dataGridView.Margin = new Padding(4); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(742, 444); + dataGridView.TabIndex = 0; + // + // buttonDel + // + buttonDel.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonDel.Location = new Point(754, 198); + buttonDel.Margin = new Padding(4); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(112, 56); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // FormClients + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(878, 444); + Controls.Add(buttonDel); + Controls.Add(dataGridView); + Margin = new Padding(4); + Name = "FormPastries"; + Text = "Клиенты"; + Load += FormClients_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonDel; + } +} \ No newline at end of file diff --git a/Confectionery/Confectionery/FormClients.cs b/Confectionery/Confectionery/FormClients.cs new file mode 100644 index 0000000..6e3e48d --- /dev/null +++ b/Confectionery/Confectionery/FormClients.cs @@ -0,0 +1,78 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +namespace ConfectioneryView +{ + public partial class FormClients : Form + { + private readonly ILogger _logger; + private readonly IClientLogic _logic; + public FormClients(ILogger logger, IClientLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ClientFIO"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Email"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Password"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка клиентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки клиентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void FormClients_Load(object sender, EventArgs e) + { + LoadData(); + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) + == DialogResult.Yes) + { + int id = Convert.ToInt32( + dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление клиента"); + try + { + if (!_logic.Delete(new ClientBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. " + + "Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления компонента"); + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + } +} \ No newline at end of file diff --git a/Confectionery/Confectionery/FormClients.resx b/Confectionery/Confectionery/FormClients.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Confectionery/Confectionery/FormClients.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Confectionery/Confectionery/FormCreateOrder.Designer.cs b/Confectionery/Confectionery/FormCreateOrder.Designer.cs index 377b38d..09041eb 100644 --- a/Confectionery/Confectionery/FormCreateOrder.Designer.cs +++ b/Confectionery/Confectionery/FormCreateOrder.Designer.cs @@ -36,12 +36,14 @@ textBoxSum = new TextBox(); buttonSave = new Button(); buttonCancel = new Button(); + labelClient = new Label(); + comboBoxClient = new ComboBox(); SuspendLayout(); // // labelPastry // labelPastry.AutoSize = true; - labelPastry.Location = new Point(16, 21); + labelPastry.Location = new Point(16, 14); labelPastry.Name = "labelPastry"; labelPastry.Size = new Size(84, 25); labelPastry.TabIndex = 0; @@ -50,7 +52,7 @@ // labelCount // labelCount.AutoSize = true; - labelCount.Location = new Point(16, 66); + labelCount.Location = new Point(16, 61); labelCount.Name = "labelCount"; labelCount.Size = new Size(111, 25); labelCount.TabIndex = 1; @@ -59,7 +61,7 @@ // labelSum // labelSum.AutoSize = true; - labelSum.Location = new Point(16, 112); + labelSum.Location = new Point(16, 153); labelSum.Name = "labelSum"; labelSum.Size = new Size(71, 25); labelSum.TabIndex = 2; @@ -70,7 +72,7 @@ comboBoxPastry.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; comboBoxPastry.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxPastry.FormattingEnabled = true; - comboBoxPastry.Location = new Point(170, 21); + comboBoxPastry.Location = new Point(170, 11); comboBoxPastry.Name = "comboBoxPastry"; comboBoxPastry.Size = new Size(396, 33); comboBoxPastry.TabIndex = 3; @@ -79,7 +81,7 @@ // textBoxCount // textBoxCount.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - textBoxCount.Location = new Point(170, 66); + textBoxCount.Location = new Point(170, 57); textBoxCount.Name = "textBoxCount"; textBoxCount.Size = new Size(396, 31); textBoxCount.TabIndex = 4; @@ -88,10 +90,10 @@ // textBoxSum // textBoxSum.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - textBoxSum.Location = new Point(170, 112); + textBoxSum.Location = new Point(170, 149); textBoxSum.Name = "textBoxSum"; textBoxSum.ReadOnly = true; - textBoxSum.Size = new Size(396, 31); + textBoxSum.Size = new Size(159, 31); textBoxSum.TabIndex = 5; // // buttonSave @@ -116,6 +118,24 @@ buttonCancel.UseVisualStyleBackColor = true; buttonCancel.Click += ButtonCancel_Click; // + // labelClient + // + labelClient.AutoSize = true; + labelClient.Location = new Point(16, 108); + labelClient.Name = "labelClient"; + labelClient.Size = new Size(71, 25); + labelClient.TabIndex = 8; + labelClient.Text = "Клиент:"; + // + // comboBoxClient + // + comboBoxClient.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxClient.FormattingEnabled = true; + comboBoxClient.Location = new Point(170, 102); + comboBoxClient.Name = "comboBoxClient"; + comboBoxClient.Size = new Size(396, 33); + comboBoxClient.TabIndex = 9; + // // FormCreateOrder // AutoScaleDimensions = new SizeF(10F, 25F); @@ -129,6 +149,8 @@ Controls.Add(labelSum); Controls.Add(labelCount); Controls.Add(labelPastry); + Controls.Add(comboBoxClient); + Controls.Add(labelClient); Name = "FormCreateOrder"; Text = "Создание заказа"; Load += FormCreateOrder_Load; @@ -146,5 +168,7 @@ private TextBox textBoxSum; private Button buttonSave; private Button buttonCancel; + private Label labelClient; + private ComboBox comboBoxClient; } } \ No newline at end of file diff --git a/Confectionery/Confectionery/FormCreateOrder.cs b/Confectionery/Confectionery/FormCreateOrder.cs index 8170330..f80286f 100644 --- a/Confectionery/Confectionery/FormCreateOrder.cs +++ b/Confectionery/Confectionery/FormCreateOrder.cs @@ -9,13 +9,15 @@ namespace ConfectioneryView private readonly ILogger _logger; private readonly IPastryLogic _logicP; private readonly IOrderLogic _logicO; + private readonly IClientLogic _logicC; public FormCreateOrder(ILogger logger, - IPastryLogic logicP, IOrderLogic logicO) + IPastryLogic logicP, IOrderLogic logicO, IClientLogic logicC) { InitializeComponent(); _logger = logger; _logicP = logicP; _logicO = logicO; + _logicC = logicC; } private void FormCreateOrder_Load(object sender, EventArgs e) { @@ -38,6 +40,25 @@ namespace ConfectioneryView MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } + _logger.LogInformation("Загрузка клиентов для заказа"); + try + { + var list = _logicC.ReadList(null); + if (list != null) + { + comboBoxClient.DisplayMember = "ClientFIO"; + comboBoxClient.ValueMember = "Id"; + comboBoxClient.DataSource = list; + comboBoxClient.SelectedItem = null; + } + _logger.LogInformation("Клиенты загружены"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки клиентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } } private void CalcSum() { @@ -70,12 +91,12 @@ namespace ConfectioneryView } private void ComboBoxPastry_SelectedIndexChanged(object sender, EventArgs e) - { + { CalcSum(); } private void ButtonSave_Click(object sender, EventArgs e) { - if (string.IsNullOrEmpty(textBoxCount.Text)) + if (string.IsNullOrEmpty(textBoxCount.Text)) { MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); @@ -87,12 +108,19 @@ namespace ConfectioneryView MessageBoxButtons.OK, MessageBoxIcon.Error); return; } + if (comboBoxClient.SelectedValue == null) + { + MessageBox.Show("Выберите клиента", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } _logger.LogInformation("Создание заказа"); try { var operationResult = _logicO.CreateOrder(new OrderBindingModel { PastryId = Convert.ToInt32(comboBoxPastry.SelectedValue), + ClientId = Convert.ToInt32(comboBoxClient.SelectedValue), Count = Convert.ToInt32(textBoxCount.Text), Sum = Convert.ToDouble(textBoxSum.Text) }); diff --git a/Confectionery/Confectionery/FormMain.Designer.cs b/Confectionery/Confectionery/FormMain.Designer.cs index 02bbddf..79d0ada 100644 --- a/Confectionery/Confectionery/FormMain.Designer.cs +++ b/Confectionery/Confectionery/FormMain.Designer.cs @@ -38,6 +38,7 @@ referencesToolStripMenuItem = new ToolStripMenuItem(); componentsToolStripMenuItem = new ToolStripMenuItem(); pastriesToolStripMenuItem = new ToolStripMenuItem(); + clientsToolStripMenuItem = new ToolStripMenuItem(); отчётыToolStripMenuItem = new ToolStripMenuItem(); listOfComponentsToolStripMenuItem = new ToolStripMenuItem(); ComponentsByPastryToolStripMenuItem = new ToolStripMenuItem(); @@ -119,13 +120,13 @@ menuStrip.Items.AddRange(new ToolStripItem[] { referencesToolStripMenuItem, отчётыToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; - menuStrip.Size = new Size(235, 33); + menuStrip.Size = new Size(415, 33); menuStrip.TabIndex = 8; menuStrip.Text = "menuStrip1"; // // referencesToolStripMenuItem // - referencesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItem, pastriesToolStripMenuItem }); + referencesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItem, pastriesToolStripMenuItem, clientsToolStripMenuItem }); referencesToolStripMenuItem.Name = "referencesToolStripMenuItem"; referencesToolStripMenuItem.Size = new Size(139, 29); referencesToolStripMenuItem.Text = "Справочники"; @@ -144,6 +145,13 @@ pastriesToolStripMenuItem.Text = "Кондитерские изделия"; pastriesToolStripMenuItem.Click += PastriesToolStripMenuItem_Click; // + // clientsToolStripMenuItem + // + clientsToolStripMenuItem.Name = "clientsToolStripMenuItem"; + clientsToolStripMenuItem.Size = new Size(298, 34); + clientsToolStripMenuItem.Text = "Клиенты"; + clientsToolStripMenuItem.Click += ClientsToolStripMenuItem_Click; + // // отчётыToolStripMenuItem // отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { listOfComponentsToolStripMenuItem, ComponentsByPastryToolStripMenuItem, listOfOrdersToolStripMenuItem }); @@ -211,5 +219,6 @@ private ToolStripMenuItem listOfComponentsToolStripMenuItem; private ToolStripMenuItem ComponentsByPastryToolStripMenuItem; private ToolStripMenuItem listOfOrdersToolStripMenuItem; + private ToolStripMenuItem clientsToolStripMenuItem; } } \ No newline at end of file diff --git a/Confectionery/Confectionery/FormMain.cs b/Confectionery/Confectionery/FormMain.cs index f212a04..188a0bc 100644 --- a/Confectionery/Confectionery/FormMain.cs +++ b/Confectionery/Confectionery/FormMain.cs @@ -32,6 +32,7 @@ namespace ConfectioneryView { dataGridView.DataSource = list; dataGridView.Columns["PastryId"].Visible = false; + dataGridView.Columns["ClientId"].Visible = false; dataGridView.Columns["PastryName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.None; } @@ -64,6 +65,15 @@ namespace ConfectioneryView form.ShowDialog(); } } + private void ClientsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService( + typeof(FormClients)); + if (service is FormClients form) + { + form.ShowDialog(); + } + } private void ListOfComponentsToolStripMenuItem_Click(object sender, EventArgs e) { @@ -203,6 +213,8 @@ namespace ConfectioneryView Id = id, PastryId = Convert.ToInt32(dataGridView.SelectedRows[ 0].Cells["PastryId"].Value), + ClientId = Convert.ToInt32(dataGridView.SelectedRows[ + 0].Cells["ClientId"].Value), Status = Enum.Parse(dataGridView.SelectedRows[ 0].Cells["Status"].Value.ToString()), Count = Convert.ToInt32(dataGridView.SelectedRows[ diff --git a/Confectionery/Confectionery/Program.cs b/Confectionery/Confectionery/Program.cs index fea7b85..53b5074 100644 --- a/Confectionery/Confectionery/Program.cs +++ b/Confectionery/Confectionery/Program.cs @@ -38,10 +38,12 @@ namespace ConfectioneryView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -51,6 +53,7 @@ namespace ConfectioneryView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/Confectionery/Confectionery/DataSources/ConfectioneryContracts.BusinessLogicsContracts.IComponentLogic.datasource b/Confectionery/Confectionery/Properties/DataSources/ConfectioneryContracts.BusinessLogicsContracts.IComponentLogic.datasource similarity index 100% rename from Confectionery/Confectionery/DataSources/ConfectioneryContracts.BusinessLogicsContracts.IComponentLogic.datasource rename to Confectionery/Confectionery/Properties/DataSources/ConfectioneryContracts.BusinessLogicsContracts.IComponentLogic.datasource diff --git a/Confectionery/ConfectioneryClientApp/ConfectioneryClientApp.csproj b/Confectionery/ConfectioneryClientApp/ConfectioneryClientApp.csproj index 1b28a01..6362625 100644 --- a/Confectionery/ConfectioneryClientApp/ConfectioneryClientApp.csproj +++ b/Confectionery/ConfectioneryClientApp/ConfectioneryClientApp.csproj @@ -6,4 +6,14 @@ enable + + + + + + + + + + diff --git a/Confectionery/ConfectioneryClientApp/Controllers/HomeController.cs b/Confectionery/ConfectioneryClientApp/Controllers/HomeController.cs index 09f7ebd..97dfc43 100644 --- a/Confectionery/ConfectioneryClientApp/Controllers/HomeController.cs +++ b/Confectionery/ConfectioneryClientApp/Controllers/HomeController.cs @@ -1,32 +1,146 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.ViewModels; using ConfectioneryClientApp.Models; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; - namespace ConfectioneryClientApp.Controllers { public class HomeController : Controller { private readonly ILogger _logger; - public HomeController(ILogger logger) { _logger = logger; } - public IActionResult Index() { - return View(); + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest> + ($"api/main/getorders?clientId={APIClient.Client.Id}")); } - + [HttpGet] public IActionResult Privacy() { - return View(); + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.Client); } - - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + [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 }); + 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.Pastries = APIClient.GetRequest> + ("api/main/getpastrylist"); + return View(); + } + [HttpPost] + public void Create(int pastry, 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, + PastryId = pastry, + Count = count, + Sum = Calc(count, pastry) + }); + Response.Redirect("Index"); + } + [HttpPost] + public double Calc(int count, int pastry) + { + var prod = APIClient.GetRequest + ($"api/main/getpastry?pastryId={pastry}"); + return count * (prod?.Price ?? 1); } } } diff --git a/Confectionery/ConfectioneryClientApp/Models/ErrorViewModel.cs b/Confectionery/ConfectioneryClientApp/Models/ErrorViewModel.cs index 6238b7c..7e19d8d 100644 --- a/Confectionery/ConfectioneryClientApp/Models/ErrorViewModel.cs +++ b/Confectionery/ConfectioneryClientApp/Models/ErrorViewModel.cs @@ -3,7 +3,6 @@ namespace ConfectioneryClientApp.Models public class ErrorViewModel { public string? RequestId { get; set; } - public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); } } diff --git a/Confectionery/ConfectioneryClientApp/Program.cs b/Confectionery/ConfectioneryClientApp/Program.cs index 0727468..5ac26d4 100644 --- a/Confectionery/ConfectioneryClientApp/Program.cs +++ b/Confectionery/ConfectioneryClientApp/Program.cs @@ -1,15 +1,19 @@ +using ConfectioneryClientApp; + var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllersWithViews(); var app = builder.Build(); +APIClient.Connect(builder.Configuration); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/Home/Error"); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + // The default HSTS value is 30 days. You may want to change + // this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } diff --git a/Confectionery/ConfectioneryClientApp/Properties/launchSettings.json b/Confectionery/ConfectioneryClientApp/Properties/launchSettings.json index 3f8bdc1..75419ab 100644 --- a/Confectionery/ConfectioneryClientApp/Properties/launchSettings.json +++ b/Confectionery/ConfectioneryClientApp/Properties/launchSettings.json @@ -9,16 +9,7 @@ } }, "profiles": { - "http": { - "commandName": "Project", - "dotnetRunMessages": true, - "launchBrowser": true, - "applicationUrl": "http://localhost:5290", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "https": { + "ConfectioneryClientApp": { "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, diff --git a/Confectionery/ConfectioneryClientApp/Views/Home/Create.cshtml b/Confectionery/ConfectioneryClientApp/Views/Home/Create.cshtml new file mode 100644 index 0000000..ab60f97 --- /dev/null +++ b/Confectionery/ConfectioneryClientApp/Views/Home/Create.cshtml @@ -0,0 +1,56 @@ +@{ + ViewData["Title"] = "Создание заказа"; +} +
+

Создание заказа

+
+
+
+
Кондитерское изделие:
+
+ +
+
+
+
Количество:
+
+ +
+
+
+
Сумма:
+
+ +
+
+
+
+
+ +
+
+
+ diff --git a/Confectionery/ConfectioneryClientApp/Views/Home/Enter.cshtml b/Confectionery/ConfectioneryClientApp/Views/Home/Enter.cshtml new file mode 100644 index 0000000..22a10d4 --- /dev/null +++ b/Confectionery/ConfectioneryClientApp/Views/Home/Enter.cshtml @@ -0,0 +1,21 @@ +@{ + ViewData["Title"] = "Вход в приложение"; +} +
+

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

+
+
+
+
Логин:
+
+
+
+
Пароль:
+
+
+
+
+
+
+
diff --git a/Confectionery/ConfectioneryClientApp/Views/Home/Index.cshtml b/Confectionery/ConfectioneryClientApp/Views/Home/Index.cshtml index bcfd79a..2781785 100644 --- a/Confectionery/ConfectioneryClientApp/Views/Home/Index.cshtml +++ b/Confectionery/ConfectioneryClientApp/Views/Home/Index.cshtml @@ -1,8 +1,75 @@ -@{ - ViewData["Title"] = "Home Page"; +@using ConfectioneryContracts.ViewModels +@model List +@{ + ViewData["Title"] = "Главная страница"; } -
-

Welcome

-

Learn about building Web apps with ASP.NET Core.

+

Заказы

+
+ @{ + if (Model == null) + { +

Авторизируйтесь

+ return; + } +

+ Создать заказ +

+ + + + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + + + } + +
+ Номер + + Кондитерское изделие + + Дата создания + + Количество + + Сумма + + Статус +
+ @Html.DisplayFor(modelItem => + item.Id) + + @Html.DisplayFor(modelItem => + item.PastryName) + + @Html.DisplayFor(modelItem => + item.DateCreate) + + @Html.DisplayFor(modelItem => + item.Count) + + @Html.DisplayFor(modelItem => + item.Sum) + + @Html.DisplayFor(modelItem => + item.Status) +
+ } +
\ No newline at end of file diff --git a/Confectionery/ConfectioneryClientApp/Views/Home/Privacy.cshtml b/Confectionery/ConfectioneryClientApp/Views/Home/Privacy.cshtml index af4fb19..34c9d31 100644 --- a/Confectionery/ConfectioneryClientApp/Views/Home/Privacy.cshtml +++ b/Confectionery/ConfectioneryClientApp/Views/Home/Privacy.cshtml @@ -1,6 +1,35 @@ -@{ - ViewData["Title"] = "Privacy Policy"; +@using ConfectioneryContracts.ViewModels +@model ClientViewModel +@{ + ViewData["Title"] = "Личные данные"; } -

@ViewData["Title"]

- -

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

+
+

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

+
+
+
+
Логин:
+
+ +
+
+
+
Пароль:
+
+ +
+
+
+
ФИО:
+
+ +
+
+
+
+
+ +
+
+
\ No newline at end of file diff --git a/Confectionery/ConfectioneryClientApp/Views/Home/Register.cshtml b/Confectionery/ConfectioneryClientApp/Views/Home/Register.cshtml new file mode 100644 index 0000000..10020f6 --- /dev/null +++ b/Confectionery/ConfectioneryClientApp/Views/Home/Register.cshtml @@ -0,0 +1,26 @@ +@{ + ViewData["Title"] = "Регистрация"; +} +
+

Регистрация

+
+
+
+
Логин:
+
+
+
+
Пароль:
+
+
+
+
ФИО:
+
+
+
+
+
+ +
+
+
\ No newline at end of file diff --git a/Confectionery/ConfectioneryClientApp/Views/Shared/Error.cshtml b/Confectionery/ConfectioneryClientApp/Views/Shared/Error.cshtml index a1e0478..d8b3c8c 100644 --- a/Confectionery/ConfectioneryClientApp/Views/Shared/Error.cshtml +++ b/Confectionery/ConfectioneryClientApp/Views/Shared/Error.cshtml @@ -1,6 +1,6 @@ @model ErrorViewModel @{ - ViewData["Title"] = "Error"; + ViewData["Title"] = "Ошибка"; }

Error.

diff --git a/Confectionery/ConfectioneryClientApp/Views/Shared/_Layout.cshtml b/Confectionery/ConfectioneryClientApp/Views/Shared/_Layout.cshtml index 92169de..dab21c2 100644 --- a/Confectionery/ConfectioneryClientApp/Views/Shared/_Layout.cshtml +++ b/Confectionery/ConfectioneryClientApp/Views/Shared/_Layout.cshtml @@ -3,27 +3,34 @@ - @ViewData["Title"] - ConfectioneryClientApp + @ViewData["Title"] - Кондитерская - - + + +
-