2024-04-30 20:36:13 +04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using ServiceStationContracts.BindingModels;
|
2024-05-28 22:40:54 +04:00
|
|
|
|
using ServiceStationContracts.BusinessLogicsContracts;
|
2024-05-27 23:35:42 +04:00
|
|
|
|
using ServiceStationContracts.SearchModels;
|
|
|
|
|
using ServiceStationContracts.ViewModels;
|
2024-04-30 20:36:13 +04:00
|
|
|
|
using ServiceStationGuarantorApp.Models;
|
|
|
|
|
using System.Diagnostics;
|
2024-05-27 23:35:42 +04:00
|
|
|
|
using System.Runtime.InteropServices.ComTypes;
|
2024-04-30 20:36:13 +04:00
|
|
|
|
|
|
|
|
|
namespace ServiceStationGuarantorApp.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class HomeController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<HomeController> _logger;
|
2024-05-28 22:40:54 +04:00
|
|
|
|
private readonly IGuarantorReportLogic _report;
|
2024-04-30 20:36:13 +04:00
|
|
|
|
|
2024-05-28 22:40:54 +04:00
|
|
|
|
public HomeController(ILogger<HomeController> logger, IGuarantorReportLogic guarantorReportLogic)
|
2024-04-30 20:36:13 +04:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
2024-05-28 22:40:54 +04:00
|
|
|
|
_report = guarantorReportLogic;
|
2024-04-30 20:36:13 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult Index()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult Privacy()
|
|
|
|
|
{
|
2024-05-27 23:35:42 +04:00
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
return View(APIGuarantor.Guarantor);
|
2024-04-30 20:36:13 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-27 23:35:42 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Privacy(string number, string email, string FIO, string password)
|
|
|
|
|
{
|
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(number) || string.IsNullOrEmpty(FIO) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(email))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы ввели не все данные!");
|
|
|
|
|
}
|
|
|
|
|
APIGuarantor.PostRequest("api/guarantor/updatedata", new GuarantorBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = APIGuarantor.Guarantor.Id,
|
|
|
|
|
GuarantorNumber = number,
|
|
|
|
|
GuarantorEmail = email,
|
|
|
|
|
GuarantorFIO = FIO,
|
|
|
|
|
GuarantorPassword = password,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
APIGuarantor.Guarantor.GuarantorNumber = number;
|
|
|
|
|
APIGuarantor.Guarantor.GuarantorEmail = email;
|
|
|
|
|
APIGuarantor.Guarantor.GuarantorFIO = FIO;
|
|
|
|
|
APIGuarantor.Guarantor.GuarantorPassword = password;
|
|
|
|
|
Response.Redirect("Index");
|
|
|
|
|
}
|
2024-04-30 20:36:13 +04:00
|
|
|
|
|
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
|
|
|
public IActionResult Error()
|
|
|
|
|
{
|
|
|
|
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult Enter()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-27 23:35:42 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Enter(string number, string password)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(number) || string.IsNullOrEmpty(password))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Не хватает пароля или номера.");
|
|
|
|
|
}
|
|
|
|
|
APIGuarantor.Guarantor = APIGuarantor.GetRequest<GuarantorViewModel>($"api/guarantor/login?guarantorNumber={number}&password={password}");
|
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Неверный логин/пароль");
|
|
|
|
|
}
|
|
|
|
|
Response.Redirect("Index");
|
|
|
|
|
}
|
2024-04-30 20:36:13 +04:00
|
|
|
|
|
|
|
|
|
public IActionResult Register()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-27 23:35:42 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Register(string FIO, string number, string password, string email)
|
2024-04-30 20:36:13 +04:00
|
|
|
|
{
|
2024-05-27 23:35:42 +04:00
|
|
|
|
if (string.IsNullOrEmpty(FIO) || string.IsNullOrEmpty(number) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(email))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введены не все данные");
|
|
|
|
|
}
|
2024-04-30 20:36:13 +04:00
|
|
|
|
|
2024-05-27 23:35:42 +04:00
|
|
|
|
APIGuarantor.PostRequest("api/guarantor/register", new GuarantorBindingModel
|
|
|
|
|
{
|
|
|
|
|
GuarantorNumber = number,
|
|
|
|
|
GuarantorEmail = email,
|
|
|
|
|
GuarantorFIO = FIO,
|
|
|
|
|
GuarantorPassword = password
|
|
|
|
|
});
|
|
|
|
|
Response.Redirect("Enter");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//......................................................... Запчасть..............................................................................
|
2024-04-30 20:36:13 +04:00
|
|
|
|
|
2024-05-27 23:35:42 +04:00
|
|
|
|
public IActionResult ListSpareParts()
|
|
|
|
|
{
|
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction("Enter");
|
|
|
|
|
}
|
|
|
|
|
return View(APIGuarantor.GetRequest<List<SparePartViewModel>>($"api/main/getsparepartlist?guarantorId={APIGuarantor.Guarantor.Id}"));
|
|
|
|
|
}
|
2024-04-30 20:36:13 +04:00
|
|
|
|
|
2024-05-27 23:35:42 +04:00
|
|
|
|
public IActionResult CreateSparePart()
|
|
|
|
|
{
|
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction("Enter");
|
|
|
|
|
}
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateSparePart(string SparePartName, double SparePartPrice)
|
|
|
|
|
{
|
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Авторизуйтесь");
|
|
|
|
|
}
|
|
|
|
|
APIGuarantor.PostRequest("api/main/createsparepart", new SparePartBindingModel
|
|
|
|
|
{
|
|
|
|
|
GuarantorId = APIGuarantor.Guarantor.Id,
|
|
|
|
|
SparePartName = SparePartName,
|
|
|
|
|
SparePartPrice = SparePartPrice
|
|
|
|
|
});
|
|
|
|
|
Response.Redirect("ListSpareParts");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult UpdateSparePart()
|
|
|
|
|
{
|
|
|
|
|
ViewBag.SpareParts = new List<SparePartViewModel>();
|
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction("Enter");
|
|
|
|
|
}
|
|
|
|
|
ViewBag.SpareParts = APIGuarantor.GetRequest<List<SparePartViewModel>>($"api/main/getsparepartlist?guarantorId={APIGuarantor.Guarantor.Id}");
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void UpdateSparePart(int sparepart, string sparepartName, double sparepartPrice)
|
|
|
|
|
{
|
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Авторизуйтесь");
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(sparepartName))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введите название запчасти");
|
|
|
|
|
}
|
|
|
|
|
if (sparepartPrice < 0)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Цена запчасти не может быть меньше 0");
|
|
|
|
|
}
|
|
|
|
|
APIGuarantor.PostRequest("api/main/updatesparepart", new SparePartBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = sparepart,
|
|
|
|
|
SparePartName = sparepartName,
|
|
|
|
|
SparePartPrice = sparepartPrice,
|
|
|
|
|
GuarantorId = APIGuarantor.Guarantor.Id
|
|
|
|
|
});
|
|
|
|
|
Response.Redirect("ListSpareParts");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult DeleteSparePart()
|
|
|
|
|
{
|
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction("Enter");
|
|
|
|
|
}
|
|
|
|
|
ViewBag.SpareParts = APIGuarantor.GetRequest<List<SparePartViewModel>>($"api/main/getsparepartlist?guarantorId={APIGuarantor.Guarantor.Id}");
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void DeleteSparePart(int sparepart)
|
|
|
|
|
{
|
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Авторизуйтесь");
|
|
|
|
|
}
|
|
|
|
|
APIGuarantor.PostRequest("api/main/deletesparepart", new SparePartBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = sparepart
|
|
|
|
|
});
|
|
|
|
|
Response.Redirect("ListSpareParts");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-28 22:40:54 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public string GetSparePartsReport(DateTime dateFrom, DateTime dateTo)
|
|
|
|
|
{
|
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Авторизуйтесь");
|
|
|
|
|
}
|
|
|
|
|
List<ReportSparePartsViewModel> spareparts;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
spareparts = _report.GetSpareParts(new ReportGuarantorBindingModel
|
|
|
|
|
{
|
|
|
|
|
GuarantorId = APIGuarantor.Guarantor.Id,
|
|
|
|
|
DateFrom = dateFrom,
|
|
|
|
|
DateTo = dateTo,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка создания отчета");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
string table = "";
|
|
|
|
|
table += "<h2>Предварительный отчет</h2>";
|
|
|
|
|
table += "<table class=\"table\">";
|
|
|
|
|
table += "<thead class=\"thead-dark\">";
|
|
|
|
|
table += "<tr>";
|
|
|
|
|
table += "<th scope=\"col\">Название запчасти</th>";
|
|
|
|
|
table += "<th scope=\"col\">Стоимость запчасти</th>";
|
|
|
|
|
table += "<th scope=\"col\">Название ремонта</th>";
|
|
|
|
|
table += "<th scope=\"col\">Цена ремонта</th>";
|
|
|
|
|
table += "<th scope=\"col\">Тип ТО</th>";
|
|
|
|
|
table += "<th scope=\"col\">Дата ТО</th>";
|
|
|
|
|
table += "<th scope=\"col\">Цена ТО</th>";
|
|
|
|
|
table += "</tr>";
|
|
|
|
|
table += "</thead>";
|
|
|
|
|
foreach (var sparepart in spareparts)
|
|
|
|
|
{
|
|
|
|
|
bool isRepair = true;
|
|
|
|
|
if (sparepart.RepairPrice == 0)
|
|
|
|
|
{
|
|
|
|
|
isRepair = false;
|
|
|
|
|
}
|
|
|
|
|
table += "<tbody>";
|
|
|
|
|
table += "<tr>";
|
|
|
|
|
table += $"<td>{sparepart.SparePartName}</td>";
|
|
|
|
|
table += $"<td>{sparepart.SparePartPrice}</td>";
|
|
|
|
|
table += $"<td>{(isRepair ? sparepart.RepairName : string.Empty)}</td>";
|
|
|
|
|
table += $"<td>{(isRepair ? sparepart.RepairPrice : string.Empty)}</td>";
|
|
|
|
|
table += $"<td>{sparepart.WorkType}</td>";
|
|
|
|
|
table += $"<td>{(isRepair ? string.Empty : sparepart.TechnicalWorkDate)}</td>";
|
|
|
|
|
table += $"<td>{(isRepair ? string.Empty : sparepart.TechnicalWorkPrice)}</td>";
|
|
|
|
|
table += "</tr>";
|
|
|
|
|
table += "</tbody>";
|
|
|
|
|
}
|
|
|
|
|
table += "</table>";
|
|
|
|
|
return table;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//......................................................... Ремонт..............................................................................
|
2024-05-27 23:35:42 +04:00
|
|
|
|
|
2024-05-28 22:40:54 +04:00
|
|
|
|
public IActionResult ListRepairs()
|
2024-04-30 20:36:13 +04:00
|
|
|
|
{
|
2024-05-27 23:35:42 +04:00
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction("Enter");
|
|
|
|
|
}
|
|
|
|
|
return View(APIGuarantor.GetRequest<List<RepairViewModel>>($"api/main/getrepairlist?guarantorId={APIGuarantor.Guarantor.Id}"));
|
|
|
|
|
}
|
2024-04-30 20:36:13 +04:00
|
|
|
|
|
2024-05-27 23:35:42 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public Tuple<RepairViewModel, string>? GetRepair(int repairId)
|
|
|
|
|
{
|
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Необходима авторизация");
|
|
|
|
|
}
|
|
|
|
|
var result = APIGuarantor.GetRequest<Tuple<RepairViewModel, List<Tuple<string, string>>>>($"api/main/getrepair?repairId={repairId}");
|
|
|
|
|
if (result == null) return default;
|
|
|
|
|
string table = "";
|
|
|
|
|
for (int i = 0; i < result.Item2.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
var sparepartName = result.Item2[i].Item1;
|
|
|
|
|
var sparepartPrice = result.Item2[i].Item2;
|
|
|
|
|
table += "<tr>";
|
|
|
|
|
table += $"<td>{sparepartName}</td>";
|
|
|
|
|
table += $"<td>{sparepartPrice}</td>";
|
|
|
|
|
table += "</tr>";
|
|
|
|
|
}
|
|
|
|
|
return Tuple.Create(result.Item1, table);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult CreateRepair()
|
|
|
|
|
{
|
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction("Enter");
|
|
|
|
|
}
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateRepair(string repairName, double repairPrice)
|
|
|
|
|
{
|
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Авторизуйтесь");
|
|
|
|
|
}
|
|
|
|
|
APIGuarantor.PostRequest("api/main/createrepair", new RepairBindingModel
|
|
|
|
|
{
|
|
|
|
|
GuarantorId = APIGuarantor.Guarantor.Id,
|
|
|
|
|
RepairName = repairName,
|
|
|
|
|
RepairPrice = repairPrice
|
|
|
|
|
});
|
|
|
|
|
Response.Redirect("ListRepairs");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult UpdateRepair()
|
|
|
|
|
{
|
|
|
|
|
ViewBag.Repairs = new List<RepairViewModel>();
|
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction("Enter");
|
|
|
|
|
}
|
|
|
|
|
ViewBag.Repairs = APIGuarantor.GetRequest<List<RepairViewModel>>($"api/main/getrepairlist?guarantorId={APIGuarantor.Guarantor.Id}");
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void UpdateRepair(int repair, string RepairName, double RepairPrice)
|
|
|
|
|
{
|
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Авторизуйтесь");
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(RepairName))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введите название ремонта");
|
|
|
|
|
}
|
|
|
|
|
if (RepairPrice < 0)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Цена ремонта не может быть меньше 0");
|
|
|
|
|
}
|
|
|
|
|
APIGuarantor.PostRequest("api/main/updaterepair", new RepairBindingModel
|
|
|
|
|
{
|
|
|
|
|
GuarantorId = APIGuarantor.Guarantor.Id,
|
|
|
|
|
Id = repair,
|
|
|
|
|
RepairName = RepairName,
|
|
|
|
|
RepairPrice = RepairPrice
|
|
|
|
|
});
|
|
|
|
|
Response.Redirect("ListRepairs");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult DeleteRepair()
|
|
|
|
|
{
|
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction("Enter");
|
|
|
|
|
}
|
|
|
|
|
ViewBag.Repairs = APIGuarantor.GetRequest<List<RepairViewModel>>($"api/main/getrepairlist?guarantorId={APIGuarantor.Guarantor.Id}");
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void DeleteRepair(int repair)
|
|
|
|
|
{
|
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Авторизуйтесь");
|
|
|
|
|
}
|
|
|
|
|
APIGuarantor.PostRequest("api/main/deleterepair", new RepairBindingModel { Id = repair });
|
|
|
|
|
Response.Redirect("ListRepairs");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//......................................................... Работа..............................................................................
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2024-04-30 20:36:13 +04:00
|
|
|
|
public IActionResult ListWorks()
|
|
|
|
|
{
|
2024-05-27 23:35:42 +04:00
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction("Enter");
|
|
|
|
|
}
|
|
|
|
|
return View(APIGuarantor.GetRequest<List<WorkViewModel>>($"api/main/getworklist?guarantorId={APIGuarantor.Guarantor.Id}"));
|
|
|
|
|
}
|
2024-04-30 20:36:13 +04:00
|
|
|
|
|
2024-05-27 23:35:42 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public Tuple<WorkViewModel, string>? GetWork(int workId)
|
|
|
|
|
{
|
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Необходима авторизация");
|
|
|
|
|
}
|
|
|
|
|
var result = APIGuarantor.GetRequest<Tuple<WorkViewModel, List<Tuple<string, string>>>>($"api/main/getwork?workId={workId}");
|
|
|
|
|
if (result == null) return default;
|
|
|
|
|
string table = "";
|
|
|
|
|
for (int i = 0; i < result.Item2.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
var sparepartName = result.Item2[i].Item1;
|
|
|
|
|
var sparepartPrice = result.Item2[i].Item2;
|
|
|
|
|
table += "<tr>";
|
|
|
|
|
table += $"<td>{sparepartName}</td>";
|
|
|
|
|
table += $"<td>{sparepartPrice}</td>";
|
|
|
|
|
table += "</tr>";
|
|
|
|
|
}
|
|
|
|
|
return Tuple.Create(result.Item1, table);
|
|
|
|
|
}
|
2024-04-30 20:36:13 +04:00
|
|
|
|
|
2024-05-27 23:35:42 +04:00
|
|
|
|
public IActionResult CreateWork()
|
|
|
|
|
{
|
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction("Enter");
|
|
|
|
|
}
|
|
|
|
|
return View();
|
|
|
|
|
}
|
2024-04-30 20:36:13 +04:00
|
|
|
|
|
2024-05-27 23:35:42 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateWork(string WorkName, double WorkPrice)
|
|
|
|
|
{
|
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Авторизуйтесь");
|
|
|
|
|
}
|
|
|
|
|
APIGuarantor.PostRequest("api/main/creatework", new WorkBindingModel
|
|
|
|
|
{
|
|
|
|
|
GuarantorId = APIGuarantor.Guarantor.Id,
|
|
|
|
|
WorkName = WorkName,
|
|
|
|
|
WorkPrice = WorkPrice,
|
|
|
|
|
Status = ServiceStationDataModels.Enums.WorkStatus.Принята
|
|
|
|
|
});
|
|
|
|
|
Response.Redirect("ListWorks");
|
|
|
|
|
}
|
2024-04-30 20:36:13 +04:00
|
|
|
|
|
2024-05-27 23:35:42 +04:00
|
|
|
|
public IActionResult UpdateWork()
|
|
|
|
|
{
|
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction("Enter");
|
|
|
|
|
}
|
|
|
|
|
ViewBag.Works = APIGuarantor.GetRequest<List<WorkViewModel>>($"api/main/getworklist?guarantorId={APIGuarantor.Guarantor.Id}");
|
|
|
|
|
return View();
|
|
|
|
|
}
|
2024-04-30 20:36:13 +04:00
|
|
|
|
|
2024-05-27 23:35:42 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void UpdateWork(int work, string WorkName, double WorkPrice)
|
|
|
|
|
{
|
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Авторизуйтесь");
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(WorkName))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введите название работы");
|
|
|
|
|
}
|
|
|
|
|
if (WorkPrice < 0)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Цена работы не может быть меньше 0");
|
|
|
|
|
}
|
|
|
|
|
APIGuarantor.PostRequest("api/main/updatework", new WorkBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = work,
|
|
|
|
|
WorkName = WorkName,
|
|
|
|
|
GuarantorId = APIGuarantor.Guarantor.Id,
|
|
|
|
|
WorkPrice = WorkPrice,
|
|
|
|
|
});
|
|
|
|
|
Response.Redirect("ListWorks");
|
|
|
|
|
}
|
2024-04-30 20:36:13 +04:00
|
|
|
|
|
2024-05-27 23:35:42 +04:00
|
|
|
|
public IActionResult DeleteWork()
|
|
|
|
|
{
|
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction("Enter");
|
|
|
|
|
}
|
|
|
|
|
ViewBag.Works = APIGuarantor.GetRequest<List<WorkViewModel>>($"api/main/getworklist?guarantorId={APIGuarantor.Guarantor.Id}");
|
|
|
|
|
return View();
|
|
|
|
|
}
|
2024-04-30 20:36:13 +04:00
|
|
|
|
|
2024-05-27 23:35:42 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void DeleteWork(int work)
|
|
|
|
|
{
|
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Авторизуйтесь");
|
|
|
|
|
}
|
|
|
|
|
APIGuarantor.PostRequest("api/main/deletework", new WorkBindingModel { Id = work });
|
|
|
|
|
Response.Redirect("ListWorks");
|
|
|
|
|
}
|
2024-04-30 20:36:13 +04:00
|
|
|
|
|
2024-05-27 23:35:42 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void UpdateWorkStatus(int work, string status)
|
2024-04-30 20:36:13 +04:00
|
|
|
|
{
|
2024-05-27 23:35:42 +04:00
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Авторизуйтесь");
|
|
|
|
|
}
|
|
|
|
|
if (status == "Отдать на выполнение")
|
|
|
|
|
{
|
|
|
|
|
APIGuarantor.PostRequest("api/main/updateworkstatusexecution", new WorkBindingModel { Id = work, Status = ServiceStationDataModels.Enums.WorkStatus.Выполняется});
|
|
|
|
|
}
|
|
|
|
|
if (status == "Готова")
|
|
|
|
|
{
|
|
|
|
|
APIGuarantor.PostRequest("api/main/updateworkstatusexecution", new WorkBindingModel { Id = work, Status = ServiceStationDataModels.Enums.WorkStatus.Готова});
|
|
|
|
|
}
|
|
|
|
|
Response.Redirect("ListWorks");
|
2024-04-30 20:36:13 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-27 23:35:42 +04:00
|
|
|
|
public IActionResult UpdateWorkStatus()
|
2024-04-30 20:36:13 +04:00
|
|
|
|
{
|
2024-05-27 23:35:42 +04:00
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction("Enter");
|
|
|
|
|
}
|
|
|
|
|
ViewBag.Works = APIGuarantor.GetRequest<List<WorkViewModel>>($"api/main/getworklist?guarantorId={APIGuarantor.Guarantor.Id}");
|
2024-04-30 20:36:13 +04:00
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2024-05-27 23:35:42 +04:00
|
|
|
|
public IActionResult AddSparepartToRepair()
|
2024-04-30 20:36:13 +04:00
|
|
|
|
{
|
2024-05-27 23:35:42 +04:00
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction("Enter");
|
|
|
|
|
}
|
|
|
|
|
return View(Tuple.Create(APIGuarantor.GetRequest<List<RepairViewModel>>($"api/main/getrepairlist?guarantorId={APIGuarantor.Guarantor.Id}"),
|
|
|
|
|
APIGuarantor.GetRequest<List<SparePartViewModel>>($"api/main/getsparepartlist?guarantorId={APIGuarantor.Guarantor.Id}")));
|
|
|
|
|
}
|
2024-04-30 20:36:13 +04:00
|
|
|
|
|
2024-05-27 23:35:42 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void AddSparepartToRepair(int repair, int[] sparepart)
|
|
|
|
|
{
|
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Авторизуйтесь");
|
|
|
|
|
}
|
|
|
|
|
APIGuarantor.PostRequest("api/main/addspareparttorepair", Tuple.Create(new RepairSearchModel() { Id = repair }, sparepart));
|
|
|
|
|
Response.Redirect("ListRepairs");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult AddSparepartToWork()
|
|
|
|
|
{
|
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction("Enter");
|
|
|
|
|
}
|
|
|
|
|
return View(Tuple.Create(APIGuarantor.GetRequest<List<WorkViewModel>>($"api/main/getworklist?guarantorId={APIGuarantor.Guarantor.Id}"),
|
|
|
|
|
APIGuarantor.GetRequest<List<SparePartViewModel>>($"api/main/getsparepartlist?guarantorId={APIGuarantor.Guarantor.Id}")));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void AddSparepartToWork(int work, int[] sparepart)
|
|
|
|
|
{
|
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Авторизуйтесь");
|
|
|
|
|
}
|
|
|
|
|
APIGuarantor.PostRequest("api/main/addspareparttowork", Tuple.Create(new WorkSearchModel() { Id = work }, sparepart));
|
|
|
|
|
Response.Redirect("ListWorks");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-28 22:40:54 +04:00
|
|
|
|
public IActionResult GetWordFile()
|
|
|
|
|
{
|
|
|
|
|
return new PhysicalFileResult(Directory.GetCurrentDirectory() + "\\Reports\\wordfile.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
|
|
|
|
|
}
|
|
|
|
|
public IActionResult GetExcelFile()
|
|
|
|
|
{
|
|
|
|
|
return new PhysicalFileResult(Directory.GetCurrentDirectory() + "\\Reports\\excelfile.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
|
|
}
|
|
|
|
|
public IActionResult GetPdfFile()
|
|
|
|
|
{
|
|
|
|
|
return new PhysicalFileResult(Directory.GetCurrentDirectory() + "\\Reports\\pdffile.pdf", "application/pdf");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2024-05-27 23:35:42 +04:00
|
|
|
|
public IActionResult ListDefectSparePartToFile()
|
|
|
|
|
{
|
2024-05-28 22:40:54 +04:00
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction("Enter");
|
|
|
|
|
}
|
|
|
|
|
return View(APIGuarantor.GetRequest<List<SparePartViewModel>>($"api/main/getsparepartlist?guarantorId={APIGuarantor.Guarantor.Id}"));
|
|
|
|
|
}
|
2024-05-27 23:35:42 +04:00
|
|
|
|
|
2024-05-28 22:40:54 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void ListDefectSparePartToFile(int[] Ids, string type)
|
|
|
|
|
{
|
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Авторизуйтесь");
|
|
|
|
|
}
|
|
|
|
|
if (Ids.Length <= 0)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Кол-во меньше нуля");
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(type))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Неопознанный тип");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<int> res = new List<int>();
|
|
|
|
|
|
|
|
|
|
foreach (var id in Ids)
|
|
|
|
|
{
|
|
|
|
|
res.Add(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (type == "docx")
|
|
|
|
|
{
|
|
|
|
|
APIGuarantor.PostRequest("api/report/createguarantorreporttoword", new ReportGuarantorBindingModel
|
|
|
|
|
{
|
|
|
|
|
Ids = res,
|
|
|
|
|
FileName = Directory.GetCurrentDirectory() + "\\Reports\\wordfile.docx"
|
|
|
|
|
});
|
|
|
|
|
Response.Redirect("GetWordFile");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
APIGuarantor.PostRequest("api/report/createguarantorreporttoexcel", new ReportGuarantorBindingModel
|
|
|
|
|
{
|
|
|
|
|
Ids = res,
|
|
|
|
|
FileName = Directory.GetCurrentDirectory() + "\\Reports\\excelfile.xlsx"
|
|
|
|
|
});
|
|
|
|
|
Response.Redirect("GetExcelFile");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult ListSparePartsToPdfFile()
|
|
|
|
|
{
|
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction("Enter");
|
|
|
|
|
}
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void ListSparePartsToPdfFile(DateTime dateFrom, DateTime dateTo, string guarantorEmail)
|
2024-05-27 23:35:42 +04:00
|
|
|
|
{
|
2024-05-28 22:40:54 +04:00
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Авторизуйтесь");
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(guarantorEmail))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Email пуст");
|
|
|
|
|
}
|
|
|
|
|
APIGuarantor.PostRequest("api/report/createguarantorreporttopdf", new ReportGuarantorBindingModel
|
|
|
|
|
{
|
|
|
|
|
FileName = Directory.GetCurrentDirectory() + "\\Reports\\pdffile.pdf",
|
|
|
|
|
DateFrom = dateFrom,
|
|
|
|
|
DateTo = dateTo,
|
|
|
|
|
GuarantorId = APIGuarantor.Guarantor.Id,
|
|
|
|
|
});
|
|
|
|
|
Response.Redirect("GetPdfFile");
|
|
|
|
|
}
|
2024-04-30 20:36:13 +04:00
|
|
|
|
|
|
|
|
|
public IActionResult BindingRepairToDefects()
|
|
|
|
|
{
|
2024-05-28 22:40:54 +04:00
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction("Enter");
|
|
|
|
|
}
|
|
|
|
|
return View(Tuple.Create(APIGuarantor.GetRequest<List<RepairViewModel>>($"api/main/getrepairlist?guarantorId={APIGuarantor.Guarantor.Id}"),
|
|
|
|
|
APIGuarantor.GetRequest<List<DefectViewModel>>("api/main/getdefects")));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void BindingRepairToDefects(int repair, int defect)
|
|
|
|
|
{
|
|
|
|
|
if (APIGuarantor.Guarantor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Авторизуйтесь");
|
|
|
|
|
}
|
|
|
|
|
APIGuarantor.PostRequest("api/main/updatedefect", new DefectBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = defect,
|
|
|
|
|
RepairId = repair
|
|
|
|
|
});
|
2024-04-30 20:36:13 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|