using CandidateReviewContracts.BindingModels; using CandidateReviewContracts.ViewModels; using Microsoft.AspNetCore.Mvc; namespace CandidateReviewClientApp.Controllers { public class CompanyController : Controller { private readonly ILogger _logger; public CompanyController(ILogger logger) { _logger = logger; } [HttpGet] public IActionResult CompanyProfile(int? id) { if (APIClient.User == null) { return Redirect("~/Home/Enter"); } if (id.HasValue) { APIClient.Company = APIClient.GetRequest($"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($"api/company/profile?id={id}"); if (model != null) { 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 }); } 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($"/Company/CompanyProfile/{model.Id}"); } [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"); } } }