2023-04-28 10:09:23 +04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2023-04-28 10:19:51 +04:00
|
|
|
|
using TravelCompanyClientApp;
|
2023-04-28 10:09:23 +04:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using TravelCompanyClientApp.Models;
|
|
|
|
|
using TravelCompanyContracts.BindingModels;
|
|
|
|
|
using TravelCompanyContracts.ViewModels;
|
|
|
|
|
|
2023-04-28 00:02:22 +04:00
|
|
|
|
|
2023-04-28 10:09:23 +04:00
|
|
|
|
namespace AbstractShowClientApp.Controllers
|
2023-04-28 00:02:22 +04:00
|
|
|
|
{
|
|
|
|
|
public class HomeController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<HomeController> _logger;
|
|
|
|
|
public HomeController(ILogger<HomeController> logger)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
public IActionResult Index()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
View(APIClient.GetRequest<List<OrderViewModel>>($"api/main/getorders?clientId={APIClient.Client.Id}"));
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Privacy()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
return View(APIClient.Client);
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Privacy(string login, string password, string fio)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(login) ||
|
|
|
|
|
string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введите логин, пароль и ФИО");
|
|
|
|
|
}
|
|
|
|
|
APIClient.PostRequest("api/client/updatedata", new
|
|
|
|
|
ClientBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = APIClient.Client.Id,
|
|
|
|
|
ClientFIO = fio,
|
|
|
|
|
Email = login,
|
|
|
|
|
Password = password
|
|
|
|
|
});
|
|
|
|
|
APIClient.Client.ClientFIO = fio;
|
|
|
|
|
APIClient.Client.Email = login;
|
|
|
|
|
APIClient.Client.Password = password;
|
|
|
|
|
Response.Redirect("Index");
|
|
|
|
|
}
|
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None,
|
|
|
|
|
NoStore = true)]
|
|
|
|
|
public IActionResult Error()
|
|
|
|
|
{
|
|
|
|
|
return View(new ErrorViewModel
|
|
|
|
|
{
|
|
|
|
|
RequestId =
|
|
|
|
|
Activity.Current?.Id ?? HttpContext.TraceIdentifier
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Enter()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Enter(string login, string password)
|
|
|
|
|
{
|
2023-04-28 10:09:23 +04:00
|
|
|
|
if (string.IsNullOrEmpty(login) ||
|
|
|
|
|
string.IsNullOrEmpty(password))
|
2023-04-28 00:02:22 +04:00
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введите логин и пароль");
|
|
|
|
|
}
|
|
|
|
|
APIClient.Client =
|
|
|
|
|
APIClient.GetRequest<ClientViewModel>($"api/client/login?login={login}&password={password}");
|
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Неверный логин/пароль");
|
|
|
|
|
}
|
|
|
|
|
Response.Redirect("Index");
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Register()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Register(string login, string password, string fio)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(login) ||
|
|
|
|
|
string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введите логин, пароль и ФИО");
|
|
|
|
|
}
|
2023-04-28 10:09:23 +04:00
|
|
|
|
APIClient.PostRequest("api/client/register", new
|
|
|
|
|
ClientBindingModel
|
2023-04-28 00:02:22 +04:00
|
|
|
|
{
|
|
|
|
|
ClientFIO = fio,
|
|
|
|
|
Email = login,
|
|
|
|
|
Password = password
|
|
|
|
|
});
|
|
|
|
|
Response.Redirect("Enter");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Create()
|
|
|
|
|
{
|
|
|
|
|
ViewBag.Products =
|
2023-04-28 10:09:23 +04:00
|
|
|
|
APIClient.GetRequest<List<TravelViewModel>>("api/main/getproductlist");
|
2023-04-28 00:02:22 +04:00
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Create(int travel, int count)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
if (count <= 0)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Количество и сумма должны быть больше 0");
|
|
|
|
|
}
|
|
|
|
|
APIClient.PostRequest("api/main/createorder", new
|
|
|
|
|
OrderBindingModel
|
|
|
|
|
{
|
|
|
|
|
ClientId = APIClient.Client.Id,
|
|
|
|
|
TravelId = travel,
|
|
|
|
|
Count = count,
|
|
|
|
|
Sum = Calc(count, travel)
|
|
|
|
|
});
|
|
|
|
|
Response.Redirect("Index");
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public double Calc(int count, int travel)
|
|
|
|
|
{
|
|
|
|
|
var prod =
|
2023-04-28 10:09:23 +04:00
|
|
|
|
APIClient.GetRequest<TravelViewModel>($"api/main/getproduct?travelId={travel}"
|
2023-04-28 00:02:22 +04:00
|
|
|
|
);
|
|
|
|
|
return count * (prod?.Price ?? 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|