using ComputerShopImplementerApp.Models; using ComputerShopContracts.BindingModels; using ComputerShopContracts.ViewModels; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; using ComputerShopDataModels.Models; using Microsoft.Extensions.Hosting; namespace ComputerShopImplementerApp.Controllers { public class HomeController : Controller { private readonly ILogger _logger; public HomeController(ILogger logger) { _logger = logger; } public IActionResult Index() { if (APIUser.User == null) { return Redirect("~/Home/Enter"); } return View(/*APIUser.GetRequest>($"api/main/getorders?userId={APIUser.User.Id}")*/); } [HttpGet] public IActionResult Privacy() { if (APIUser.User == null) { return Redirect("~/Home/Enter"); } return View(APIUser.User); } [HttpGet] public IActionResult CreateComponent() { return View(); } [HttpGet] public IActionResult CreateProduct() { return View(); } [HttpGet] public IActionResult CreateRequest() { List products = new List { new AssemblyViewModel { Id = 1, AssemblyName = "Сборка 1", Cost = 105, UserId = 1 }, new AssemblyViewModel { Id = 2, AssemblyName = "Сборка 2", Cost = 205, UserId = 1 } }; return View(products); } [HttpGet] public IActionResult CreateAssembly() { var components = new List(); components.Add(new ComponentViewModel { Id = 1, ComponentName = "Комплектующее 1", Cost = 55.5, Description = "Описание", UserId = 1 }); components.Add(new ComponentViewModel { Id = 2, ComponentName = "Комплектующее 2", Cost = 15, Description = "Описание", UserId = 1 }); return View(components); } [HttpGet] public IActionResult CreateBatch() { List products = new List { new ProductViewModel { Id = 1, ProductName = "Товар 1", Cost = 10.99, UserId = 1, Description = "Описание", BatchId = 1 }, new ProductViewModel { Id = 1, ProductName = "Товар 1", Cost = 18, UserId = 1, Description = "Описание", BatchId = 2 } }; return View(products); } public IActionResult IndexComponent() { var components = new List(); components.Add(new ComponentViewModel { Id = 1, ComponentName = "Комплектующее 1", Cost = 55.5, Description = "Описание", UserId = 1 }); components.Add(new ComponentViewModel { Id = 2, ComponentName = "Комплектующее 2", Cost = 15, Description = "Описание", UserId = 1 }); return View(components); } public IActionResult IndexProduct() { List products = new List { new ProductViewModel { Id = 1, ProductName = "Товар 1", Cost = 10.99, UserId = 1, Description = "Описание", BatchId = 1 }, new ProductViewModel { Id = 1, ProductName = "Товар 1", Cost = 18, UserId = 1, Description = "Описание", BatchId = 2 } }; return View(products); } [HttpGet] public IActionResult IndexRequest() { List products = new List { new RequestViewModel { Id = 1, AssemblyId = 1 }, new RequestViewModel { Id = 2, AssemblyId = 2 }, }; return View(products); } [HttpGet] public IActionResult IndexAssembly() { List products = new List { new AssemblyViewModel { Id = 1, AssemblyName = "Сборка 1", Cost = 105, UserId = 1 }, new AssemblyViewModel { Id = 2, AssemblyName = "Сборка 2", Cost = 205, UserId = 1 } }; return View(products); } [HttpGet] public IActionResult IndexBatch() { List products = new List { new BatchViewModel { Id = 1, ProductId = 1 }, new BatchViewModel { Id = 2, ProductId = 2 }, }; return View(products); } [HttpGet] public IActionResult ComponentRequestAssemblyReport() { List detailTimeReports = new List { new ComponentRequestAssemblyReportViewModel { ComponentName = "Комплектующее 1", DateRequests = new List { DateTime.Today, DateTime.Now }, Assemblies = new List {"Сборка 1", "Сборка 2"} }, new ComponentRequestAssemblyReportViewModel { ComponentName = "Комплектующее 2", DateRequests = new List { DateTime.Today, DateTime.Now }, Assemblies = new List {"Сборка 3", "Сборка 4"} }, }; return View(detailTimeReports); } [HttpGet] public IActionResult ComponentBatchReport() { List detailTimeReports = new List { new ComponentBatchReportViewModel { ComponentName = "Комплектующее 1", DateBatch = new List { DateTime.Today, DateTime.Now }, }, new ComponentBatchReportViewModel { ComponentName = "Комплектующее 1", DateBatch = new List { DateTime.Today, DateTime.Now }, } }; return View(detailTimeReports); } [HttpGet] public IActionResult ReportsMenu() { return View(); } [HttpPost] public void Privacy(string fio, string phonenumber, string login, string password, string email) { if (APIUser.User == null) { throw new Exception("Требуется авторизация"); } if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(email)) { throw new Exception("Требуется логин, пароль и email"); } APIUser.PostRequest("api/user/updatedata", new UserBindingModel { Id = APIUser.User.Id, Fio = fio, PhoneNumber = phonenumber, Login = login, Password = password, Email = email }); APIUser.User.Fio = fio; APIUser.User.PhoneNumber = phonenumber; APIUser.User.Password = password; APIUser.User.Email = email; 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("Введите логин и пароль"); } APIUser.User = APIUser.GetRequest($"api/user/loginimplementer?login={login}&password={password}"); if (APIUser.User == null) { throw new Exception("Не верный логин или пароль"); } Response.Redirect("Index"); } [HttpGet] public IActionResult Register() { return View(); } [HttpPost] public void Register(string fio, string phonenumber, string login, string password, string email) { if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(email)) { throw new Exception("Введите логин, пароль, почту"); } APIUser.PostRequest("api/user/registerimplementer", new UserBindingModel { Fio = fio, PhoneNumber = phonenumber, Login = login, Password = password, Email = email }); Response.Redirect("Enter"); return; } } }