80 lines
2.4 KiB
C#
80 lines
2.4 KiB
C#
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)
|
|
{
|
|
APIClient.PostRequest($"api/user/update", new UserBindingModel { Id = APIClient.User.Id, CompanyId = model.Id });
|
|
}
|
|
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);
|
|
}
|
|
Response.Redirect("/Home/Index");
|
|
}
|
|
|
|
[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");
|
|
}
|
|
}
|
|
}
|