2024-11-18 23:37:50 +04:00
|
|
|
|
using CandidateReviewContracts.BindingModels;
|
|
|
|
|
using CandidateReviewContracts.ViewModels;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
namespace CandidateReviewClientApp.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class CompanyController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<CompanyController> _logger;
|
|
|
|
|
public CompanyController(ILogger<CompanyController> logger)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult CompanyProfile(int? id)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
if (id.HasValue)
|
|
|
|
|
{
|
|
|
|
|
APIClient.Company = APIClient.GetRequest<CompanyViewModel?>($"api/company/profile?id={id}");
|
|
|
|
|
}
|
|
|
|
|
var model = APIClient.Company;
|
|
|
|
|
return View(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult EditCompanyProfile(int? id)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
if (!id.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return View(new CompanyViewModel());
|
|
|
|
|
}
|
|
|
|
|
var model = APIClient.GetRequest<CompanyViewModel?>($"api/company/profile?id={id}");
|
|
|
|
|
if (model != null)
|
|
|
|
|
{
|
2024-11-19 16:45:59 +04:00
|
|
|
|
APIClient.PostRequest($"api/user/update", new UserBindingModel {
|
|
|
|
|
Id = APIClient.User.Id,
|
|
|
|
|
CompanyId = model.Id,
|
|
|
|
|
Surname = APIClient.User.Surname,
|
|
|
|
|
Name = APIClient.User.Name,
|
|
|
|
|
LastName = APIClient.User.LastName,
|
|
|
|
|
Email = APIClient.User.Email,
|
|
|
|
|
Password = APIClient.User.Password,
|
|
|
|
|
EmailConfirmed = APIClient.User.EmailConfirmed,
|
|
|
|
|
Role = APIClient.User.Role,
|
|
|
|
|
AvatarFilePath = APIClient.User.AvatarFilePath,
|
|
|
|
|
PhoneNumber = APIClient.User.PhoneNumber
|
|
|
|
|
});
|
2024-11-18 23:37:50 +04:00
|
|
|
|
}
|
|
|
|
|
return View(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void EditCompanyProfile(CompanyBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Доступно только авторизованным пользователям");
|
|
|
|
|
}
|
|
|
|
|
if (model.Id != 0)
|
|
|
|
|
{
|
|
|
|
|
APIClient.PostRequest("api/company/update", model);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
APIClient.PostRequest("api/company/create", model);
|
|
|
|
|
}
|
2024-11-19 16:45:59 +04:00
|
|
|
|
Response.Redirect($"/Company/CompanyProfile/{model.Id}");
|
2024-11-18 23:37:50 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Delete(int id)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Доступно только авторизованным пользователям");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
APIClient.PostRequest($"api/company/delete", new CompanyBindingModel { Id = id });
|
|
|
|
|
Response.Redirect("/Home/Index");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|