This commit is contained in:
mmrbnjd
2025-07-30 16:39:37 +03:30
parent b3167b83b9
commit 5731c9ff97
6 changed files with 48 additions and 12 deletions

View File

@@ -10,6 +10,7 @@ namespace Common.Dtos
{ {
public int CompanyID { get; set; }= 0; public int CompanyID { get; set; }= 0;
public int? ExperID { get; set; } public int? ExperID { get; set; }
public int? UserID { get; set; }
public string Username { get; set; } = ""; public string Username { get; set; } = "";
public string Role { get; set; }= ""; public string Role { get; set; }= "";
} }

View File

@@ -12,16 +12,18 @@ namespace Hushian.Application.Services
public class ExperService public class ExperService
{ {
private readonly IGenericRepository<Company> _CompanyRepository; private readonly IGenericRepository<Company> _CompanyRepository;
private readonly IGenericRepository<User> _UserRepository;
private readonly IGenericRepository<Exper> _ExperRepository; private readonly IGenericRepository<Exper> _ExperRepository;
private readonly VerificationService _VerificationService; private readonly VerificationService _VerificationService;
private readonly IMapper _mapper; private readonly IMapper _mapper;
public ExperService(IGenericRepository<Exper> experRepository, VerificationService verificationService, IMapper mapper, IGenericRepository<Company> companyRepository) public ExperService(IGenericRepository<Exper> experRepository, VerificationService verificationService, IMapper mapper, IGenericRepository<Company> companyRepository, IGenericRepository<User> userRepository)
{ {
_ExperRepository = experRepository; _ExperRepository = experRepository;
_VerificationService = verificationService; _VerificationService = verificationService;
_mapper = mapper; _mapper = mapper;
_CompanyRepository = companyRepository; _CompanyRepository = companyRepository;
_UserRepository = userRepository;
} }
public async Task<ResponseBase<bool>> ADDExper(ADD_ExperDto dto, int CompanyID) public async Task<ResponseBase<bool>> ADDExper(ADD_ExperDto dto, int CompanyID)
@@ -64,7 +66,7 @@ namespace Hushian.Application.Services
} }
public async Task<Read_ExperDto?> GetInfoExper(int ExperID) public async Task<Read_ExperDto?> GetInfoExper(int ExperID)
=> _mapper.Map<Read_ExperDto>(await _ExperRepository.Get().FirstOrDefaultAsync(w => w.ID == ExperID)); => _mapper.Map<Read_ExperDto>(await _ExperRepository.Get().FirstOrDefaultAsync(w => w.ID == ExperID));
public async Task<CurrentUserInfo?> GetCurrentUserInfo(int CompanyID, int? ExperID) public async Task<CurrentUserInfo?> GetCurrentUserInfo(int CompanyID, int? ExperID, int? UserID)
{ {
if (ExperID.HasValue) if (ExperID.HasValue)
{ {
@@ -76,6 +78,16 @@ namespace Hushian.Application.Services
Role = "Exper" Role = "Exper"
}).FirstOrDefaultAsync(); }).FirstOrDefaultAsync();
} }
else if (UserID.HasValue)
{
return await _UserRepository.Get().Where(w => w.ID == UserID).Select(s => new CurrentUserInfo
{
CompanyID = 0,
UserID = UserID,
Username = s.Mobile,
Role = "User"
}).FirstOrDefaultAsync();
}
else else
{ {
return await _CompanyRepository.Get().Where(w => w.ID == CompanyID).Select(s => new CurrentUserInfo return await _CompanyRepository.Get().Where(w => w.ID == CompanyID).Select(s => new CurrentUserInfo

View File

@@ -83,11 +83,12 @@ namespace Hushian.WebApi.Controllers.v1
return response != null ? Ok(response) : BadRequest(new List<string> { "یافت نشد" }); return response != null ? Ok(response) : BadRequest(new List<string> { "یافت نشد" });
} }
[HttpGet("GetCurrentUserInfo")] [HttpGet("GetCurrentUserInfo")]
[Authorize(Roles = "Exper,Company")] [Authorize(Roles = "Exper,Company,User")]
public async Task<ActionResult> GetCurrentUserInfo() public async Task<ActionResult> GetCurrentUserInfo()
{ {
int CompanyID = 0; int CompanyID = 0;
int? ExperID = null; int? ExperID = null;
int? UserID = null;
if (User.IsInRole("Exper")) if (User.IsInRole("Exper"))
{ {
string strExperID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First(); string strExperID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
@@ -99,8 +100,13 @@ namespace Hushian.WebApi.Controllers.v1
string strCompanyID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First(); string strCompanyID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
CompanyID = Convert.ToInt32(strCompanyID); CompanyID = Convert.ToInt32(strCompanyID);
} }
else if (User.IsInRole("User"))
{
string strUserID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
UserID = Convert.ToInt32(strUserID);
}
var response = await _experService.GetCurrentUserInfo(CompanyID,ExperID); var response = await _experService.GetCurrentUserInfo(CompanyID,ExperID,UserID);
return response != null ? Ok(response) : BadRequest(new List<string> { "یافت نشد" }); return response != null ? Ok(response) : BadRequest(new List<string> { "یافت نشد" });
} }
[HttpPut("ExperEditingFromManager/{ExperID}")] //ویرایش کارشناس توسط مدیرش [HttpPut("ExperEditingFromManager/{ExperID}")] //ویرایش کارشناس توسط مدیرش

View File

@@ -4,9 +4,13 @@
@using Common.Dtos.Group @using Common.Dtos.Group
@using HushianWebApp.Service @using HushianWebApp.Service
@using HushianWebApp.Services @using HushianWebApp.Services
@inject ChatService ChatService
@inject ILocalStorageService localStorageService; @inject ILocalStorageService localStorageService;
@inject AuthService authService; @inject AuthService authService;
@inject BaseController baseController; @inject BaseController baseController;
@inject CompanyService companyService
@inject UserService userService
@inject GroupService groupService
@layout UserPanelLayout @layout UserPanelLayout
<div class="container-fluid"> <div class="container-fluid">
<div class="row" style="height:85vh"> <div class="row" style="height:85vh">
@@ -117,7 +121,7 @@
@code { @code {
[Parameter] public int CompanyID { get; set; } [Parameter] public int CompanyID { get; set; }
ReadANDUpdate_CompanyDto CompanyInfo = new(); ReadANDUpdate_CompanyDto? CompanyInfo = new();
Common.Dtos.CurrentUserInfo CurrentUser = new(); Common.Dtos.CurrentUserInfo CurrentUser = new();
List<Read_GroupDto> CompanyGroups = new(); List<Read_GroupDto> CompanyGroups = new();
ChatItemDto? LastOpenChat = new(); ChatItemDto? LastOpenChat = new();
@@ -129,6 +133,7 @@
{ {
get get
{ {
if (CompanyInfo == null) return string.Empty;
string value = $"{CompanyInfo.FullName}"; string value = $"{CompanyInfo.FullName}";
if (LastOpenChat != null) if (LastOpenChat != null)
{ {
@@ -187,18 +192,20 @@
async Task Afterlogin() async Task Afterlogin()
{ {
IsLogin = true; IsLogin = true;
CurrentUser = new(); CurrentUser =await userService.GetCurrentUserInfo();
await IsCompany(); await IsCompany();
} }
async Task IsCompany() async Task IsCompany()
{ {
CompanyInfo = new(); CompanyInfo = await companyService.GetCompany(CompanyID);
CompanyGroups = new(); if (CompanyInfo!=null)
CompanyGroups = await groupService.GetGroupsCompany(CompanyID);
await IsLastChat(); await IsLastChat();
} }
async Task IsLastChat() async Task IsLastChat()
{ {
LastOpenChat = null; if (CompanyInfo != null)
LastOpenChat =await ChatService.GetLastChatInCompany(CompanyID);
StateHasChanged(); StateHasChanged();
} }
} }

View File

@@ -35,7 +35,7 @@ namespace HushianWebApp.Service
if (_Http.DefaultRequestHeaders.Any(t => t.Key == "Authorization")) if (_Http.DefaultRequestHeaders.Any(t => t.Key == "Authorization"))
_Http.DefaultRequestHeaders.Remove("Authorization"); _Http.DefaultRequestHeaders.Remove("Authorization");
} }
public async Task<HttpResponseMessage> Get(string route) public async Task<HttpResponseMessage> Get(string route,string From="")
{ {
var result = await _Http.GetAsync(route); var result = await _Http.GetAsync(route);
return await Check(result); return await Check(result);
@@ -141,7 +141,14 @@ namespace HushianWebApp.Service
else if (result.StatusCode == System.Net.HttpStatusCode.Forbidden) else if (result.StatusCode == System.Net.HttpStatusCode.Forbidden)
_ToastService.Notify(new ToastMessage(ToastType.Danger, "به این بخش دسترسی ندارید")); _ToastService.Notify(new ToastMessage(ToastType.Danger, "به این بخش دسترسی ندارید"));
else if (result.StatusCode == System.Net.HttpStatusCode.NotFound) else if (result.StatusCode == System.Net.HttpStatusCode.NotFound)
_ToastService.Notify(new ToastMessage(ToastType.Danger, "یافت نشد")); {
string From ="" ;
if (result.RequestMessage.RequestUri.AbsolutePath.ToString().Contains("GetCompany")) From = "شرکت";
_ToastService.Notify(new ToastMessage(ToastType.Danger, $"{From} یافت نشد"));
}
else if (!result.IsSuccessStatusCode) else if (!result.IsSuccessStatusCode)
{ {

View File

@@ -73,6 +73,9 @@ namespace HushianWebApp.Service
return response.IsSuccessStatusCode; return response.IsSuccessStatusCode;
} }
public async Task<ChatItemDto> GetLastChatInCompany(int CompanyID)
{
return new();
}
} }
} }