взаимодействие рест апи с поручителем
This commit is contained in:
parent
aecee9325c
commit
4dbe272b1e
@ -102,7 +102,46 @@ namespace ServiceStationBusinessLogic.BusinessLogics
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(RepairBindingModel model, bool withParams = true)
|
||||
public bool AddSparePartToRepair(RepairSearchModel model, int[] spareparts)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("AddSparePartToRepair. RepairName:{RepairName}. Id:{Id}", model.RepairName, model.Id);
|
||||
var element = _repairStorage.GetElement(model);
|
||||
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("AddSparePartToRepair element not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
_logger.LogInformation("AddSparePartToRepair find. Id:{Id}", element.Id);
|
||||
|
||||
foreach (int sparepart in spareparts)
|
||||
{
|
||||
if (!element.RepairSpareParts.Keys.Contains(sparepart))
|
||||
{
|
||||
element.RepairSpareParts.Add(sparepart, new SparePartViewModel() { Id = sparepart });
|
||||
}
|
||||
}
|
||||
|
||||
_repairStorage.Update(new RepairBindingModel()
|
||||
{
|
||||
Id = element.Id,
|
||||
RepairName = element.RepairName,
|
||||
RepairStartDate = element.RepairStartDate,
|
||||
RepairPrice = element.RepairPrice,
|
||||
GuarantorId = element.GuarantorId,
|
||||
DefectId = element.DefectId,
|
||||
RepairSpareParts = element.RepairSpareParts,
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(RepairBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
|
@ -91,7 +91,7 @@ namespace ServiceStationBusinessLogic.BusinessLogics
|
||||
|
||||
public bool Update(WorkBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
//CheckModel(model);
|
||||
|
||||
if (_workStorage.Update(model) == null)
|
||||
{
|
||||
@ -102,7 +102,46 @@ namespace ServiceStationBusinessLogic.BusinessLogics
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(WorkBindingModel model, bool withParams = true)
|
||||
public bool AddSparePartToWork(WorkSearchModel model, int[] spareparts)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("AddSparePartToWork. WorkName:{workName}. Id:{Id}", model.WorkName, model.Id);
|
||||
var element = _workStorage.GetElement(model);
|
||||
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("AddSparePartToWork element not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
_logger.LogInformation("AddSparePartToWork find. Id:{Id}", element.Id);
|
||||
|
||||
foreach (int sparepart in spareparts)
|
||||
{
|
||||
if (!element.WorkSpareParts.Keys.Contains(sparepart))
|
||||
{
|
||||
element.WorkSpareParts.Add(sparepart, new SparePartViewModel() { Id = sparepart });
|
||||
}
|
||||
}
|
||||
|
||||
_workStorage.Update(new WorkBindingModel
|
||||
{
|
||||
Id = element.Id,
|
||||
WorkName = element.WorkName,
|
||||
Status = element.Status,
|
||||
WorkPrice = element.WorkPrice,
|
||||
GuarantorId = element.GuarantorId,
|
||||
TechnicalWorkId = element.TechnicalWorkId,
|
||||
WorkSpareParts = element.WorkSpareParts,
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(WorkBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
|
@ -17,5 +17,6 @@ namespace ServiceStationContracts.BusinessLogicsContracts
|
||||
bool Create(RepairBindingModel model);
|
||||
bool Update(RepairBindingModel model);
|
||||
bool Delete(RepairBindingModel model);
|
||||
}
|
||||
bool AddSparePartToRepair(RepairSearchModel model, int[] spareparts);
|
||||
}
|
||||
}
|
||||
|
@ -17,5 +17,6 @@ namespace ServiceStationContracts.BusinessLogicsContracts
|
||||
bool Create(WorkBindingModel model);
|
||||
bool Update(WorkBindingModel model);
|
||||
bool Delete(WorkBindingModel model);
|
||||
}
|
||||
bool AddSparePartToWork(WorkSearchModel model, int[] spareparts);
|
||||
}
|
||||
}
|
||||
|
@ -13,5 +13,6 @@ namespace ServiceStationContracts.SearchModels
|
||||
public string? GuarantorFIO { get; set; }
|
||||
public string? GuarantorEmail { get; set; }
|
||||
public string? GuarantorNumber { get; set; }
|
||||
}
|
||||
public string? GuarantorPassword { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using ServiceStationDataModels.Enums;
|
||||
using Newtonsoft.Json;
|
||||
using ServiceStationDataModels.Enums;
|
||||
using ServiceStationDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -27,5 +28,13 @@ namespace ServiceStationContracts.ViewModels
|
||||
public int? DefectId { get; set; }
|
||||
|
||||
public Dictionary<int, ISparePartModel> RepairSpareParts { get; set; } = new();
|
||||
}
|
||||
|
||||
public RepairViewModel() { }
|
||||
|
||||
[JsonConstructor]
|
||||
public RepairViewModel(Dictionary<int, SparePartViewModel> RepairSpareParts)
|
||||
{
|
||||
this.RepairSpareParts = RepairSpareParts.ToDictionary(x => x.Key, x => x.Value as ISparePartModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using ServiceStationDataModels.Enums;
|
||||
using Newtonsoft.Json;
|
||||
using ServiceStationDataModels.Enums;
|
||||
using ServiceStationDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
@ -23,5 +24,13 @@ namespace ServiceStationContracts.ViewModels
|
||||
public int? TechnicalWorkId { get; set; }
|
||||
|
||||
public Dictionary<int, ISparePartModel> WorkSpareParts { get; set; } = new();
|
||||
}
|
||||
|
||||
public WorkViewModel() { }
|
||||
|
||||
[JsonConstructor]
|
||||
public WorkViewModel(Dictionary<int, SparePartViewModel> WorkSpareParts)
|
||||
{
|
||||
this.WorkSpareParts = WorkSpareParts.ToDictionary(x => x.Key, x => x.Value as ISparePartModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,8 +14,6 @@ namespace ServiceStationDataModels.Enums
|
||||
|
||||
Выполняется = 1,
|
||||
|
||||
Готова = 2,
|
||||
|
||||
Завершена = 3
|
||||
Готова = 2
|
||||
}
|
||||
}
|
@ -40,15 +40,15 @@ namespace ServiceStationDatabaseImplement.Implements
|
||||
public GuarantorViewModel? GetElement(GuarantorSearchModel model)
|
||||
{
|
||||
using var context = new ServiceStationDatabase();
|
||||
if (!model.Id.HasValue && !string.IsNullOrEmpty(model.GuarantorFIO)) return null;
|
||||
if (!model.Id.HasValue && !string.IsNullOrEmpty(model.GuarantorNumber) && string.IsNullOrEmpty(model.GuarantorPassword)) return null;
|
||||
|
||||
if (!string.IsNullOrEmpty(model.GuarantorFIO))
|
||||
if (!string.IsNullOrEmpty(model.GuarantorNumber) && !string.IsNullOrEmpty(model.GuarantorPassword))
|
||||
{
|
||||
return context.Guarantors
|
||||
.Include(x => x.SpareParts)
|
||||
.Include(x => x.Repairs)
|
||||
.Include(x => x.Works)
|
||||
.FirstOrDefault(x => x.GuarantorFIO.Contains(model.GuarantorFIO))?
|
||||
.FirstOrDefault(x => x.GuarantorNumber.Contains(model.GuarantorNumber) && x.GuarantorPassword.Contains(model.GuarantorPassword))?
|
||||
.GetViewModel;
|
||||
}
|
||||
return context.Guarantors
|
||||
|
@ -76,8 +76,12 @@ namespace ServiceStationDatabaseImplement.Models
|
||||
TechnicalWorkId = model.TechnicalWorkId;
|
||||
return;
|
||||
}
|
||||
if (model.Status != WorkStatus.Неизвестен)
|
||||
{
|
||||
Status = model.Status;
|
||||
return;
|
||||
}
|
||||
WorkName = model.WorkName;
|
||||
Status = model.Status;
|
||||
WorkPrice = model.WorkPrice;
|
||||
GuarantorId = model.GuarantorId;
|
||||
}
|
||||
|
@ -1,7 +1,10 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ServiceStationContracts.BindingModels;
|
||||
using ServiceStationContracts.SearchModels;
|
||||
using ServiceStationContracts.ViewModels;
|
||||
using ServiceStationGuarantorApp.Models;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices.ComTypes;
|
||||
|
||||
namespace ServiceStationGuarantorApp.Controllers
|
||||
{
|
||||
@ -19,42 +22,41 @@ namespace ServiceStationGuarantorApp.Controllers
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Privacy()
|
||||
{
|
||||
//if (APIGuarantor.Guarantor == null)
|
||||
//{
|
||||
// return Redirect("~/Home/Enter");
|
||||
//}
|
||||
return View();
|
||||
if (APIGuarantor.Guarantor == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(APIGuarantor.Guarantor);
|
||||
}
|
||||
|
||||
//[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))
|
||||
// {
|
||||
// throw new Exception("Введите номер, ФИО и пароль");
|
||||
// }
|
||||
// APIGuarantor.PostRequest("api/guarantor/updatedata", new GuarantorBindingModel
|
||||
// {
|
||||
// Id = APIGuarantor.Guarantor.Id,
|
||||
// GuarantorNumber = number,
|
||||
// GuarantorEmail = email,
|
||||
// GuarantorFIO = FIO,
|
||||
// GuarantorPassword = password,
|
||||
// });
|
||||
[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");
|
||||
//}
|
||||
APIGuarantor.Guarantor.GuarantorNumber = number;
|
||||
APIGuarantor.Guarantor.GuarantorEmail = email;
|
||||
APIGuarantor.Guarantor.GuarantorFIO = FIO;
|
||||
APIGuarantor.Guarantor.GuarantorPassword = password;
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult Error()
|
||||
@ -62,113 +64,459 @@ namespace ServiceStationGuarantorApp.Controllers
|
||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Enter()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[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");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Register()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult ListDefectSparePartToFile()
|
||||
[HttpPost]
|
||||
public void Register(string FIO, string number, string password, string email)
|
||||
{
|
||||
return View();
|
||||
}
|
||||
if (string.IsNullOrEmpty(FIO) || string.IsNullOrEmpty(number) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(email))
|
||||
{
|
||||
throw new Exception("Введены не все данные");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult ListSparePartsToPdfFile()
|
||||
APIGuarantor.PostRequest("api/guarantor/register", new GuarantorBindingModel
|
||||
{
|
||||
GuarantorNumber = number,
|
||||
GuarantorEmail = email,
|
||||
GuarantorFIO = FIO,
|
||||
GuarantorPassword = password
|
||||
});
|
||||
Response.Redirect("Enter");
|
||||
return;
|
||||
}
|
||||
|
||||
//......................................................... Запчасть..............................................................................
|
||||
|
||||
public IActionResult ListSpareParts()
|
||||
{
|
||||
if (APIGuarantor.Guarantor == null)
|
||||
{
|
||||
return RedirectToAction("Enter");
|
||||
}
|
||||
return View(APIGuarantor.GetRequest<List<SparePartViewModel>>($"api/main/getsparepartlist?guarantorId={APIGuarantor.Guarantor.Id}"));
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
//......................................................... Ремонт..............................................................................
|
||||
|
||||
public IActionResult ListRepairs()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
if (APIGuarantor.Guarantor == null)
|
||||
{
|
||||
return RedirectToAction("Enter");
|
||||
}
|
||||
return View(APIGuarantor.GetRequest<List<RepairViewModel>>($"api/main/getrepairlist?guarantorId={APIGuarantor.Guarantor.Id}"));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult ListSpareParts()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
[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);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult ListRepairs()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
public IActionResult CreateRepair()
|
||||
{
|
||||
if (APIGuarantor.Guarantor == null)
|
||||
{
|
||||
return RedirectToAction("Enter");
|
||||
}
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[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]
|
||||
public IActionResult ListWorks()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
if (APIGuarantor.Guarantor == null)
|
||||
{
|
||||
return RedirectToAction("Enter");
|
||||
}
|
||||
return View(APIGuarantor.GetRequest<List<WorkViewModel>>($"api/main/getworklist?guarantorId={APIGuarantor.Guarantor.Id}"));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult CreateSparePart()
|
||||
[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);
|
||||
}
|
||||
|
||||
public IActionResult CreateWork()
|
||||
{
|
||||
if (APIGuarantor.Guarantor == null)
|
||||
{
|
||||
return RedirectToAction("Enter");
|
||||
}
|
||||
return View();
|
||||
}
|
||||
|
||||
[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");
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
[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");
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
[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");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateWorkStatus(int work, string status)
|
||||
{
|
||||
return View();
|
||||
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");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult UpdateSparePart()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult DeleteSparePart()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult CreateRepair()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult UpdateRepair() {
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult DeleteRepair()
|
||||
public IActionResult UpdateWorkStatus()
|
||||
{
|
||||
if (APIGuarantor.Guarantor == null)
|
||||
{
|
||||
return RedirectToAction("Enter");
|
||||
}
|
||||
ViewBag.Works = APIGuarantor.GetRequest<List<WorkViewModel>>($"api/main/getworklist?guarantorId={APIGuarantor.Guarantor.Id}");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult AddSparepartToRepair()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
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}")));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult CreateWork()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
[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");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult UpdateWork()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
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}")));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult DeleteWork()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
[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");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult AddSparepartToWork()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult ListDefectSparePartToFile()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult ListSparePartsToPdfFile()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult BindingRepairToDefects()
|
||||
|
@ -13,7 +13,10 @@
|
||||
<div class="form-group">
|
||||
<label for="repair">Выберите ремонт</label>
|
||||
<select id="repair" name="repair" class="form-control">
|
||||
@* тут будет код *@
|
||||
@foreach (var repair in Model.Item1)
|
||||
{
|
||||
<option value="@repair.Id">@Html.DisplayFor(modelItem => repair.RepairName)</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
@ -27,7 +30,18 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@* тут будет код *@
|
||||
@foreach (var sparepart in Model.Item2)
|
||||
{
|
||||
<tr>
|
||||
<td class="align-middle">
|
||||
<div class="form-check">
|
||||
<input type="checkbox" class="form-check-input" name="sparepart[]" value="@sparepart.Id" id="@sparepart.Id">
|
||||
</div>
|
||||
</td>
|
||||
<td class="align-middle">@Html.DisplayFor(modelItem => sparepart.SparePartName)</td>
|
||||
<td class="align-middle">@Html.DisplayFor(modelItem => sparepart.SparePartPrice)</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
@ -13,7 +13,10 @@
|
||||
<div class="form-group">
|
||||
<label for="work">Выберите работу</label>
|
||||
<select id="work" name="work" class="form-control">
|
||||
@* тут будет код *@
|
||||
@foreach (var work in Model.Item1)
|
||||
{
|
||||
<option value="@work.Id">@Html.DisplayFor(modelItem => work.WorkName)</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
@ -27,7 +30,18 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@* тут будет код *@
|
||||
@foreach (var sparepart in Model.Item2)
|
||||
{
|
||||
<tr>
|
||||
<td class="align-middle">
|
||||
<div class="form-check">
|
||||
<input type="checkbox" class="form-check-input" name="sparepart[]" value="@sparepart.Id" id="@sparepart.Id">
|
||||
</div>
|
||||
</td>
|
||||
<td class="align-middle">@Html.DisplayFor(modelItem => sparepart.SparePartName)</td>
|
||||
<td class="align-middle">@Html.DisplayFor(modelItem => sparepart.SparePartPrice)</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
@ -8,7 +8,7 @@
|
||||
<div class="card-body">
|
||||
<div class="form-group">
|
||||
<label> Ремонт: </label>
|
||||
<select id="repair" name="repair" class="form-control"></select>
|
||||
<select id="repair" name="repair" class="form-control" asp-items="@(new SelectList(@ViewBag.Repairs, "Id", "RepairName", "RepairPrice"))"></select>
|
||||
</div>
|
||||
<br>
|
||||
<div class="text-center pb-3">
|
||||
|
@ -8,7 +8,7 @@
|
||||
<div class="card-body">
|
||||
<div class="form-group">
|
||||
<label>Запчасти: </label>
|
||||
<select id="sparepart" name="sparepart" class="form-control"></select>
|
||||
<select id="sparepart" name="sparepart" class="form-control" asp-items="@(new SelectList(@ViewBag.SpareParts, "Id", "SparePartName", "SparePartPrice"))"></select>
|
||||
</div>
|
||||
<br>
|
||||
<div class="text-center pb-3">
|
||||
|
@ -7,7 +7,7 @@
|
||||
<div class="card-body">
|
||||
<div class="form-group">
|
||||
<label> Работа: </label>
|
||||
<select id="work" name="work" class="form-control"></select>
|
||||
<select id="work" name="work" class="form-control" asp-items="@(new SelectList(@ViewBag.Works, "Id", "WorkName", "WorkPrice"))"></select>
|
||||
</div>
|
||||
<br>
|
||||
<div class="text-center pb-3">
|
||||
|
@ -11,6 +11,9 @@
|
||||
<table class="table">
|
||||
<thead class="thead-dark">
|
||||
<tr style="height: 31px">
|
||||
<th>
|
||||
Номер
|
||||
</th>
|
||||
<th>
|
||||
Название ремонта
|
||||
</th>
|
||||
@ -23,7 +26,23 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@* тут будет код *@
|
||||
@foreach (var item in Model)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Id)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.RepairName)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.RepairStartDate)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.RepairPrice)
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="flex-column justify-content-md-center">
|
||||
|
@ -1,5 +1,6 @@
|
||||
@using ServiceStationContracts.ViewModels
|
||||
|
||||
@model List<SparePartViewModel>
|
||||
@{
|
||||
ViewData["Title"] = "ListSpareParts";
|
||||
}
|
||||
@ -9,6 +10,9 @@
|
||||
<table class="table">
|
||||
<thead class="thead-dark">
|
||||
<tr style="height: 31px">
|
||||
<th>
|
||||
Номер
|
||||
</th>
|
||||
<th>
|
||||
Название
|
||||
</th>
|
||||
@ -18,7 +22,20 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@* тут будет код *@
|
||||
@foreach (var item in Model)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Id)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.SparePartName)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.SparePartPrice)
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="flex-column justify-content-md-center">
|
||||
|
@ -1,4 +1,6 @@
|
||||
|
||||
@using ServiceStationContracts.ViewModels
|
||||
|
||||
@model List<WorkViewModel>
|
||||
@{
|
||||
ViewData["Title"] = "ListWorks";
|
||||
}
|
||||
@ -8,6 +10,9 @@
|
||||
<table class="table">
|
||||
<thead class="thead-dark">
|
||||
<tr style="height: 31px">
|
||||
<th>
|
||||
Номер
|
||||
</th>
|
||||
<th>
|
||||
Название работы
|
||||
</th>
|
||||
@ -20,7 +25,23 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@* тут будет код *@
|
||||
@foreach (var item in Model)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Id)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.WorkName)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Status)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.WorkPrice)
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="flex-column justify-content-md-center">
|
||||
@ -39,5 +60,9 @@
|
||||
<div class="text-center">
|
||||
<a asp-controller="Home" asp-action="DeleteWork" class="btn btn-outline-dark text-center d-flex justify-content-md-center">Удалить</a>
|
||||
</div>
|
||||
|
||||
<div class="text-center">
|
||||
<a asp-controller="Home" asp-action="UpdateWorkStatus" class="btn btn-outline-dark text-center d-flex justify-content-md-center">Изменить статус работы</a>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
@ -8,7 +8,7 @@
|
||||
<div class="card-body ">
|
||||
<div class="form-group">
|
||||
<label>Ремонт: </label>
|
||||
<select id="repair" name="repair" class="form-control"></select>
|
||||
<select id="repair" name="repair" class="form-control" asp-items="@(new SelectList(@ViewBag.Repairs, "Id", "RepairName", "RepairPrice"))"></select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Название ремонта</label>
|
||||
@ -16,7 +16,7 @@
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Стоимость ремонта</label>
|
||||
<input type="number" min="100" step="100" id="repairPrice" placeholder="Введите стоимость ремонта" name="repairPrice" class="form-control" />
|
||||
<input type="number" min="0" step="100" id="repairPrice" placeholder="Введите стоимость ремонта" name="repairPrice" class="form-control" />
|
||||
</div>
|
||||
<table class="table">
|
||||
<thead>
|
||||
@ -25,7 +25,7 @@
|
||||
<th scope="col">Стоимость запчасти</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tbody id="table-elements">
|
||||
@* тут будет код *@
|
||||
</tbody>
|
||||
</table>
|
||||
@ -38,4 +38,29 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</form>
|
||||
|
||||
@section Scripts
|
||||
{
|
||||
<script>
|
||||
function check() {
|
||||
var repair = $('#repair').val();
|
||||
if (repair) {
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
url: "/Home/GetRepair",
|
||||
data: { repairId: repair },
|
||||
success: function (result) {
|
||||
$('#repairName').val(result.item1.repairName);
|
||||
$('#repairPrice').val(result.item1.repairPrice);
|
||||
$('#table-elements').html(result.item2);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
check();
|
||||
$('#repair').on('change', function () {
|
||||
check();
|
||||
});
|
||||
</script>
|
||||
}
|
@ -8,7 +8,7 @@
|
||||
<div class="card-body ">
|
||||
<div class="form-group">
|
||||
<label>Запчасти: </label>
|
||||
<select id="sparepart" name="sparepart" class="form-control"></select>
|
||||
<select id="sparepart" name="sparepart" class="form-control" asp-items="@(new SelectList(@ViewBag.SpareParts, "Id", "SparePartName", "SparePartPrice"))"></select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Название запчасти</label>
|
||||
@ -16,7 +16,7 @@
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Стоимость запчасти</label>
|
||||
<input type="text" id="sparepartPrice" placeholder="Введите стоимость запчасти" name="sparepartPriced" class="form-control" step="1" />
|
||||
<input type="text" id="sparepartPrice" placeholder="Введите стоимость запчасти" name="sparepartPrice" class="form-control" step="1" />
|
||||
</div>
|
||||
<br>
|
||||
<div class="text-center pb-3">
|
||||
@ -27,4 +27,29 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</form>
|
||||
|
||||
@section Scripts
|
||||
{
|
||||
<script>
|
||||
function check() {
|
||||
var sparepart = $('#sparepart').val();
|
||||
if (sparepart) {
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
url: "/Home/GetSparePart",
|
||||
data: { sparepartId: sparepart },
|
||||
success: function (result) {
|
||||
$('#sparepartName').val(result.item1.sparepartName);
|
||||
$('#sparepartPrice').val(result.item1.sparepartPrice);
|
||||
$('#table-elements').html(result.item2);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
check();
|
||||
$('#sparepart').on('change', function () {
|
||||
check();
|
||||
});
|
||||
</script>
|
||||
}
|
@ -1,6 +1,4 @@
|
||||
|
||||
|
||||
@{
|
||||
@{
|
||||
ViewData["Title"] = "UpdateWork";
|
||||
}
|
||||
|
||||
@ -9,7 +7,7 @@
|
||||
<div class="card-body ">
|
||||
<div class="form-group">
|
||||
<label>Работа: </label>
|
||||
<select id="work" name="work" class="form-control"></select>
|
||||
<select id="work" name="work" class="form-control" asp-items="@(new SelectList(@ViewBag.Works, "Id", "WorkName", "WorkPrice"))"></select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Название работы</label>
|
||||
@ -17,7 +15,7 @@
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Стоимость работы</label>
|
||||
<input type="number" min="100" step="100" id="workPrice" placeholder="Введите стоимость работы" name="workPrice" class="form-control" />
|
||||
<input type="number" min="0" step="100" id="workPrice" placeholder="Введите стоимость работы" name="workPrice" class="form-control" />
|
||||
</div>
|
||||
<table class="table">
|
||||
<thead>
|
||||
@ -26,7 +24,7 @@
|
||||
<th scope="col">Стоимость запчасти</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tbody id="table-elements">
|
||||
@* тут будет код *@
|
||||
</tbody>
|
||||
</table>
|
||||
@ -40,3 +38,27 @@
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@section Scripts
|
||||
{
|
||||
<script>
|
||||
function check() {
|
||||
var work = $('#work').val();
|
||||
if (work) {
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
url: "/Home/GetWork",
|
||||
data: { workId: work },
|
||||
success: function (result) {
|
||||
$('#workName').val(result.item1.WorkName);
|
||||
$('#table-elements').html(result.item2);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
check();
|
||||
$('#work').on('change', function () {
|
||||
check();
|
||||
});
|
||||
</script>
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
@{
|
||||
ViewData["Title"] = "UpdateWorkStatus";
|
||||
}
|
||||
|
||||
<form method="post">
|
||||
<div class="container d-flex justify-content-center align-items-center w-25">
|
||||
<div class="card-body">
|
||||
<div class="form-group">
|
||||
<label> Работа: </label>
|
||||
<select id="work" name="work" class="form-control" asp-items="@(new SelectList(@ViewBag.Works, "Id", "WorkName", "WorkPrice"))"></select>
|
||||
</div>
|
||||
<br>
|
||||
<div class="text-center pb-3">
|
||||
<input name="status" type="submit" value="Отдать на выполнение" class="btn btn-outline-dark text-center w-100" />
|
||||
</div>
|
||||
<div class="text-center pb-3">
|
||||
<input name="status" type="submit" value="Готова" class="btn btn-outline-dark text-center w-100" />
|
||||
</div>
|
||||
<div class="text-center">
|
||||
<input name="status" type="submit" value="Назад" class="btn btn-outline-dark text-center w-100" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
@ -6,5 +6,5 @@
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"IPAddress": "http://localhost:5244/"
|
||||
"IPAddress": "https://localhost:7288/"
|
||||
}
|
||||
|
@ -0,0 +1,67 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ServiceStationContracts.BindingModels;
|
||||
using ServiceStationContracts.BusinessLogicsContracts;
|
||||
using ServiceStationContracts.SearchModels;
|
||||
using ServiceStationContracts.ViewModels;
|
||||
|
||||
namespace ServiceStationRestApi.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class GuarantorController : Controller
|
||||
{
|
||||
private readonly IGuarantorLogic _glogic;
|
||||
private readonly ILogger _logger;
|
||||
public GuarantorController(IGuarantorLogic glogic, ILogger<GuarantorController> logger)
|
||||
{
|
||||
_glogic = glogic;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Register(GuarantorBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_glogic.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка регистрации");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public GuarantorViewModel? Login(string guarantorNumber, string password)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _glogic.ReadElement(new GuarantorSearchModel
|
||||
{
|
||||
GuarantorNumber = guarantorNumber,
|
||||
GuarantorPassword = password
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка входа в систему");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateGuarantor(GuarantorBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_glogic.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления данных");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -15,13 +15,19 @@ namespace ServiceStationRestApi.Controllers
|
||||
private readonly ICarLogic _clogic;
|
||||
private readonly IDefectLogic _dlogic;
|
||||
private readonly ITechnicalWorkLogic _tlogic;
|
||||
private readonly ISparePartLogic _splogic;
|
||||
private readonly IRepairLogic _rlogic;
|
||||
private readonly IWorkLogic _wlogic;
|
||||
|
||||
public MainController(ILogger<MainController> logger, ICarLogic clogic, IDefectLogic dlogic, ITechnicalWorkLogic tlogic)
|
||||
public MainController(ILogger<MainController> logger, ICarLogic clogic, IDefectLogic dlogic, ITechnicalWorkLogic tlogic, ISparePartLogic splogic, IRepairLogic rlogic, IWorkLogic wlogic)
|
||||
{
|
||||
_logger = logger;
|
||||
_clogic = clogic;
|
||||
_dlogic = dlogic;
|
||||
_tlogic = tlogic;
|
||||
_splogic = splogic;
|
||||
_rlogic = rlogic;
|
||||
_wlogic = wlogic;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@ -245,5 +251,270 @@ namespace ServiceStationRestApi.Controllers
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<SparePartViewModel>? GetSparePartList(int guarantorId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _splogic.ReadList(new SparePartSearchModel
|
||||
{
|
||||
GuarantorId = guarantorId
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка запчастей");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateSparePart(SparePartBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_splogic.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания запчасти");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateSparePart(SparePartBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_splogic.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления запчасти");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void DeleteSparePart(SparePartBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_splogic.Delete(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления запчасти");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<RepairViewModel>? GetRepairList(int guarantorId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _rlogic.ReadList(new RepairSearchModel
|
||||
{
|
||||
GuarantorId = guarantorId
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка ремонтов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateRepair(RepairBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_rlogic.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания ремонта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateRepair(RepairBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_rlogic.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления ремонта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void DeleteRepair(RepairBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_rlogic.Delete(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления ремонта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<WorkViewModel>? GetWorkList(int guarantorId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _wlogic.ReadList(new WorkSearchModel
|
||||
{
|
||||
GuarantorId = guarantorId
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка работ");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateWork(WorkBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_wlogic.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания работы");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateWork(WorkBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_wlogic.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления работы");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateWorkStatus(WorkBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_wlogic.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления статуса работы");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateWorkStatusExecution(WorkBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_wlogic.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления статуса работы");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void DeleteWork(WorkBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_wlogic.Delete(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления работы");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void AddSparePartToRepair(Tuple<RepairSearchModel, int[]> model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_rlogic.AddSparePartToRepair(model.Item1, model.Item2);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка добавления запчасти в ремонт.");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void AddSparePartToWork(Tuple<WorkSearchModel, int[]> model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_wlogic.AddSparePartToWork(model.Item1, model.Item2);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка добавления запчасти в работу.");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public Tuple<RepairViewModel, List<Tuple<string, string>>>? GetRepair(int repairId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var elem = _rlogic.ReadElement(new RepairSearchModel { Id = repairId });
|
||||
if (elem == null) return null;
|
||||
return Tuple.Create(elem, elem.RepairSpareParts.Select(x => Tuple.Create(x.Value.SparePartName, x.Value.SparePartPrice.ToString("F2"))).ToList());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения запчасти по id={Id}", repairId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public Tuple<WorkViewModel, List<Tuple<string, string>>>? GetWork(int workId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var elem = _wlogic.ReadElement(new WorkSearchModel { Id = workId });
|
||||
if (elem == null) return null;
|
||||
return Tuple.Create(elem, elem.WorkSpareParts.Select(x => Tuple.Create(x.Value.SparePartName, x.Value.SparePartPrice.ToString("F2"))).ToList());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения запчасти по id={Id}", workId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,11 +16,22 @@ builder.Services.AddTransient<IDefectStorage, DefectStorage>();
|
||||
builder.Services.AddTransient<IExecutorStorage, ExecutorStorage>();
|
||||
builder.Services.AddTransient<ITechnicalWorkStorage, TechnicalWorkStorage>();
|
||||
|
||||
builder.Services.AddTransient<ISparePartStorage, SparePartStorage>();
|
||||
builder.Services.AddTransient<IWorkStorage, WorkStorage>();
|
||||
builder.Services.AddTransient<IRepairStorage, RepairStorage>();
|
||||
builder.Services.AddTransient<IGuarantorStorage, GuarantorStorage>();
|
||||
|
||||
|
||||
builder.Services.AddTransient<ICarLogic, CarLogic>();
|
||||
builder.Services.AddTransient<IDefectLogic, DefectLogic>();
|
||||
builder.Services.AddTransient<IExecutorLogic, ExecutorLogic>();
|
||||
builder.Services.AddTransient<ITechnicalWorkLogic, TechnicalWorkLogic>();
|
||||
|
||||
builder.Services.AddTransient<ISparePartLogic, SparePartLogic>();
|
||||
builder.Services.AddTransient<IWorkLogic, WorkLogic>();
|
||||
builder.Services.AddTransient<IRepairLogic, RepairLogic>();
|
||||
builder.Services.AddTransient<IGuarantorLogic, GuarantorLogic>();
|
||||
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
|
Loading…
x
Reference in New Issue
Block a user