125 lines
3.6 KiB
C#
125 lines
3.6 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.Formatters;
|
|
using ServiceSourceClientApp.Models;
|
|
using ServiceSourceExecutorApp;
|
|
using ServiceStationContracts.BindingModels;
|
|
using ServiceStationContracts.ViewModels;
|
|
using System.Diagnostics;
|
|
|
|
namespace ServiceSourceClientApp.Controllers {
|
|
public class HomeController : Controller {
|
|
private readonly ILogger<HomeController> _logger;
|
|
|
|
public HomeController(ILogger<HomeController> logger) {
|
|
_logger = logger;
|
|
}
|
|
|
|
[HttpGet]
|
|
public IActionResult Index() {
|
|
if (APIClient.executor == null) {
|
|
return Redirect("~/Home/Enter");
|
|
}
|
|
|
|
var view = APIClient.GetRequest<List<WorkViewModel>>($"api/Main/GetWorks?_executorId={APIClient.executor.Id}");
|
|
return View(view);
|
|
}
|
|
|
|
[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.executor = APIClient.GetRequest<ExecutorViewModel>($"api/main/Login?email={email}&password={password}");
|
|
if (APIClient.executor == 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/Main/Register", new ExecutorBindingModel {
|
|
Email = email,
|
|
Password = password,
|
|
FIO = fio
|
|
});
|
|
Response.Redirect("Enter");
|
|
return;
|
|
}
|
|
|
|
[HttpGet]
|
|
public IActionResult Privacy() {
|
|
if (APIClient.executor == null) {
|
|
return Redirect("~/Home/Enter");
|
|
}
|
|
return View(APIClient.executor);
|
|
}
|
|
|
|
[HttpPost]
|
|
public void Privacy(string email, string password, string fio) {
|
|
if (APIClient.executor == null) {
|
|
Response.Redirect("~/Home/Enter");
|
|
return;
|
|
}
|
|
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) {
|
|
throw new Exception("Ââåäèòå ïî÷òó, ïàðîëü è ÔÈÎ");
|
|
}
|
|
APIClient.PostRequest("api/Main/UpdateData", new ExecutorBindingModel {
|
|
Id = APIClient.executor.Id,
|
|
Email = email,
|
|
Password = password,
|
|
FIO = fio
|
|
});
|
|
|
|
APIClient.executor.FIO = fio;
|
|
APIClient.executor.Email = email;
|
|
APIClient.executor.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 CreateWork() {
|
|
ViewBag.Tasks = APIClient.GetRequest<List<TaskViewModel>>($"api/Main/GetTasks?");
|
|
return View(APIClient.GetRequest<List<ClientViewModel>>($"api/Main/GetClients?"));
|
|
}
|
|
|
|
[HttpPost]
|
|
public void CreateWork(int[] ids, int task) {
|
|
if (APIClient.executor == null) {
|
|
Response.Redirect("~/Home/Enter");
|
|
return;
|
|
}
|
|
APIClient.PostRequest("api/Main/CreateWork", new WorkFromWebBindingModel {
|
|
Price = Calc(task, ids.Length),
|
|
ExecutorId = APIClient.executor.Id,
|
|
TaskId = task,
|
|
client_ids = ids
|
|
});
|
|
}
|
|
|
|
[HttpPost]
|
|
public double Calc(int task, int count) {
|
|
var task_info = APIClient.GetRequest<TaskViewModel>($"api/Main/GetTask?_taskId={task}") ?? throw new Exception("Îøèáêà ïîëó÷åèÿ äàííûõ");
|
|
return task_info.Price + 700 * count;
|
|
}
|
|
}
|
|
}
|