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)
|
|
|
|
|
{
|
2024-11-23 21:39:18 +04:00
|
|
|
|
var userId = id ?? APIClient.User?.Id;
|
2024-11-18 23:37:50 +04:00
|
|
|
|
|
|
|
|
|
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]
|
2024-11-23 21:39:18 +04:00
|
|
|
|
public IActionResult UserProfileEdit(int? id)
|
2024-11-18 23:37:50 +04:00
|
|
|
|
{
|
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("/Home/Enter");
|
|
|
|
|
}
|
2024-11-23 21:39:18 +04:00
|
|
|
|
|
|
|
|
|
if (APIClient.Company == null)
|
2024-11-19 16:45:59 +04:00
|
|
|
|
{
|
2024-11-23 21:39:18 +04:00
|
|
|
|
return Redirect("/Home/Index");
|
2024-11-19 16:45:59 +04:00
|
|
|
|
}
|
2024-11-23 21:39:18 +04:00
|
|
|
|
|
|
|
|
|
if (!id.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return View(new UserViewModel());
|
|
|
|
|
}
|
|
|
|
|
else if (id.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var employee = APIClient.GetRequest<UserViewModel?>($"api/user/profile?id={id}");
|
|
|
|
|
return View(employee);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var model = APIClient.GetRequest<UserViewModel?>($"api/user/profile?id={APIClient.User.Id}");
|
|
|
|
|
return View(model);
|
|
|
|
|
}
|
2024-11-18 23:37:50 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void UserProfileEdit(UserBindingModel model)
|
|
|
|
|
{
|
2024-11-23 21:39:18 +04:00
|
|
|
|
if (model.Id != 0)
|
2024-11-18 23:37:50 +04:00
|
|
|
|
{
|
2024-11-23 21:39:18 +04:00
|
|
|
|
APIClient.PostRequest("api/user/update", model);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
APIClient.PostRequest("api/user/register", model);
|
|
|
|
|
if (APIClient.Company != null)
|
|
|
|
|
{
|
|
|
|
|
APIClient.Company?.Employees.Add(new UserViewModel
|
|
|
|
|
{
|
|
|
|
|
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 = CandidateReviewDataModels.Enums.RoleEnum.Сотрудник,
|
|
|
|
|
AvatarFilePath = model.AvatarFilePath,
|
|
|
|
|
PhoneNumber = model.PhoneNumber
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
Response.Redirect($"/Company/CompanyProfile/{model.CompanyId}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
|
2024-11-23 21:39:18 +04:00
|
|
|
|
public IActionResult DeleteEmployee(int id)
|
|
|
|
|
{
|
|
|
|
|
APIClient.PostRequest("api/user/delete", new UserBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = id
|
|
|
|
|
});
|
|
|
|
|
APIClient.Company = APIClient.GetRequest<CompanyViewModel?>($"api/company/profile?id={APIClient.User?.CompanyId}");
|
|
|
|
|
|
|
|
|
|
return Redirect($"~/Company/CompanyProfile");
|
|
|
|
|
}
|
|
|
|
|
|
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 });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|