diff --git a/BeautySalonView/ClientWebApp/Controllers/HomeController.cs b/BeautySalonView/ClientWebApp/Controllers/HomeController.cs index 8a27f17..3e28200 100644 --- a/BeautySalonView/ClientWebApp/Controllers/HomeController.cs +++ b/BeautySalonView/ClientWebApp/Controllers/HomeController.cs @@ -1,8 +1,11 @@ -using ClientApp.Models; +using BeautySalonContracts.BindingModels; +using BeautySalonContracts.ViewModels; +using BeutySalonClientApp.Models; +using BeutySalonClientApp; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; -namespace ClientApp.Controllers +namespace BeutySalonClientApp.Controllers { public class HomeController : Controller { @@ -13,12 +16,142 @@ namespace ClientApp.Controllers _logger = logger; } - public IActionResult Index() + public IActionResult Enter() { return View(); } - public IActionResult Privacy() + [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"); + } + public IActionResult Procedure(int page) + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + if (page == 0) + { + page = 1; + } + ViewBag.Procedure = APIClient.GetRequest> + ($"api/procedure/getmany?userId={APIClient.Client.Id}&page={page}"); + ViewBag.Page = page; + ViewBag.NumberOfPages = APIClient.GetRequest + ($"api/procedure/getnumberofpages?userId={APIClient.Client.Id}"); + return View(); + } + public IActionResult Register() + { + return View(); + } + + [HttpPost] + public void Register(string login, string fio, string password, string email) + { + if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(fio) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(email)) + { + throw new Exception("Введите логин, пароль и ФИО"); + } + APIClient.PostRequest("api/client/register", new ClientBindingModel + { + ClientLogin = login, + ClientFIO = fio, + ClientEmail = email, + ClientPassword = password + }); + Response.Redirect("Enter"); + return; + } + + public IActionResult Order(int page) + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + if (page == 0) + { + page = 1; + } + ViewBag.Order = APIClient.GetRequest> + ($"api/order/getmany?userId={APIClient.Client.Id}&page={page}"); + ViewBag.Page = page; + ViewBag.NumberOfPages = APIClient.GetRequest + ($"api/order/getnumberofpages?userId={APIClient.Client.Id}"); + return View(); + } + + public IActionResult Evaluation(int page) + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + if (page == 0) + { + page = 1; + } + ViewBag.Rating = APIClient.GetRequest> + ($"api/rating/getmany?userId={APIClient.Client.Id}&page={page}"); + ViewBag.Page = page; + ViewBag.NumberOfPages = APIClient.GetRequest + ($"api/rating/getnumberofpages?userId={APIClient.Client.Id}"); + return View(); + } + + public IActionResult Index() + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + return View(); + } + + public IActionResult FormationOrder() + { + return View(); + } + + public IActionResult FormingAnRating() + { + return View(); + } + + public IActionResult LinkingProceduresForSelectedOrders() + { + return View(); + } + + public IActionResult ServiceList() + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.IsAllowed = true; + return View(); + } + + + public IActionResult OrderFormationAccordingProcedures() + { + return View(); + } + + public IActionResult Report() { return View(); } @@ -28,5 +161,6 @@ namespace ClientApp.Controllers { return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); } + } -} +} \ No newline at end of file diff --git a/BeautySalonView/ClientWebApp/Controllers/OrderController.cs b/BeautySalonView/ClientWebApp/Controllers/OrderController.cs index 60c8b65..e2a0023 100644 --- a/BeautySalonView/ClientWebApp/Controllers/OrderController.cs +++ b/BeautySalonView/ClientWebApp/Controllers/OrderController.cs @@ -1,83 +1,96 @@ -using Microsoft.AspNetCore.Http; +using BeautySalonContracts.BindingModels; +using BeautySalonContracts.ViewModels; +using BeutySalonClientApp; using Microsoft.AspNetCore.Mvc; -namespace ClientApp.Controllers +namespace BeutySalonClientApp.Controllers { public class OrderController : Controller { - // GET: OrderController - public ActionResult Index() + public IActionResult Create() { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } return View(); } - // GET: OrderController/Details/5 - public ActionResult Details(int id) - { - return View(); - } - - // GET: OrderController/Create - public ActionResult Create() - { - return View(); - } - - // POST: OrderController/Create [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult Create(IFormCollection collection) + public void Create([FromBody] OrderBindingModel orderModel) { - try + if (APIClient.Client == null) { - return RedirectToAction(nameof(Index)); - } - catch - { - return View(); + throw new Exception("403"); } + orderModel.ClientId = APIClient.Client.Id; + APIClient.PostRequest("api/order/create", orderModel); } - // GET: OrderController/Edit/5 - public ActionResult Edit(int id) + public IActionResult Update(int id) { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Id = id; return View(); } - // POST: OrderController/Edit/5 [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult Edit(int id, IFormCollection collection) + public void Update([FromBody] OrderBindingModel orderModel) { - try + if (APIClient.Client == null) { - return RedirectToAction(nameof(Index)); - } - catch - { - return View(); + throw new Exception("403"); } + orderModel.ClientId = APIClient.Client.Id; + APIClient.PostRequest("api/order/update", orderModel); } - // GET: OrderController/Delete/5 - public ActionResult Delete(int id) + [HttpPost] + public void Delete(int id) { - return View(); + if (APIClient.Client == null) + { + return; + } + APIClient.PostRequest($"api/order/delete", + new OrderBindingModel() { Id = id }); + return; } - // POST: OrderController/Delete/5 - [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult Delete(int id, IFormCollection collection) + [HttpGet] + public List? GetAllServices() { - try + if (APIClient.Client == null) { - return RedirectToAction(nameof(Index)); + throw new Exception("403"); } - catch + var services = APIClient.GetRequest>($"api/service/getall"); + return services; + } + + public OrderViewModel? Get(int id) + { + if (APIClient.Client == null) { - return View(); + return new(); } + OrderViewModel? order = APIClient + .GetRequest($"api/order/get?id={id}"); + return order; + } + + public List? GetAllByUser() + { + if (APIClient.Client == null) + { + return new(); + } + List? order = APIClient + .GetRequest>($"api/order/GetAllByUser?userId={APIClient.Client.Id}"); + return order; } } } diff --git a/BeautySalonView/ClientWebApp/Controllers/ProcedureController.cs b/BeautySalonView/ClientWebApp/Controllers/ProcedureController.cs index 5be0ff5..b5075a5 100644 --- a/BeautySalonView/ClientWebApp/Controllers/ProcedureController.cs +++ b/BeautySalonView/ClientWebApp/Controllers/ProcedureController.cs @@ -1,83 +1,96 @@ -using Microsoft.AspNetCore.Http; +using BeautySalonContracts.BindingModels; +using BeautySalonContracts.ViewModels; +using BeutySalonClientApp; using Microsoft.AspNetCore.Mvc; -namespace ClientApp.Controllers +namespace BeutySalonClientApp.Controllers { public class ProcedureController : Controller { - // GET: ProcedureController - public ActionResult Index() + public IActionResult Create() { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } return View(); } - // GET: ProcedureController/Details/5 - public ActionResult Details(int id) - { - return View(); - } - - // GET: ProcedureController/Create - public ActionResult Create() - { - return View(); - } - - // POST: ProcedureController/Create [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult Create(IFormCollection collection) + public void Create([FromBody] ProcedureBindingModel procedureModel) { - try + if (APIClient.Client == null) { - return RedirectToAction(nameof(Index)); - } - catch - { - return View(); + throw new Exception("403"); } + procedureModel.ClientId = APIClient.Client.Id; + APIClient.PostRequest("api/procedure/create", procedureModel); } - // GET: ProcedureController/Edit/5 - public ActionResult Edit(int id) + public IActionResult Update(int id) { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Id = id; return View(); } - // POST: ProcedureController/Edit/5 [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult Edit(int id, IFormCollection collection) + public void Update([FromBody] ProcedureBindingModel procedureModel) { - try + if (APIClient.Client == null) { - return RedirectToAction(nameof(Index)); - } - catch - { - return View(); + throw new Exception("403"); } + procedureModel.ClientId = APIClient.Client.Id; + APIClient.PostRequest("api/procedure/update", procedureModel); } - // GET: ProcedureController/Delete/5 - public ActionResult Delete(int id) + [HttpPost] + public void Delete(int id) { - return View(); + if (APIClient.Client == null) + { + return; + } + APIClient.PostRequest($"api/procedure/delete", + new ProcedureBindingModel() { Id = id }); + return; } - // POST: ProcedureController/Delete/5 - [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult Delete(int id, IFormCollection collection) + [HttpGet] + public List? GetAllCosmetics() { - try + if (APIClient.Client == null) { - return RedirectToAction(nameof(Index)); + throw new Exception("403"); } - catch + var cosmetics = APIClient.GetRequest>($"api/cosmetic/getall"); + return cosmetics; + } + + public ProcedureViewModel? Get(int id) + { + if (APIClient.Client == null) { - return View(); + return new(); } + ProcedureViewModel? procedure = APIClient + .GetRequest($"api/procedure/get?id={id}"); + return procedure; + } + + public List? GetAllByUser() + { + if (APIClient.Client == null) + { + return new(); + } + List? procedures = APIClient.GetRequest> + ($"api/procedure/getallbyuser?userId={APIClient.Client.Id}"); + return procedures; } } } diff --git a/BeautySalonView/ClientWebApp/Models/ErrorViewModel.cs b/BeautySalonView/ClientWebApp/Models/ErrorViewModel.cs index 4441fee..5a48625 100644 --- a/BeautySalonView/ClientWebApp/Models/ErrorViewModel.cs +++ b/BeautySalonView/ClientWebApp/Models/ErrorViewModel.cs @@ -1,4 +1,4 @@ -namespace ClientApp.Models +namespace BeutySalonClientApp.Models { public class ErrorViewModel { @@ -6,4 +6,4 @@ namespace ClientApp.Models public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); } -} +} \ No newline at end of file diff --git a/BeautySalonView/ClientWebApp/Program.cs b/BeautySalonView/ClientWebApp/Program.cs index 0727468..3818527 100644 --- a/BeautySalonView/ClientWebApp/Program.cs +++ b/BeautySalonView/ClientWebApp/Program.cs @@ -1,7 +1,10 @@ +using BeutySalonClientApp; + var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllersWithViews(); +APIClient.Connect(builder.Configuration); var app = builder.Build(); diff --git a/BeautySalonView/ClientWebApp/Views/Home/Index.cshtml b/BeautySalonView/ClientWebApp/Views/Home/Index.cshtml index d2d19bd..29418f1 100644 --- a/BeautySalonView/ClientWebApp/Views/Home/Index.cshtml +++ b/BeautySalonView/ClientWebApp/Views/Home/Index.cshtml @@ -1,8 +1,8 @@ @{ - ViewData["Title"] = "Home Page"; + ViewData["Title"] = "HomePage"; } +

Мы Вас не ждали, зло пожаловать!

-

Welcome

-

Learn about building Web apps with ASP.NET Core.

-
+

Logo

+ \ No newline at end of file