using Microsoft.AspNetCore.Mvc; using ServiceStationContracts.BindingModels; using ServiceStationContracts.SearchModels; using ServiceStationContracts.ViewModels; using ServiceStationExecutorApp.Models; using System.Collections.Generic; using System.Diagnostics; namespace ServiceStationExecutorApp.Controllers { public class HomeController : Controller { private readonly ILogger _logger; public HomeController(ILogger logger) { _logger = logger; } public IActionResult Index() { return View(); } public IActionResult Privacy() { if(APIExecutor.Executor == null) { return RedirectToAction("Enter"); } return View(APIExecutor.Executor); } [HttpPost] public void Privacy(string email, string fio, string number, string password) { if (APIExecutor.Executor == null) { throw new Exception("Авторизироваться не забыли?"); } if (string.IsNullOrEmpty(fio) || string.IsNullOrEmpty(number) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(email)) { throw new Exception("Введены не все данные"); } APIExecutor.PostRequest("api/executor/updateexecutor", new ExecutorBindingModel { ExecutorEmail = email, ExecutorNumber = number, ExecutorFIO = fio, ExecutorPassword = password, Id = APIExecutor.Executor.Id }); Response.Redirect("Index"); } public IActionResult Enter() { return View(); } [HttpPost] public void Enter(string executorNumber, string password) { if(string.IsNullOrEmpty(executorNumber) || string.IsNullOrEmpty(password)) { throw new Exception("Не хватает пароля или номера."); } APIExecutor.Executor = APIExecutor.GetRequest($"api/executor/login?executorNumber={executorNumber}&password={password}"); if (APIExecutor.Executor == null) { throw new Exception("Неверный логин/пароль"); } Response.Redirect("Index"); } public IActionResult Register() { return View(); } [HttpPost] public void Register(string fio, string executorNumber, string password, string email) { if(string.IsNullOrEmpty(fio) || string.IsNullOrEmpty(executorNumber) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(email)) { throw new Exception("Введены не все данные"); } APIExecutor.PostRequest("api/executor/register", new ExecutorBindingModel { ExecutorNumber = executorNumber, ExecutorEmail = email, ExecutorFIO = fio, ExecutorPassword = password }); Response.Redirect("Enter"); return; } public IActionResult ListCars() { if (APIExecutor.Executor == null) { return RedirectToAction("Enter"); } return View(APIExecutor.GetRequest>($"api/main/getcarlist?executorId={APIExecutor.Executor.Id}")); } public IActionResult ListDefects() { if (APIExecutor.Executor == null) { return RedirectToAction("Enter"); } return View(APIExecutor.GetRequest>($"api/main/getdefectlist?executorId={APIExecutor.Executor.Id}")); } public IActionResult ListTechnicalWorks() { if (APIExecutor.Executor == null) { return RedirectToAction("Enter"); } return View(APIExecutor.GetRequest>($"api/main/gettechnicalworklist?executorId={APIExecutor.Executor.Id}")); } [HttpGet] public Tuple? GetDefect(int defectId) { if(APIExecutor.Executor == null) { throw new Exception("Необходима авторизация"); } var result = APIExecutor.GetRequest>>>($"api/main/getdefect?defectId={defectId}"); if (result == null) return default; string table = ""; for(int i = 0; i < result.Item2.Count; i++) { var carNumber = result.Item2[i].Item1; var carBrand = result.Item2[i].Item2; table += ""; table += $"{carNumber}"; table += $"{carBrand}"; table += ""; } return Tuple.Create(result.Item1, table); } [HttpGet] public Tuple? GetTechnicalWork(int technicalWorkId) { if(APIExecutor.Executor == null) { throw new Exception("Необходима авторизация"); } var result = APIExecutor.GetRequest>>>($"api/main/gettechnicalwork?technicalworkId={technicalWorkId}"); if (result == null) return default; string table = ""; for(int i = 0;i{carNumber}"; table += $"{carBrand}"; table += ""; } return Tuple.Create(result.Item1, table); } public IActionResult DeleteCar() { if (APIExecutor.Executor == null) { return RedirectToAction("Enter"); } ViewBag.Cars = APIExecutor.GetRequest>($"api/main/getcarlist?executorId={APIExecutor.Executor.Id}"); return View(); } [HttpPost] public void DeleteCar(int car) { if (APIExecutor.Executor == null) { throw new Exception("Авторизироваться не забыли?"); } APIExecutor.PostRequest("api/main/deletecar", new CarBindingModel { Id = car }); Response.Redirect("ListCars"); } public IActionResult DeleteDefect() { if (APIExecutor.Executor == null) { return RedirectToAction("Enter"); } ViewBag.Defects = APIExecutor.GetRequest>($"api/main/getdefectlist?executorId={APIExecutor.Executor.Id}"); return View(); } [HttpPost] public void DeleteDefect(int defect) { if (APIExecutor.Executor == null) { throw new Exception("Авторизироваться не забыли?"); } APIExecutor.PostRequest("api/main/deletedefect", new DefectBindingModel { Id = defect }); Response.Redirect("ListDefects"); } public IActionResult DeleteTechnicalWork() { if (APIExecutor.Executor == null) { return RedirectToAction("Enter"); } ViewBag.TechnicalWorks = APIExecutor.GetRequest>($"api/main/gettechnicalworklist?executorId={APIExecutor.Executor.Id}"); return View(); } [HttpPost] public void DeleteTechnicalWork(int technicalWork) { if (APIExecutor.Executor == null) { throw new Exception("Авторизироваться не забыли?"); } APIExecutor.PostRequest("api/main/deletetechnicalwork", new TechnicalWorkBindingModel { Id = technicalWork }); Response.Redirect("ListTechnicalWorks"); } public IActionResult UpdateCar() { if (APIExecutor.Executor == null) { return RedirectToAction("Enter"); } ViewBag.Cars = APIExecutor.GetRequest>($"api/main/getcarlist?executorId={APIExecutor.Executor.Id}"); return View(); } [HttpPost] public void UpdateCar(int car, string carNumber, string carBrand) { if (APIExecutor.Executor == null) { throw new Exception("Авторизироваться не забыли?"); } if (string.IsNullOrEmpty(carNumber)) { throw new Exception("Введите номер машины"); } if (string.IsNullOrEmpty(carBrand)) { throw new Exception("Введите бренд машины"); } APIExecutor.PostRequest("api/main/updatecar", new CarBindingModel { Id = car, CarNumber = carNumber, CarBrand = carBrand, ExecutorId = APIExecutor.Executor.Id }); Response.Redirect("ListCars"); } public IActionResult UpdateDefect() { if (APIExecutor.Executor == null) { return RedirectToAction("Enter"); } ViewBag.Defects = APIExecutor.GetRequest>($"api/main/getdefectlist?executorId={APIExecutor.Executor.Id}"); return View(); } [HttpPost] public void UpdateDefect(int defect, string DefectType, double DefectPrice) { if (APIExecutor.Executor == null) { throw new Exception("Авторизироваться не забыли?"); } if (string.IsNullOrEmpty(DefectType)) { throw new Exception("Введите тип неисправности"); } if(DefectPrice < 100) { throw new Exception("Минимальная цена неисправности 100"); } APIExecutor.PostRequest("api/main/updatedefect", new DefectBindingModel { ExecutorId = APIExecutor.Executor.Id, Id = defect, DefectType = DefectType, DefectPrice = DefectPrice }); Response.Redirect("ListDefects"); } public IActionResult UpdateTechnicalWork() { if (APIExecutor.Executor == null) { return RedirectToAction("Enter"); } ViewBag.TechnicalWorks = APIExecutor.GetRequest>($"api/main/gettechnicalworklist?executorId={APIExecutor.Executor.Id}"); return View(); } [HttpPost] public void UpdateTechnicalWork(int technicalWork, string TechnicalWorkType, double TechnicalWorkPrice) { if (APIExecutor.Executor == null) { throw new Exception("Авторизироваться не забыли?"); } if (string.IsNullOrEmpty(TechnicalWorkType)) { throw new Exception("Введите тип ТО"); } if(TechnicalWorkPrice < 100) { throw new Exception("Цена ТО должны быть больше 100"); } APIExecutor.PostRequest("api/main/updatetechnicalwork", new TechnicalWorkBindingModel { Id = technicalWork, WorkType = TechnicalWorkType, ExecutorId = APIExecutor.Executor.Id, WorkPrice = TechnicalWorkPrice, }); Response.Redirect("ListTechnicalWorks"); } public IActionResult CreateCar() { if (APIExecutor.Executor == null) { return RedirectToAction("Enter"); } return View(); } [HttpPost] public void CreateCar(string CarNumber, string CarBrand) { if(APIExecutor.Executor == null) { throw new Exception("Авторизироваться не забыли?"); } APIExecutor.PostRequest("api/main/createcar", new CarBindingModel { ExecutorId = APIExecutor.Executor.Id, CarNumber = CarNumber, CarBrand = CarBrand }); Response.Redirect("ListCars"); } public IActionResult CreateDefect() { if (APIExecutor.Executor == null) { return RedirectToAction("Enter"); } return View(); } [HttpPost] public void CreateDefect(string defectType, double defectPrice) { if (APIExecutor.Executor == null) { throw new Exception("Авторизироваться не забыли?"); } APIExecutor.PostRequest("api/main/createdefect", new DefectBindingModel { ExecutorId = APIExecutor.Executor.Id, DefectType = defectType, DefectPrice = defectPrice }); Response.Redirect("ListDefects"); } public IActionResult CreateTechnicalWork() { if (APIExecutor.Executor == null) { return RedirectToAction("Enter"); } return View(); } [HttpPost] public void CreateTechnicalWork(string WorkType, double WorkPrice) { if (APIExecutor.Executor == null) { throw new Exception("Авторизироваться не забыли?"); } APIExecutor.PostRequest("api/main/createtechnicalwork", new TechnicalWorkBindingModel { ExecutorId = APIExecutor.Executor.Id, WorkType = WorkType, WorkPrice = WorkPrice, DateStartWork = DateTime.Now }); Response.Redirect("ListTechnicalWorks"); } public IActionResult AddCarToDefect() { if (APIExecutor.Executor == null) { return RedirectToAction("Enter"); } return View(Tuple.Create(APIExecutor.GetRequest>($"api/main/getdefectlist?executorId={APIExecutor.Executor.Id}"), APIExecutor.GetRequest>($"api/main/getcarlist?executorId={APIExecutor.Executor.Id}"))); } [HttpPost] public void AddCarToDefect(int defect, int[] car) { if(APIExecutor.Executor == null) { throw new Exception("Авторизироваться не забыли?"); } APIExecutor.PostRequest("api/main/addcartodefect", Tuple.Create( new DefectSearchModel() { Id = defect }, car )); Response.Redirect("ListDefects"); } public IActionResult AddCarToTechnicalWork() { if (APIExecutor.Executor == null) { return RedirectToAction("Enter"); } return View(Tuple.Create(APIExecutor.GetRequest>($"api/main/gettechnicalworklist?executorId={APIExecutor.Executor.Id}"), APIExecutor.GetRequest>($"api/main/getcarlist?executorId={APIExecutor.Executor.Id}"))); } [HttpPost] public void AddCarToTechnicalWork(int technicalWork, int[] car) { if (APIExecutor.Executor == null) { throw new Exception("Авторизироваться не забыли?"); } APIExecutor.PostRequest("api/main/addcartotechnicalwork", Tuple.Create( new TechnicalWorkSearchModel() { Id = technicalWork }, car )); Response.Redirect("ListTechnicalWorks"); } public IActionResult BindingTechnicalWorkToWork() { if (APIExecutor.Executor == null) { return RedirectToAction("Enter"); } var technicalWork = new TechnicalWorkViewModel { Id = 1, WorkType = "type1", WorkPrice = 1000.0, DateStartWork = DateTime.Now, ExecutorId = 1 }; var work = new WorkViewModel { Id = 1, WorkName = "work1", WorkPrice = 1000.0, Status = ServiceStationDataModels.Enums.WorkStatus.Принята }; List technicalWorks = new List(); List works = new List(); technicalWorks.Add(technicalWork); works.Add(work); return View(Tuple.Create(technicalWorks, works)); } public IActionResult ListWorkToFile() { if (APIExecutor.Executor == null) { return RedirectToAction("Enter"); } var car = new CarViewModel { Id = 1, CarNumber = "111", CarBrand = "lamba" }; var car2 = new CarViewModel { Id = 2, CarNumber = "121", CarBrand = "lamba" }; var car3 = new CarViewModel { Id = 3, CarNumber = "131", CarBrand = "lamba" }; List cars = new List(); cars.Add(car); cars.Add(car2); cars.Add(car3); return View(cars); } public IActionResult ListCarsToPdf() { if (APIExecutor.Executor == null) { return RedirectToAction("Enter"); } return View(); } [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); } } }