using ElectronicsShopContracts.BindingModels; using ElectronicsShopContracts.BusinessLogicContracts; using ElectronicsShopContracts.SearchModels; using ElectronicsShopContracts.ViewModels; using ElectronicsShopDataModels.Models; using ElectronicsShopUserApp.Models; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using System.Diagnostics; using System.Reflection; using System.Runtime.Serialization; using System.Xml.Serialization; namespace ElectronicsShopUserApp.Controllers { public class HomeController : Controller { private readonly ILogger _logger; private Dictionary _productList; public int Id; //private readonly IOrderLogic _order; public HomeController(ILogger logger) { _logger = logger; _productList = new Dictionary(); } public IActionResult Index() { if (APIClient.Client == null) { return Redirect("~/Home/Enter"); } return View(APIClient.GetRequset>($"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 email, string password, string fio) { if (APIClient.Client == null) { throw new Exception("Вход для авторизованных"); } if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) { throw new Exception("Введите почту, пароль и ФИО"); } APIClient.PostRequest("api/client/updatedata", new ClientBindingModel { ID = APIClient.Client.ID, ClientFIO = fio, Email = email, Password = password, }); APIClient.Client.ClientFIO = fio; APIClient.Client.Email = email; 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 email, string password) { if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password)) { throw new Exception("Введите почту и пароль"); } APIClient.Client = APIClient.GetRequset($"api/Client/Login?email={email}&password={password}"); if (APIClient.Client == null) { throw new Exception("Неверный адрес почты/пароль"); } Response.Redirect("Index"); } [HttpGet] public IActionResult Register() { return View(); } [HttpPost] public void Register(string email, string password, string fio) { if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) { throw new Exception("Введите почту,пароль и ФИО"); } APIClient.PostRequest("api/client/register", new ClientBindingModel { ClientFIO = fio, Email = email, Password = password }); Response.Redirect("Enter"); return; } public IActionResult Orders() { if (APIClient.Client == null) { return Redirect("~/Home/Enter"); } var view = APIClient.GetRequset>($"api/main/getorders?_clientid={APIClient.Client.ID}"); return View(view); } [HttpGet] public IActionResult CreateOrder() { if (APIClient.Client == null) { return Redirect("~/Home/Enter"); } APIClient.PostRequest("api/main/createorder", new OrderBindingModel { ClientID = APIClient.Client.ID, DateCreate = DateTime.Now, }); return RedirectToAction("OrderView"); } [HttpGet] public IActionResult DeleteOrder(int id) { APIClient.PostRequest($"api/main/deleteorders", new OrderBindingModel { ID = id }); return RedirectToAction("Orders"); } [HttpGet] public IActionResult OrderView() { if (APIClient.Client == null) { return Redirect("~/Home/Enter"); } var view = APIClient.GetRequset($"api/main/getorder?_clientid={APIClient.Client?.ID}"); if (view != null) { Id = view.ID; } var products = APIClient.GetRequset>>($"api/main/getorderproducts?_orderid={view?.ID}"); foreach (var pr in products) { var product = JsonConvert.DeserializeObject(pr[0]); int count = JsonConvert.DeserializeObject(pr[1]); _productList.Add(product.ID, (product, count)); } (int, Dictionary) tuple = (Id, _productList); return View(tuple); } [HttpPost] public void OrderView(int sum, int id) { if (sum <= 0) { APIClient.PostRequest($"api/main/deleteorders", new OrderBindingModel { ID = id}); } Response.Redirect("Orders"); } [HttpGet] public IActionResult DeleteProductOrder(int id) { var view = APIClient.GetRequset($"api/main/getorder?_clientid={APIClient.Client?.ID}"); APIClient.PostRequestStr($"api/main/deleteproductorder", view.ID, id); return RedirectToAction("OrderView"); } [HttpGet] public IActionResult AddProduct() { ViewBag.Products = APIClient.GetRequset>($"api/main/getproducts"); return View(); } [HttpPost] public void AddProduct(int product, int count) { var _product = APIClient.GetRequset($"api/main/getproduct?_productid={product}"); var _order = APIClient.GetRequset($"api/main/getorder?_clientid={APIClient.Client?.ID}"); APIClient.ListPostRequest($"api/main/addproduct", _product, count, _order.ID); Response.Redirect("OrderView"); } [HttpPost] public double Calc(int count, int product) { var _product = APIClient.GetRequset($"api/main/getproduct?_productid={product}"); return count * (_product?.Price ?? 1); } [HttpGet] public IActionResult Report() { //ViewBag.Reports = APIClient.GetRequset>($"api/main/getproducts"); написать нормальные данные об отчётах return View(); } [HttpGet] public IActionResult Message() { //ViewBag.Reports = APIClient.GetRequset>($"api/main/getproducts"); Писем так же пока нема return View(); } [HttpGet] public IActionResult GetWordFile() { return new PhysicalFileResult("C:\\gg\\wordfile.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"); } public IActionResult GetExcelFile() { return new PhysicalFileResult("C:\\gg\\excelfile.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); } [HttpPost] public void ListPreserves(List preserve, string type) {/* if (APIEmployee.Employee == null) { throw new Exception("Вы как суда попали? Суда вход только авторизованным"); } Я Хуй знает как оно фурычит, БОСС Я УСТАЛ if (preserve.Count <= 0) { throw new Exception("Количество должно быть больше 0"); } if (string.IsNullOrEmpty(type)) { throw new Exception("Неверный тип отчета"); } if (type == "docx") { APIEmployee.PostRequest("api/report/createroductlistwordfile", new ReportProductBindingModel { Preserve = preserve, FileName = "C:\\gg\\wordfile.docx" }); Response.Redirect("GetWordFile"); } else { APIEmployee.PostRequest("api/report/createproductlistexcelfile", new ReportProductBindingModel { Preserve = preserve, FileName = "C:\\gg\\excelfile.xlsx" }); Response.Redirect("GetExcelFile"); }*/ } } }