complete lab 5
This commit is contained in:
parent
55afd631fe
commit
bf2b86f897
@ -15,7 +15,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushibarListImplement", "Su
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarFileImplement", "SushiBarFileImplement\SushiBarFileImplement.csproj", "{E55FF400-876B-4E35-8536-E099241195B8}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarDatabaseImplement", "SushiBarDatabaseImplement\SushiBarDatabaseImplement.csproj", "{4E59EEFE-0146-4AFB-BA8C-18F2D8F8D22D}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarDatabaseImplement", "SushiBarDatabaseImplement\SushiBarDatabaseImplement.csproj", "{4E59EEFE-0146-4AFB-BA8C-18F2D8F8D22D}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarRestApi", "SushiBarRestApi\SushiBarRestApi.csproj", "{0ADB6C71-701C-43A7-869C-A92D7C36C4EC}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarClientApi", "SushiBarClientApi\SushiBarClientApi.csproj", "{BF58D50B-0408-4124-8CD3-1D5DFEE83104}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -51,6 +55,14 @@ Global
|
||||
{4E59EEFE-0146-4AFB-BA8C-18F2D8F8D22D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4E59EEFE-0146-4AFB-BA8C-18F2D8F8D22D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4E59EEFE-0146-4AFB-BA8C-18F2D8F8D22D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0ADB6C71-701C-43A7-869C-A92D7C36C4EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0ADB6C71-701C-43A7-869C-A92D7C36C4EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0ADB6C71-701C-43A7-869C-A92D7C36C4EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0ADB6C71-701C-43A7-869C-A92D7C36C4EC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{BF58D50B-0408-4124-8CD3-1D5DFEE83104}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BF58D50B-0408-4124-8CD3-1D5DFEE83104}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BF58D50B-0408-4124-8CD3-1D5DFEE83104}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BF58D50B-0408-4124-8CD3-1D5DFEE83104}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
16
SushiBar/SushiBar/FormMain.Designer.cs
generated
16
SushiBar/SushiBar/FormMain.Designer.cs
generated
@ -42,6 +42,7 @@
|
||||
this.buttonReady = new System.Windows.Forms.Button();
|
||||
this.buttonIssue = new System.Windows.Forms.Button();
|
||||
this.buttonReload = new System.Windows.Forms.Button();
|
||||
this.clientsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.menuStrip1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
@ -70,7 +71,8 @@
|
||||
//
|
||||
this.directoryToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.componentsToolStripMenuItem,
|
||||
this.sushiToolStripMenuItem});
|
||||
this.sushiToolStripMenuItem,
|
||||
this.clientsToolStripMenuItem});
|
||||
this.directoryToolStripMenuItem.Name = "directoryToolStripMenuItem";
|
||||
this.directoryToolStripMenuItem.Size = new System.Drawing.Size(67, 20);
|
||||
this.directoryToolStripMenuItem.Text = "Directory";
|
||||
@ -78,14 +80,14 @@
|
||||
// componentsToolStripMenuItem
|
||||
//
|
||||
this.componentsToolStripMenuItem.Name = "componentsToolStripMenuItem";
|
||||
this.componentsToolStripMenuItem.Size = new System.Drawing.Size(143, 22);
|
||||
this.componentsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.componentsToolStripMenuItem.Text = "Components";
|
||||
this.componentsToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click);
|
||||
//
|
||||
// sushiToolStripMenuItem
|
||||
//
|
||||
this.sushiToolStripMenuItem.Name = "sushiToolStripMenuItem";
|
||||
this.sushiToolStripMenuItem.Size = new System.Drawing.Size(143, 22);
|
||||
this.sushiToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.sushiToolStripMenuItem.Text = "Sushi";
|
||||
this.sushiToolStripMenuItem.Click += new System.EventHandler(this.SushiToolStripMenuItem_Click);
|
||||
//
|
||||
@ -170,6 +172,13 @@
|
||||
this.buttonReload.UseVisualStyleBackColor = true;
|
||||
this.buttonReload.Click += new System.EventHandler(this.ButtonReload_Click);
|
||||
//
|
||||
// clientsToolStripMenuItem
|
||||
//
|
||||
this.clientsToolStripMenuItem.Name = "clientsToolStripMenuItem";
|
||||
this.clientsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.clientsToolStripMenuItem.Text = "Clients";
|
||||
this.clientsToolStripMenuItem.Click += new System.EventHandler(this.ClientsToolStripMenuItem_Click);
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
@ -210,5 +219,6 @@
|
||||
private ToolStripMenuItem listComponentsToolStripMenuItem;
|
||||
private ToolStripMenuItem componentsOnSushiToolStripMenuItem;
|
||||
private ToolStripMenuItem listOrdersToolStripMenuItem;
|
||||
private ToolStripMenuItem clientsToolStripMenuItem;
|
||||
}
|
||||
}
|
@ -30,7 +30,8 @@ namespace SushiBar
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["SushiId"].Visible = false;
|
||||
dataGridView.Columns[""]
|
||||
dataGridView.Columns["ClientId"].Visible = false;
|
||||
dataGridView.Columns["ClientFio"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -55,13 +56,14 @@ namespace SushiBar
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
_logger.LogInformation("Order №{id}. Change statuc on -Submit", id);
|
||||
_logger.LogInformation("Order №{id}. Change status on -Submit", id);
|
||||
try
|
||||
{
|
||||
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel {
|
||||
Id = id,
|
||||
SushiId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SushiId"].Value),
|
||||
SushiName = dataGridView.SelectedRows[0].Cells["SushiName"].Value.ToString(),
|
||||
ClientFio = dataGridView.SelectedRows[0].Cells["ClientFio"].Value.ToString(),
|
||||
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
|
||||
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
|
||||
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
|
||||
@ -94,7 +96,8 @@ namespace SushiBar
|
||||
Id = id,
|
||||
SushiId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SushiId"].Value),
|
||||
SushiName = dataGridView.SelectedRows[0].Cells["SushiName"].Value.ToString() ?? "",
|
||||
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString() ?? "Unkown"),
|
||||
ClientFio = dataGridView.SelectedRows[0].Cells["ClientFio"].Value.ToString() ?? "",
|
||||
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString() ?? "Unknown"),
|
||||
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
|
||||
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString() ?? "0"),
|
||||
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString() ?? ""),
|
||||
@ -127,6 +130,7 @@ namespace SushiBar
|
||||
SushiId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SushiId"].Value),
|
||||
SushiName = dataGridView.SelectedRows[0].Cells["SushiName"].Value.ToString(),
|
||||
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
|
||||
ClientFio = dataGridView.SelectedRows[0].Cells["ClientFio"].Value.ToString(),
|
||||
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
|
||||
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
|
||||
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
|
||||
@ -195,7 +199,6 @@ namespace SushiBar
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void ListOrdersToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
@ -205,7 +208,15 @@ namespace SushiBar
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void ClientsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormClients));
|
||||
if (service is FormClients form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -50,6 +50,7 @@ namespace SushiBar
|
||||
services.AddTransient<FormSushiMoreThenOne>();
|
||||
services.AddTransient<FormReportOrders>();
|
||||
services.AddTransient<FormSushiOnComponents>();
|
||||
services.AddTransient<FormClients>();
|
||||
}
|
||||
}
|
||||
}
|
105
SushiBar/SushiBarBusinessLogic/BusinessLogics/ClientLogic.cs
Normal file
105
SushiBar/SushiBarBusinessLogic/BusinessLogics/ClientLogic.cs
Normal file
@ -0,0 +1,105 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarContracts.ViewModels;
|
||||
|
||||
namespace SushiBarBusinessLogic.BusinessLogics;
|
||||
|
||||
public class ClientLogic : IClientLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IClientStorage _clientStorage;
|
||||
|
||||
public ClientLogic(ILogger<ClientLogic> logger, IClientStorage clientStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_clientStorage = clientStorage;
|
||||
}
|
||||
|
||||
public List<ClientViewModel>? ReadList(ClientSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList clients .FIO:{ClientFio} .EMAIL:{Email} .Id:{Id}", model.ClientFio, model.Email, model.Id);
|
||||
var list = _clientStorage.GetFilteredList(model);
|
||||
_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 clients .FIO:{ClientFio} .EMAIL:{Email} .Id:{Id}", model.ClientFio, 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) return true;
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Update(ClientBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_clientStorage.Update(model) != null) return true;
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Delete(ClientBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_clientStorage.Delete(model) != null) return true;
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
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), "FIO must be not null");
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Email))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model.Email), "EMAIL must be not null");
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model.Password), "PASSWORD must be not null");
|
||||
}
|
||||
_logger.LogInformation("Client .FIO:{ClientFio} .EMAIL:{Email} .Password:{Password} .Id:{Id}", model.ClientFio, model.Email, model.Password, model.Id);
|
||||
var client = _clientStorage.GetElement(new ClientSearchModel()
|
||||
{
|
||||
Email = model.Email
|
||||
});
|
||||
if (client != null && client.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Email is already exists");
|
||||
}
|
||||
}
|
||||
}
|
@ -31,12 +31,9 @@ namespace SushiBarBusinessLogic.BusinessLogics
|
||||
|
||||
model.Status = OrderStatus.Accepted;
|
||||
|
||||
if (_orderStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
if (_orderStorage.Insert(model) != null) return true;
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool DeliveryOrder(OrderBindingModel model)
|
||||
|
40
SushiBar/SushiBarClientApi/APIClient.cs
Normal file
40
SushiBar/SushiBarClientApi/APIClient.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using SushiBarContracts.ViewModels;
|
||||
|
||||
namespace SushiBarClientApi;
|
||||
|
||||
public static class APIClient
|
||||
{
|
||||
private static readonly HttpClient _client = new();
|
||||
public static ClientViewModel? Client { get; set; }
|
||||
|
||||
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<T>(string requestUrl)
|
||||
{
|
||||
var response = _client.GetAsync(requestUrl);
|
||||
var result = response.Result.Content.ReadAsStringAsync().Result;
|
||||
if (response.Result.IsSuccessStatusCode)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<T>(result);
|
||||
}
|
||||
throw new Exception(result);
|
||||
}
|
||||
public static void PostRequest<T>(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);
|
||||
}
|
||||
}
|
||||
}
|
60
SushiBar/SushiBarClientApi/Views/Home/Create.cshtml
Normal file
60
SushiBar/SushiBarClientApi/Views/Home/Create.cshtml
Normal file
@ -0,0 +1,60 @@
|
||||
@model SushiBarContracts.ViewModels.SushiViewModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Create";
|
||||
}
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Create order</h2>
|
||||
</div>
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="col-4">Sushi:</div>
|
||||
<div class="col-8">
|
||||
<select
|
||||
id="sushi"
|
||||
name="sushi"
|
||||
class="form-control"
|
||||
asp-items="@ViewBag.Sushi">
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Count:</div>
|
||||
<div class="col-8">
|
||||
<input type="text" name="count" id="count"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Sum:</div>
|
||||
<div class="col-8">
|
||||
<input type="text" id="sum" name="sum" readonly/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4">
|
||||
<input type="submit" value="Create" class="btn btn-primary"/>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<script>
|
||||
$('#sushi').on('change', () => {
|
||||
check();
|
||||
});
|
||||
$('#count').on('change', () => {
|
||||
check();
|
||||
});
|
||||
function check() {
|
||||
const count = $('#count').val();
|
||||
const sushi = $('#sushi').val();
|
||||
console.log()
|
||||
if (count && sushi) {
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: "/Home/Calc",
|
||||
data: { count, sushi },
|
||||
success: (result) => { $("#sum").val(result) }
|
||||
});
|
||||
}
|
||||
}
|
||||
</script>
|
22
SushiBar/SushiBarClientApi/Views/Home/Enter.cshtml
Normal file
22
SushiBar/SushiBarClientApi/Views/Home/Enter.cshtml
Normal file
@ -0,0 +1,22 @@
|
||||
@{
|
||||
ViewData["Title"] = "Enter";
|
||||
}
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Sign in</h2>
|
||||
</div>
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="col-4">Login:</div>
|
||||
<div class="col-8"><input type="text" name="login" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Password:</div>
|
||||
<div class="col-8"><input type="password" name="password" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4">
|
||||
<input type="submit" value="Enter" class="btn btn-primary"/>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
26
SushiBar/SushiBarClientApi/Views/Home/Register.cshtml
Normal file
26
SushiBar/SushiBarClientApi/Views/Home/Register.cshtml
Normal file
@ -0,0 +1,26 @@
|
||||
@{
|
||||
ViewData["Title"] = "Register";
|
||||
}
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Sign up</h2>
|
||||
</div>
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="col-4">Login:</div>
|
||||
<div class="col-8"><input type="text" name="login" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Password:</div>
|
||||
<div class="col-8"><input type="password" name="password" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">FIO:</div>
|
||||
<div class="col-8"><input type="text" name="fio" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4">
|
||||
<input type="submit" value="Register" class="btn btn-primary"/>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
53
SushiBar/SushiBarClientApi/Views/Home/_Layout.cshtml
Normal file
53
SushiBar/SushiBarClientApi/Views/Home/_Layout.cshtml
Normal file
@ -0,0 +1,53 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>@ViewData["Title"] - AbstractShowClientApp</title>
|
||||
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
|
||||
<link rel="stylesheet" href="~/css/site.css" />
|
||||
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bgwhite border-bottom box-shadow mb-3">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" asp-area="" asp-controller="Home" aspaction="Index">Sushi bar</a>
|
||||
<button class="navbar-toggler" type="button" datatoggle="collapse" data-target=".navbar-collapse" ariacontrols="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="navbar-collapse collapse d-sm-inline-flex flex-smrow-reverse">
|
||||
<ul class="navbar-nav flex-grow-1">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Index">Orders</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Privacy">My info</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Enter">Sign in</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Register">Sign up</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
<div class="container">
|
||||
<main role="main" class="pb-3">
|
||||
@RenderBody()
|
||||
</main>
|
||||
</div>
|
||||
<footer class="border-top footer text-muted">
|
||||
<div class="container">
|
||||
© 2023 - SushiBar -
|
||||
<a asp-area="" aspcontroller="Home" asp-action="Privacy">My info</a>
|
||||
</div>
|
||||
</footer>
|
||||
<script src="~/js/site.js" asp-append-version="true"></script>
|
||||
@RenderSection("Scripts", required: false)
|
||||
</body>
|
||||
</html>
|
@ -8,6 +8,7 @@ namespace SushiBarContracts.BindingModels
|
||||
public int Id { get; set; }
|
||||
public int SushiId { get; set; }
|
||||
public int ClientId { get; set; }
|
||||
public string ClientFio { get; set; } = string.Empty;
|
||||
public string SushiName { get; set; } = string.Empty;
|
||||
public int Count { get; set; }
|
||||
public double Sum { get; set; }
|
||||
|
@ -5,4 +5,5 @@ public class ClientSearchModel
|
||||
public int? Id { get; set; }
|
||||
public string? ClientFio { get; set; }
|
||||
public string? Email { get; set; }
|
||||
public string? Password { get; set; }
|
||||
}
|
@ -12,6 +12,9 @@ namespace SushiBarContracts.ViewModels
|
||||
public int SushiId { get; init; }
|
||||
public int ClientId { get; init; }
|
||||
|
||||
[DisplayName("Client FIO")]
|
||||
public string ClientFio { get; init; } = string.Empty;
|
||||
|
||||
[DisplayName("Name of Product")]
|
||||
public string SushiName { get; init; } = string.Empty;
|
||||
|
||||
@ -29,6 +32,5 @@ namespace SushiBarContracts.ViewModels
|
||||
|
||||
[DisplayName("Date Implement")]
|
||||
public DateTime? DateImplement { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushiBarDatabaseImplement.Models;
|
||||
using SushiBarDataModels.Models;
|
||||
|
||||
namespace SushiBarDatabaseImplement.Implements;
|
||||
|
||||
@ -43,12 +42,20 @@ public class ClientStorage : IClientStorage
|
||||
|
||||
public ClientViewModel? GetElement(ClientSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
if (!model.Id.HasValue && string.IsNullOrEmpty(model.Email) && string.IsNullOrEmpty(model.Password))
|
||||
return null;
|
||||
|
||||
using var context = new SushiBarDatabase();
|
||||
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
return context.Clients
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
return context.Clients
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
.FirstOrDefault(x => x.Email == model.Email && x.Password == model.Password)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using SushiBarContracts.BindingModels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarContracts.ViewModels;
|
||||
@ -42,25 +43,18 @@ namespace SushiBarDatabaseImplement.Implements
|
||||
return new List<OrderViewModel>();
|
||||
|
||||
using var context = new SushiBarDatabase();
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return context.Orders
|
||||
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
if (!model.ClientId.HasValue)
|
||||
if (model.ClientId.HasValue)
|
||||
{
|
||||
return context.Orders
|
||||
.Include(x => x.Client)
|
||||
.Where(x => x.ClientId == model.ClientId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
|
||||
return context.Orders
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Include(x => x.Sushi)
|
||||
.Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
@ -10,11 +10,13 @@ namespace SushiBarDatabaseImplement.Models
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Required]
|
||||
public int SushiId { get; private set; }
|
||||
|
||||
[Required]
|
||||
public int ClientId { get; private set; }
|
||||
|
||||
public string SushiName { get; private set; } = string.Empty;
|
||||
|
||||
public string SushiName { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public int Count { get; private set; }
|
||||
@ -41,7 +43,7 @@ namespace SushiBarDatabaseImplement.Models
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Order()
|
||||
return new Order
|
||||
{
|
||||
Id = model.Id,
|
||||
SushiId = model.SushiId,
|
||||
@ -72,17 +74,22 @@ namespace SushiBarDatabaseImplement.Models
|
||||
DateImplement = model.DateImplement;
|
||||
}
|
||||
|
||||
public OrderViewModel GetViewModel => new()
|
||||
public OrderViewModel GetViewModel { get
|
||||
{
|
||||
Id = Id,
|
||||
SushiId = SushiId,
|
||||
SushiName = SushiName,
|
||||
ClientId = ClientId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement
|
||||
};
|
||||
var context = new SushiBarDatabase();
|
||||
return new OrderViewModel
|
||||
{
|
||||
Id = Id,
|
||||
ClientId = ClientId,
|
||||
SushiId = SushiId,
|
||||
Count = Count,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
ClientFio = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFio ?? string.Empty,
|
||||
SushiName = context.Sushi.FirstOrDefault(x => x.Id == SushiId)?.SushiName ?? string.Empty
|
||||
};
|
||||
} }
|
||||
}
|
||||
}
|
||||
|
66
SushiBar/SushiBarRestApi1/Controllers/ClientController.cs
Normal file
66
SushiBar/SushiBarRestApi1/Controllers/ClientController.cs
Normal file
@ -0,0 +1,66 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
|
||||
namespace SushiBarRestApi.Controllers;
|
||||
|
||||
[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, "Error on login");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Register(ClientBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error on registration");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
public void UpdateData(ClientBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error on update");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
75
SushiBar/SushiBarRestApi1/Controllers/MainController.cs
Normal file
75
SushiBar/SushiBarRestApi1/Controllers/MainController.cs
Normal file
@ -0,0 +1,75 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
|
||||
namespace SushiBarRestApi.Controllers;
|
||||
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class MainController : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderLogic _order;
|
||||
private readonly ISushiLogic _sushi;
|
||||
public MainController(ILogger<MainController> logger, IOrderLogic order, ISushiLogic sushi)
|
||||
{
|
||||
_logger = logger;
|
||||
_order = order;
|
||||
_sushi = sushi;
|
||||
}
|
||||
[HttpGet]
|
||||
public List<SushiViewModel>? GetProductList()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _sushi.ReadList(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error on getting list of sushi");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public SushiViewModel? GetProduct(int sushiId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _sushi.ReadElement(new SushiSearchModel() { Id = sushiId });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error getting sushi with id={Id}", sushiId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public List<OrderViewModel>? GetOrders(int clientId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _order.ReadList(new OrderSearchModel { ClientId = clientId
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error getting orders for client with id={Id}", clientId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
public void CreateOrder(OrderBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_order.CreateOrder(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error create order");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
36
SushiBar/SushiBarRestApi1/Program.cs
Normal file
36
SushiBar/SushiBarRestApi1/Program.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using Microsoft.OpenApi.Models;
|
||||
using SushiBarBusinessLogic.BusinessLogics;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarDatabaseImplement.Implements;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Logging.SetMinimumLevel(LogLevel.Trace);
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddTransient<IClientStorage, ClientStorage>();
|
||||
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
|
||||
builder.Services.AddTransient<ISushiStorage, SushiStorage>();
|
||||
|
||||
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
||||
builder.Services.AddTransient<ISushiLogic, SushiLogic>();
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "SushiBarRestApi", 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", "SushiBarRestApi v1"));
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.UseAuthorization();
|
||||
app.MapControllers();
|
||||
app.Run();
|
31
SushiBar/SushiBarRestApi1/Properties/launchSettings.json
Normal file
31
SushiBar/SushiBarRestApi1/Properties/launchSettings.json
Normal file
@ -0,0 +1,31 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:55171",
|
||||
"sslPort": 44388
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"SushiBarRestApi": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "https://localhost:7263;http://localhost:5256",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
20
SushiBar/SushiBarRestApi1/SushiBarRestApi1.csproj
Normal file
20
SushiBar/SushiBarRestApi1/SushiBarRestApi1.csproj
Normal file
@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<RootNamespace>SushiBarRestApi</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SushiBarBusinessLogic\SushiBarBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\SushiBarContracts\SushiBarContracts.csproj" />
|
||||
<ProjectReference Include="..\SushiBarDatabaseImplement\SushiBarDatabaseImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
8
SushiBar/SushiBarRestApi1/appsettings.Development.json
Normal file
8
SushiBar/SushiBarRestApi1/appsettings.Development.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
9
SushiBar/SushiBarRestApi1/appsettings.json
Normal file
9
SushiBar/SushiBarRestApi1/appsettings.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
Loading…
Reference in New Issue
Block a user