67 lines
2.4 KiB
C#
67 lines
2.4 KiB
C#
using _0_Framework.Application;
|
|
using AccountManagement.Application.Contracts.Task;
|
|
using AccountManagement.Application.Contracts.Ticket;
|
|
using AccountManagement.Application.Contracts.TicketAccessAccount;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using ServiceHost.BaseControllers;
|
|
using ServiceHost.Controllers;
|
|
|
|
namespace ServiceHost.Areas.Admin.Controllers;
|
|
public record GetAdminProfileDetails(long Id, string Fullname, string Mobile, string RoleName,
|
|
List<int> Permissions, long? PositionValue,UserType UserType,bool HasTicketAccess,
|
|
int TicketCount,int TaskCount);
|
|
|
|
public class LoginController:AdminBaseController
|
|
{
|
|
|
|
|
|
private readonly IAuthHelper _authHelper;
|
|
private readonly ITicketAccessAccountApplication _ticketAccessAccount;
|
|
private readonly ITaskApplication _taskApplication;
|
|
private readonly ITicketApplication _ticketApplication;
|
|
|
|
public LoginController(IAuthHelper authHelper, ITicketAccessAccountApplication ticketAccessAccount, ITaskApplication taskApplication, ITicketApplication ticketApplication)
|
|
{
|
|
_authHelper = authHelper;
|
|
_ticketAccessAccount = ticketAccessAccount;
|
|
_taskApplication = taskApplication;
|
|
_ticketApplication = ticketApplication;
|
|
}
|
|
/// <summary>
|
|
/// جزئیات پروفایل کاربر ادمین را برمی گرداند
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet("Profile")]
|
|
public async Task<ActionResult<GetAdminProfileDetails>> GetProfile()
|
|
{
|
|
if (!_authHelper.IsAuthenticated())
|
|
return Unauthorized();
|
|
|
|
var data = _authHelper.CurrentAccountInfo();
|
|
if (data == null)
|
|
{
|
|
return NotFound("کاربر یافت نشد");
|
|
}
|
|
|
|
var userTypeWithId = _authHelper.GetUserTypeWithId();
|
|
if (userTypeWithId.userType is not UserType.Admin)
|
|
return Unauthorized();
|
|
|
|
var hasTicketAccess = _ticketAccessAccount.HasTicketAccess(data.Id);
|
|
|
|
var taskCount = await _taskApplication.RequestedAndOverdueTasksCount(data.Id);
|
|
var ticketCount = _ticketApplication.GetAdminTicketsCount();
|
|
var details = new GetAdminProfileDetails(
|
|
data.Id,
|
|
data.Fullname,
|
|
data.Mobile,
|
|
data.RoleName,
|
|
data.Permissions,
|
|
data.PositionValue,
|
|
userTypeWithId.userType,
|
|
hasTicketAccess,
|
|
ticketCount, taskCount
|
|
);
|
|
return details;
|
|
}
|
|
} |