78 lines
2.2 KiB
C#
78 lines
2.2 KiB
C#
|
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)
|
|||
|
{
|
|||
|
return RedirectToAction("Index");
|
|||
|
}
|
|||
|
|
|||
|
return View(model);
|
|||
|
}
|
|||
|
|
|||
|
[HttpGet]
|
|||
|
public IActionResult UserProfileEdit()
|
|||
|
{
|
|||
|
if (APIClient.User == null)
|
|||
|
{
|
|||
|
return Redirect("/Home/Enter");
|
|||
|
}
|
|||
|
return View(APIClient.User);
|
|||
|
}
|
|||
|
|
|||
|
[HttpPost]
|
|||
|
public void UserProfileEdit(UserBindingModel model)
|
|||
|
{
|
|||
|
APIClient.PostRequest("api/user/update", new UserBindingModel
|
|||
|
{
|
|||
|
Id = model.Id,
|
|||
|
Surname = model.Surname,
|
|||
|
Name = model.Name,
|
|||
|
LastName = model.LastName ?? null,
|
|||
|
CompanyId = model.CompanyId ?? null,
|
|||
|
Email = model.Email,
|
|||
|
Password = model.Password,
|
|||
|
EmailConfirmed = model.EmailConfirmed,
|
|||
|
Role = model.Role,
|
|||
|
AvatarFilePath = model.AvatarFilePath ?? null,
|
|||
|
PhoneNumber = model.PhoneNumber ?? null
|
|||
|
});
|
|||
|
|
|||
|
Response.Redirect("/User/UserProfile");
|
|||
|
}
|
|||
|
|
|||
|
[HttpGet]
|
|||
|
public void Logout()
|
|||
|
{
|
|||
|
APIClient.User = null;
|
|||
|
Response.Redirect("/Home/Enter");
|
|||
|
}
|
|||
|
|
|||
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|||
|
public IActionResult Error()
|
|||
|
{
|
|||
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|||
|
}
|
|||
|
}
|
|||
|
}
|