137 lines
4.4 KiB
C#
137 lines
4.4 KiB
C#
|
using Microsoft.AspNetCore.Mvc;
|
|||
|
using System.Diagnostics;
|
|||
|
using TaskTrackerClientApp.Models;
|
|||
|
using TaskTrackerContracts.BindingModels;
|
|||
|
using TaskTrackerContracts.ViewModels;
|
|||
|
|
|||
|
namespace TaskTrackerClientApp.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<TaskViewModel>>($"api/main/gettasks?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 UserBindingModel
|
|||
|
{
|
|||
|
Id = APIClient.Client.Id,
|
|||
|
UserFIO = fio,
|
|||
|
Email = login,
|
|||
|
Password = password
|
|||
|
});
|
|||
|
|
|||
|
APIClient.Client.UserFIO = 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)
|
|||
|
{
|
|||
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
|
|||
|
{
|
|||
|
throw new Exception("Введите логин и пароль");
|
|||
|
}
|
|||
|
APIClient.Client = APIClient.GetRequest<UserViewModel>($"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("Введите логин, пароль и ФИО");
|
|||
|
}
|
|||
|
APIClient.PostRequest("api/client/register", new UserBindingModel
|
|||
|
{
|
|||
|
UserFIO = fio,
|
|||
|
Email = login,
|
|||
|
Password = password
|
|||
|
});
|
|||
|
Response.Redirect("Enter");
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
[HttpGet]
|
|||
|
public IActionResult Create()
|
|||
|
{
|
|||
|
ViewBag.Reinforceds = APIClient.GetRequest<List<ProjectViewModel>>("api/main/getreinforcedlist");
|
|||
|
return View();
|
|||
|
}
|
|||
|
|
|||
|
[HttpPost]
|
|||
|
public void Create(int reinforced, string count)
|
|||
|
{
|
|||
|
if (APIClient.Client == null)
|
|||
|
{
|
|||
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|||
|
}
|
|||
|
APIClient.PostRequest("api/main/createorder", new TaskBindingModel
|
|||
|
{
|
|||
|
UserId = APIClient.Client.Id,
|
|||
|
ProjectId = reinforced,
|
|||
|
Title = count,
|
|||
|
Description = count
|
|||
|
});
|
|||
|
Response.Redirect("Index");
|
|||
|
}
|
|||
|
}
|
|||
|
}
|