158 lines
3.7 KiB
C#
158 lines
3.7 KiB
C#
using System.Diagnostics;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using SoftwareApplication.Models;
|
|
using SoftwareContracts.BindingModels;
|
|
using SoftwareContracts.ViewModels;
|
|
|
|
namespace SoftwareApplication.Controllers
|
|
{
|
|
public class HomeController : Controller
|
|
{
|
|
private readonly ILogger<HomeController> _logger;
|
|
|
|
public HomeController(ILogger<HomeController> logger)
|
|
{
|
|
_logger = logger;
|
|
}
|
|
|
|
public IActionResult Index()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
[HttpGet]
|
|
public IActionResult Privacy()
|
|
{
|
|
if (ApiClient.User == null)
|
|
{
|
|
return Redirect("~/Home/Enter");
|
|
}
|
|
return View(ApiClient.User);
|
|
}
|
|
[HttpPost]
|
|
public void Privacy(string login, string password)
|
|
{
|
|
if (ApiClient.User == null)
|
|
{
|
|
throw new Exception("Доступно только авторизованным пользователям");
|
|
}
|
|
if (string.IsNullOrEmpty(login) ||
|
|
string.IsNullOrEmpty(password))
|
|
{
|
|
throw new Exception("Введите логин и пароль");
|
|
}
|
|
ApiClient.PostRequest("api/user/updatedata", new
|
|
UserBindingModel
|
|
{
|
|
Id = ApiClient.User.Id,
|
|
Email = login,
|
|
Password = password
|
|
});
|
|
ApiClient.User.Email = login;
|
|
ApiClient.User.Password = password;
|
|
Response.Redirect("Index");
|
|
}
|
|
|
|
[HttpGet]
|
|
public IActionResult Enter()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
public IActionResult Administration()
|
|
{
|
|
|
|
return View();
|
|
}
|
|
[HttpPost]
|
|
public void Enter(string login, string password)
|
|
{
|
|
if (string.IsNullOrEmpty(login) ||
|
|
string.IsNullOrEmpty(password))
|
|
{
|
|
throw new Exception("Введите логин и пароль");
|
|
}
|
|
ApiClient.User =
|
|
ApiClient.GetRequest<UserViewModel>($"api/user/login?login={login}&password={password}");
|
|
if (ApiClient.User == null)
|
|
{
|
|
throw new Exception("Неверный логин/пароль");
|
|
}
|
|
Response.Redirect("Index");
|
|
}
|
|
public IActionResult Logout()
|
|
{
|
|
ApiClient.User = null;
|
|
return RedirectToAction("Index");
|
|
}
|
|
[HttpGet]
|
|
public IActionResult Register()
|
|
{
|
|
return View();
|
|
}
|
|
[HttpPost]
|
|
public void Register(string login, string password)
|
|
{
|
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
|
|
{
|
|
throw new Exception("Введите логин и пароль");
|
|
}
|
|
ApiClient.PostRequest("api/user/register", new
|
|
UserBindingModel
|
|
{
|
|
Email = login,
|
|
Password = password
|
|
});
|
|
Response.Redirect("Enter");
|
|
return;
|
|
}
|
|
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
public IActionResult Error()
|
|
{
|
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|
}
|
|
//[HttpGet]
|
|
//public IActionResult CreateIssue(int? id)
|
|
//{
|
|
// _logger.LogInformation("Get issue by ID: {Id}", id);
|
|
// if (ApiClient.User == null)
|
|
// {
|
|
// return Redirect("~/Home/Enter");
|
|
// }
|
|
// if (!id.HasValue)
|
|
// {
|
|
// return View(new IssueViewModel());
|
|
|
|
// }
|
|
// // Загружаем список проектов в любом случае
|
|
// var projects = ApiClient.GetRequest<List<ProjectViewModel>>("api/project/getprojectlist");
|
|
// ViewBag.Projects = projects;
|
|
// var model = ApiClient.GetRequest<IssueViewModel?>($"api/issue/getissue?id={id}");
|
|
// return View(model);
|
|
|
|
//}
|
|
|
|
//[HttpPost]
|
|
//public void CreateIssue(IssueBindingModel model)
|
|
//{
|
|
// _logger.LogInformation("Create issue with params: {Params}", model);
|
|
// if (ApiClient.User == null)
|
|
// {
|
|
// throw new Exception("Доступно только авторизованным пользователям");
|
|
// }
|
|
// if (model.Id != 0)
|
|
// {
|
|
// ApiClient.PostRequest("api/issue/update", model);
|
|
// }
|
|
// else
|
|
// {
|
|
// ApiClient.PostRequest("api/issue/create", model);
|
|
// }
|
|
|
|
// Response.Redirect("/issue");
|
|
}
|
|
}
|
|
|