2024-11-18 23:37:50 +04:00
|
|
|
|
using CandidateReviewClientApp.Models;
|
|
|
|
|
using CandidateReviewContracts.BindingModels;
|
|
|
|
|
using CandidateReviewContracts.ViewModels;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
|
|
|
|
namespace CandidateReviewClientApp.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class UserController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<UserController> _logger;
|
|
|
|
|
|
|
|
|
|
public UserController(ILogger<UserController> logger)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult UserProfile(int? id)
|
|
|
|
|
{
|
|
|
|
|
var userId = id ?? APIClient.User.Id;
|
|
|
|
|
|
|
|
|
|
var model = APIClient.GetRequest<UserViewModel>($"api/user/profile?id={userId}");
|
|
|
|
|
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
2024-11-19 16:45:59 +04:00
|
|
|
|
return RedirectToAction("/Home/Index");
|
2024-11-18 23:37:50 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return View(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult UserProfileEdit()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("/Home/Enter");
|
|
|
|
|
}
|
2024-11-19 16:45:59 +04:00
|
|
|
|
var model = APIClient.GetRequest<UserViewModel?>($"api/user/profile?id={APIClient.User.Id}");
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction("/Home/Index");
|
|
|
|
|
}
|
|
|
|
|
return View(model);
|
2024-11-18 23:37:50 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void UserProfileEdit(UserBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
APIClient.PostRequest("api/user/update", new UserBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
Surname = model.Surname,
|
|
|
|
|
Name = model.Name,
|
2024-11-19 16:45:59 +04:00
|
|
|
|
LastName = model.LastName,
|
|
|
|
|
CompanyId = model.CompanyId,
|
2024-11-18 23:37:50 +04:00
|
|
|
|
Email = model.Email,
|
|
|
|
|
Password = model.Password,
|
|
|
|
|
EmailConfirmed = model.EmailConfirmed,
|
|
|
|
|
Role = model.Role,
|
2024-11-19 16:45:59 +04:00
|
|
|
|
AvatarFilePath = model.AvatarFilePath,
|
|
|
|
|
PhoneNumber = model.PhoneNumber
|
2024-11-18 23:37:50 +04:00
|
|
|
|
});
|
|
|
|
|
|
2024-11-19 16:45:59 +04:00
|
|
|
|
Response.Redirect($"/User/UserProfile/{model.Id}");
|
2024-11-18 23:37:50 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public void Logout()
|
|
|
|
|
{
|
|
|
|
|
APIClient.User = null;
|
|
|
|
|
Response.Redirect("/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-19 16:45:59 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Delete(UserBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Доступно только авторизованным пользователям");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
APIClient.PostRequest($"api/user/delete", new UserBindingModel {
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
Surname = model.Surname,
|
|
|
|
|
Name = model.Name,
|
|
|
|
|
LastName = model.LastName,
|
|
|
|
|
CompanyId = model.CompanyId,
|
|
|
|
|
Email = model.Email,
|
|
|
|
|
Password = model.Password,
|
|
|
|
|
EmailConfirmed = model.EmailConfirmed,
|
|
|
|
|
Role = model.Role,
|
|
|
|
|
AvatarFilePath = model.AvatarFilePath,
|
|
|
|
|
PhoneNumber = model.PhoneNumber
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Response.Redirect("/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-18 23:37:50 +04:00
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
|
|
|
public IActionResult Error()
|
|
|
|
|
{
|
|
|
|
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|