From a6b496e8e102403ea23f92b8c5709f598218f13f Mon Sep 17 00:00:00 2001
From: ValAnn
Date: Tue, 9 Apr 2024 17:15:42 +0400
Subject: [PATCH] complete
---
.../Controllers/HomeController.cs | 163 +++++++++++++++---
SushiBar/SushiBarClientApp/Program.cs | 20 +--
.../Views/Home/Create.cshtml | 50 ++++++
.../SushiBarClientApp/Views/Home/Enter.cshtml | 21 +++
.../SushiBarClientApp/Views/Home/Index.cshtml | 75 +++++++-
.../Views/Home/Privacy.cshtml | 32 +++-
.../Views/Home/Register.cshtml | 25 +++
.../Views/Shared/Error.cshtml | 2 +-
.../Views/Shared/_Layout.cshtml | 18 +-
SushiBar/SushiBarClientApp/appsettings.json | 2 +-
.../Implements/OrderStorage.cs | 8 +-
.../SushiBarDatabaseImplement/Models/Order.cs | 2 +
.../DataFileSingleton.cs | 3 +-
.../Implements/OrderStorage.cs | 6 +-
.../SushiBarFileImplement/Models/Client.cs | 2 +-
.../Controllers/MainController.cs | 19 +-
.../Controllers/WeatherForecastController.cs | 33 ----
SushiBar/SushiBarRestApi/WeatherForecast.cs | 13 --
18 files changed, 379 insertions(+), 115 deletions(-)
create mode 100644 SushiBar/SushiBarClientApp/Views/Home/Create.cshtml
create mode 100644 SushiBar/SushiBarClientApp/Views/Home/Enter.cshtml
create mode 100644 SushiBar/SushiBarClientApp/Views/Home/Register.cshtml
delete mode 100644 SushiBar/SushiBarRestApi/Controllers/WeatherForecastController.cs
delete mode 100644 SushiBar/SushiBarRestApi/WeatherForecast.cs
diff --git a/SushiBar/SushiBarClientApp/Controllers/HomeController.cs b/SushiBar/SushiBarClientApp/Controllers/HomeController.cs
index ab45248..b39499e 100644
--- a/SushiBar/SushiBarClientApp/Controllers/HomeController.cs
+++ b/SushiBar/SushiBarClientApp/Controllers/HomeController.cs
@@ -1,32 +1,153 @@
using Microsoft.AspNetCore.Mvc;
+using SushiBar.BindingModels;
+using SushiBar.ViewModels;
using SushiBarClientApp.Models;
+using SushiBarContracts.BindingModels;
+using SushiBarContracts.ViewModels;
using System.Diagnostics;
namespace SushiBarClientApp.Controllers
{
public class HomeController : Controller
{
- private readonly ILogger _logger;
-
- public HomeController(ILogger logger)
- {
- _logger = logger;
+ 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.Sushis =
+ APIClient.GetRequest>("api/main/getsushilist");
+ return View();
+ }
+ [HttpPost]
+ public void Create(int sushi, 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,
+ SushiId = sushi,
+ Count = count,
+ Sum = Calc(count, sushi)
+ });
+ Response.Redirect("Index");
+ }
+ [HttpPost]
+ public double Calc(int count, int sushi)
+ {
+ var prod =
+ APIClient.GetRequest($"api/main/getsushi?sushiId={sushi}"
+ );
+ return count * (prod?.Price ?? 1);
+ }
}
- public IActionResult Index()
- {
- return View();
- }
-
- public IActionResult Privacy()
- {
- return View();
- }
-
- [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
- public IActionResult Error()
- {
- return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
- }
}
-}
+
diff --git a/SushiBar/SushiBarClientApp/Program.cs b/SushiBar/SushiBarClientApp/Program.cs
index 0727468..7af7aa1 100644
--- a/SushiBar/SushiBarClientApp/Program.cs
+++ b/SushiBar/SushiBarClientApp/Program.cs
@@ -1,27 +1,23 @@
+using SushiBarClientApp;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using SushiBarClientApp;
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 sushiion scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
-
app.UseHttpsRedirection();
app.UseStaticFiles();
-
app.UseRouting();
-
app.UseAuthorization();
-
app.MapControllerRoute(
- name: "default",
- pattern: "{controller=Home}/{action=Index}/{id?}");
-
-app.Run();
+ name: "default",
+ pattern: "{controller=Home}/{action=Index}/{id?}");
+app.Run();
\ No newline at end of file
diff --git a/SushiBar/SushiBarClientApp/Views/Home/Create.cshtml b/SushiBar/SushiBarClientApp/Views/Home/Create.cshtml
new file mode 100644
index 0000000..3045f71
--- /dev/null
+++ b/SushiBar/SushiBarClientApp/Views/Home/Create.cshtml
@@ -0,0 +1,50 @@
+@{
+ ViewData["Title"] = "Create";
+}
+
+
Создание заказа
+
+
+
+
\ No newline at end of file
diff --git a/SushiBar/SushiBarClientApp/Views/Home/Enter.cshtml b/SushiBar/SushiBarClientApp/Views/Home/Enter.cshtml
new file mode 100644
index 0000000..106d3d5
--- /dev/null
+++ b/SushiBar/SushiBarClientApp/Views/Home/Enter.cshtml
@@ -0,0 +1,21 @@
+@{
+ ViewData["Title"] = "Enter";
+}
+
+
+
Вход в приложение
+
+
\ No newline at end of file
diff --git a/SushiBar/SushiBarClientApp/Views/Home/Index.cshtml b/SushiBar/SushiBarClientApp/Views/Home/Index.cshtml
index d2d19bd..843135f 100644
--- a/SushiBar/SushiBarClientApp/Views/Home/Index.cshtml
+++ b/SushiBar/SushiBarClientApp/Views/Home/Index.cshtml
@@ -1,8 +1,75 @@
-@{
- ViewData["Title"] = "Home Page";
+@using SushiBarContracts.ViewModels
+
+@model List
+
+@{
+ ViewData["Title"] = "Home Page";
}
+
+
+
+ @{
+ if (Model == null)
+ {
+
Авторизируйтесь
+ return;
+ }
+
+
+ Создать заказ
+
+
+
+
+
+ Номер
+
+
+ Суши
+
+
+ Дата создания
+
+
+ Количество
+
+
+ Сумма
+
+
+ Статус
+
+
+
+
+ @foreach (var item in Model)
+ {
+
+
+ @Html.DisplayFor(modelItem => item.Id)
+
+
+ @Html.DisplayFor(modelItem => item.SushiName)
+
+
+ @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/SushiBar/SushiBarClientApp/Views/Home/Privacy.cshtml b/SushiBar/SushiBarClientApp/Views/Home/Privacy.cshtml
index af4fb19..3928c4e 100644
--- a/SushiBar/SushiBarClientApp/Views/Home/Privacy.cshtml
+++ b/SushiBar/SushiBarClientApp/Views/Home/Privacy.cshtml
@@ -1,6 +1,28 @@
-@{
- ViewData["Title"] = "Privacy Policy";
-}
-@ViewData["Title"]
+@using SushiBar.ViewModels
+@using SushiBarContracts.ViewModels
+@model ClientViewModel
-Use this page to detail your site's privacy policy.
+@{
+ ViewData["Title"] = "Privacy Policy";
+}
+
+
Личные данные
+
+
\ No newline at end of file
diff --git a/SushiBar/SushiBarClientApp/Views/Home/Register.cshtml b/SushiBar/SushiBarClientApp/Views/Home/Register.cshtml
new file mode 100644
index 0000000..398b516
--- /dev/null
+++ b/SushiBar/SushiBarClientApp/Views/Home/Register.cshtml
@@ -0,0 +1,25 @@
+@{
+ ViewData["Title"] = "Register";
+}
+
+
+
Регистрация
+
+
\ No newline at end of file
diff --git a/SushiBar/SushiBarClientApp/Views/Shared/Error.cshtml b/SushiBar/SushiBarClientApp/Views/Shared/Error.cshtml
index a1e0478..4d96f6a 100644
--- a/SushiBar/SushiBarClientApp/Views/Shared/Error.cshtml
+++ b/SushiBar/SushiBarClientApp/Views/Shared/Error.cshtml
@@ -22,4 +22,4 @@
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development
and restarting the app.
-
+
\ No newline at end of file
diff --git a/SushiBar/SushiBarClientApp/Views/Shared/_Layout.cshtml b/SushiBar/SushiBarClientApp/Views/Shared/_Layout.cshtml
index 9a420a2..386e637 100644
--- a/SushiBar/SushiBarClientApp/Views/Shared/_Layout.cshtml
+++ b/SushiBar/SushiBarClientApp/Views/Shared/_Layout.cshtml
@@ -7,23 +7,31 @@
+
+
-
SushiBarClientApp
-
Суши-Бар
+
-
+
diff --git a/SushiBar/SushiBarClientApp/appsettings.json b/SushiBar/SushiBarClientApp/appsettings.json
index e9ddbf6..84946e9 100644
--- a/SushiBar/SushiBarClientApp/appsettings.json
+++ b/SushiBar/SushiBarClientApp/appsettings.json
@@ -6,5 +6,5 @@
}
},
"AllowedHosts": "*",
- "IPAddress": "http://localhost:7100/"
+ "IPAddress": "http://localhost:5037/"
}
\ No newline at end of file
diff --git a/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs b/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs
index 1295e61..33306be 100644
--- a/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs
+++ b/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs
@@ -22,10 +22,6 @@ namespace SushiBarDatabaseImplement.Implements
public List
GetFilteredList(OrderSearchModel model)
{
- if (!model.DateFrom.HasValue || !model.DateTo.HasValue)
- {
- return new();
- }
using var context = new SushiBarDatabase();
if (model.DateFrom.HasValue)
{
@@ -35,6 +31,10 @@ namespace SushiBarDatabaseImplement.Implements
{
return context.Orders.Include(x => x.Sushi).Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList();
}
+ if (model.ClientId.HasValue)
+ {
+ return context.Orders.Include(x => x.Sushi).Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList();
+ }
return context.Orders.Include(x => x.Sushi).Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList();
}
diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Order.cs b/SushiBar/SushiBarDatabaseImplement/Models/Order.cs
index ec89d77..df582eb 100644
--- a/SushiBar/SushiBarDatabaseImplement/Models/Order.cs
+++ b/SushiBar/SushiBarDatabaseImplement/Models/Order.cs
@@ -67,6 +67,8 @@ namespace SushiBarDatabaseImplement.Models
public OrderViewModel GetViewModel => new()
{
Id = Id,
+ ClientId = ClientId,
+ ClientFIO = Client.ClientFIO,
SushiId = SushiId,
SushiName = Sushi.SushiName,
Count = Count,
diff --git a/SushiBar/SushiBarFileImplement/DataFileSingleton.cs b/SushiBar/SushiBarFileImplement/DataFileSingleton.cs
index 51e7da2..cec1f78 100644
--- a/SushiBar/SushiBarFileImplement/DataFileSingleton.cs
+++ b/SushiBar/SushiBarFileImplement/DataFileSingleton.cs
@@ -1,5 +1,4 @@
-using PizzeriaFileImplement.Models;
-using SushiBarFileImplement.Models;
+using SushiBarFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
diff --git a/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs b/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs
index ab01272..748f870 100644
--- a/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs
+++ b/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs
@@ -105,12 +105,12 @@ namespace SushiBarFileImplement.Implements
{
var viewModel = order.GetViewModel;
- var pizza = source.Sushis.FirstOrDefault(x => x.Id == order.SushiId);
+ var sushi = source.Sushis.FirstOrDefault(x => x.Id == order.SushiId);
var client = source.Clients.FirstOrDefault(x => x.Id == order.ClientId);
- if (pizza != null)
+ if (sushi != null)
{
- viewModel.SushiName = pizza.SushiName;
+ viewModel.SushiName = sushi.SushiName;
}
if (client != null)
{
diff --git a/SushiBar/SushiBarFileImplement/Models/Client.cs b/SushiBar/SushiBarFileImplement/Models/Client.cs
index cbc109f..0c91fc0 100644
--- a/SushiBar/SushiBarFileImplement/Models/Client.cs
+++ b/SushiBar/SushiBarFileImplement/Models/Client.cs
@@ -5,7 +5,7 @@ using SushiBarContracts.ViewModels;
using SushiBarDataModels.Models;
using System.Xml.Linq;
-namespace PizzeriaFileImplement.Models
+namespace SushiBarFileImplement.Models
{
public class Client : IClientModel
{
diff --git a/SushiBar/SushiBarRestApi/Controllers/MainController.cs b/SushiBar/SushiBarRestApi/Controllers/MainController.cs
index e18810a..624a281 100644
--- a/SushiBar/SushiBarRestApi/Controllers/MainController.cs
+++ b/SushiBar/SushiBarRestApi/Controllers/MainController.cs
@@ -13,19 +13,19 @@ namespace SushiBarRestApi.Controllers
{
private readonly ILogger _logger;
private readonly IOrderLogic _order;
- private readonly ISushiLogic _product;
- public MainController(ILogger logger, IOrderLogic order, ISushiLogic product)
+ private readonly ISushiLogic _sushi;
+ public MainController(ILogger logger, IOrderLogic order, ISushiLogic sushi)
{
_logger = logger;
_order = order;
- _product = product;
+ _sushi = sushi;
}
[HttpGet]
- public List? GetProductList()
+ public List? GetSushiList()
{
try
{
- return _product.ReadList(null);
+ return _sushi.ReadList(null);
}
catch (Exception ex)
{
@@ -34,20 +34,19 @@ namespace SushiBarRestApi.Controllers
}
}
[HttpGet]
- public SushiViewModel? GetProduct(int productId)
+ public SushiViewModel? GetSushi(int sushiId)
{
try
{
- return _product.ReadElement(new SushiSearchModel
+ return _sushi.ReadElement(new SushiSearchModel
{
Id =
- productId
+ sushiId
});
}
catch (Exception ex)
{
- _logger.LogError(ex, "Ошибка получения продукта по id={Id}",
- productId);
+ _logger.LogError(ex, "Ошибка получения продукта по id={Id}", sushiId);
throw;
}
}
diff --git a/SushiBar/SushiBarRestApi/Controllers/WeatherForecastController.cs b/SushiBar/SushiBarRestApi/Controllers/WeatherForecastController.cs
deleted file mode 100644
index 203aa6c..0000000
--- a/SushiBar/SushiBarRestApi/Controllers/WeatherForecastController.cs
+++ /dev/null
@@ -1,33 +0,0 @@
-using Microsoft.AspNetCore.Mvc;
-
-namespace SushiBarRestApi.Controllers
-{
- [ApiController]
- [Route("[controller]")]
- public class WeatherForecastController : ControllerBase
- {
- private static readonly string[] Summaries = new[]
- {
- "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
- };
-
- private readonly ILogger _logger;
-
- public WeatherForecastController(ILogger logger)
- {
- _logger = logger;
- }
-
- [HttpGet(Name = "GetWeatherForecast")]
- public IEnumerable Get()
- {
- return Enumerable.Range(1, 5).Select(index => new WeatherForecast
- {
- Date = DateTime.Now.AddDays(index),
- TemperatureC = Random.Shared.Next(-20, 55),
- Summary = Summaries[Random.Shared.Next(Summaries.Length)]
- })
- .ToArray();
- }
- }
-}
diff --git a/SushiBar/SushiBarRestApi/WeatherForecast.cs b/SushiBar/SushiBarRestApi/WeatherForecast.cs
deleted file mode 100644
index 0dac3b7..0000000
--- a/SushiBar/SushiBarRestApi/WeatherForecast.cs
+++ /dev/null
@@ -1,13 +0,0 @@
-namespace SushiBarRestApi
-{
- public class WeatherForecast
- {
- public DateTime Date { get; set; }
-
- public int TemperatureC { get; set; }
-
- public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
-
- public string? Summary { get; set; }
- }
-}