191 lines
4.8 KiB
C#
191 lines
4.8 KiB
C#
using CarShowroomDataModels.Dtos;
|
|
using CarShowroomDataModels.Models;
|
|
using CarShowroomDataModels.Views;
|
|
using CarShowroomManagerApp.Models;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Diagnostics;
|
|
|
|
namespace CarShowroomManagerApp.Controllers
|
|
{
|
|
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<SaleView>>($"api/sale/getsalelist"));
|
|
}
|
|
|
|
public IActionResult Clients()
|
|
{
|
|
if (ApiClient.Client == null)
|
|
{
|
|
return Redirect("~/Home/Enter");
|
|
}
|
|
return
|
|
View(ApiClient.GetRequest<List<ClientView>>($"api/client/getclientlist"));
|
|
}
|
|
|
|
[HttpGet]
|
|
public IActionResult Privacy()
|
|
{
|
|
if (ApiClient.Client == null)
|
|
{
|
|
return Redirect("~/Home/Enter");
|
|
}
|
|
return View(ApiClient.Client);
|
|
}
|
|
|
|
[HttpGet]
|
|
public IActionResult Enter()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
public void Enter(string login, string password)
|
|
{
|
|
if (string.IsNullOrEmpty(login) ||
|
|
string.IsNullOrEmpty(password))
|
|
{
|
|
throw new Exception("Введите логин и пароль");
|
|
}
|
|
ApiClient.Client = ApiClient.GetRequest<EmployeeView>($"api/employee/login?login={login}&password={password}");
|
|
if (ApiClient.Client == null)
|
|
{
|
|
throw new Exception("Неверный логин/пароль");
|
|
}
|
|
Response.Redirect("Index");
|
|
}
|
|
|
|
public IActionResult SaleCreate()
|
|
{
|
|
if (ApiClient.Client == null)
|
|
{
|
|
return Redirect("~/Home/Enter");
|
|
}
|
|
ViewBag.Cars = ApiClient.GetRequest<List<CarView>>("api/car/getcarlist");
|
|
ViewBag.Clients = ApiClient.GetRequest<List<ClientView>>("api/client/getclientlist");
|
|
ViewBag.Services = ApiClient.GetRequest<List<ServiceView>>("api/service/getservicelist");
|
|
return View();
|
|
}
|
|
|
|
//[HttpPost]
|
|
//public void SaleCreate(int manufacture, 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,
|
|
// ManufactureId = manufacture,
|
|
// Count = count,
|
|
// Sum = Calc(count, manufacture)
|
|
// });
|
|
// Response.Redirect("Index");
|
|
//}
|
|
|
|
public IActionResult ClientCreate()
|
|
{
|
|
if (ApiClient.Client == null)
|
|
{
|
|
return Redirect("~/Home/Enter");
|
|
}
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
public void ClientCreate(string phonenumber, string name)
|
|
{
|
|
if (string.IsNullOrEmpty(phonenumber) ||
|
|
string.IsNullOrEmpty(name))
|
|
{
|
|
throw new Exception("Введите номер телефона и ФИО");
|
|
}
|
|
ApiClient.PostRequest("api/client/createclient", new ClientDto
|
|
{
|
|
Name = name,
|
|
PhoneNumber = phonenumber
|
|
});
|
|
return;
|
|
}
|
|
public IActionResult ClientUpdate()
|
|
{
|
|
if (ApiClient.Client == null)
|
|
{
|
|
return Redirect("~/Home/Enter");
|
|
}
|
|
ViewBag.Clients = ApiClient.GetRequest<List<ClientView>>("api/client/getclientlist");
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
public void ClientUpdate(string phonenumber, string name)
|
|
{
|
|
if (ApiClient.Client == null)
|
|
{
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
}
|
|
if (string.IsNullOrEmpty(phonenumber) ||
|
|
string.IsNullOrEmpty(name))
|
|
{
|
|
throw new Exception("Введите логин, пароль и ФИО");
|
|
}
|
|
ApiClient.PostRequest("api/client/updateclient", new ClientDto
|
|
{
|
|
Id = ApiClient.Client.Id,
|
|
Name = name,
|
|
PhoneNumber = phonenumber
|
|
});
|
|
Response.Redirect("Clients");
|
|
}
|
|
|
|
public IActionResult SaleDelete()
|
|
{
|
|
if (ApiClient.Client == null)
|
|
{
|
|
return Redirect("~/Home/Enter");
|
|
}
|
|
ViewBag.Sales = ApiClient.GetRequest<List<SaleView>>("api/sale/getsalelist");
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
public void SaleDelete(int sale)
|
|
{
|
|
if (ApiClient.Client == null)
|
|
{
|
|
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
|
}
|
|
ApiClient.PostRequest("api/sale/deletesale", new SaleDto
|
|
{
|
|
Id = sale
|
|
});
|
|
Response.Redirect("Index");
|
|
}
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
public IActionResult Error()
|
|
{
|
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|
}
|
|
}
|
|
}
|