From 5731c9ff979197212353f3910f05f81756bec426 Mon Sep 17 00:00:00 2001 From: mmrbnjd Date: Wed, 30 Jul 2025 16:39:37 +0330 Subject: [PATCH] ... --- Common/Dtos/CurrentUserInfo.cs | 1 + Hushian.Application/Services/ExperService.cs | 16 ++++++++++++++-- .../Controllers/v1/ExperController.cs | 10 ++++++++-- .../Pages/FromUserSide/UserCP.razor | 17 ++++++++++++----- .../HushianWebApp/Service/BaseController.cs | 11 +++++++++-- .../HushianWebApp/Service/ChatService.cs | 5 ++++- 6 files changed, 48 insertions(+), 12 deletions(-) diff --git a/Common/Dtos/CurrentUserInfo.cs b/Common/Dtos/CurrentUserInfo.cs index bcfa5b4..c5262aa 100644 --- a/Common/Dtos/CurrentUserInfo.cs +++ b/Common/Dtos/CurrentUserInfo.cs @@ -10,6 +10,7 @@ namespace Common.Dtos { public int CompanyID { get; set; }= 0; public int? ExperID { get; set; } + public int? UserID { get; set; } public string Username { get; set; } = ""; public string Role { get; set; }= ""; } diff --git a/Hushian.Application/Services/ExperService.cs b/Hushian.Application/Services/ExperService.cs index 8dee085..ae26c1e 100644 --- a/Hushian.Application/Services/ExperService.cs +++ b/Hushian.Application/Services/ExperService.cs @@ -12,16 +12,18 @@ namespace Hushian.Application.Services public class ExperService { private readonly IGenericRepository _CompanyRepository; + private readonly IGenericRepository _UserRepository; private readonly IGenericRepository _ExperRepository; private readonly VerificationService _VerificationService; private readonly IMapper _mapper; - public ExperService(IGenericRepository experRepository, VerificationService verificationService, IMapper mapper, IGenericRepository companyRepository) + public ExperService(IGenericRepository experRepository, VerificationService verificationService, IMapper mapper, IGenericRepository companyRepository, IGenericRepository userRepository) { _ExperRepository = experRepository; _VerificationService = verificationService; _mapper = mapper; _CompanyRepository = companyRepository; + _UserRepository = userRepository; } public async Task> ADDExper(ADD_ExperDto dto, int CompanyID) @@ -64,7 +66,7 @@ namespace Hushian.Application.Services } public async Task GetInfoExper(int ExperID) => _mapper.Map(await _ExperRepository.Get().FirstOrDefaultAsync(w => w.ID == ExperID)); - public async Task GetCurrentUserInfo(int CompanyID, int? ExperID) + public async Task GetCurrentUserInfo(int CompanyID, int? ExperID, int? UserID) { if (ExperID.HasValue) { @@ -76,6 +78,16 @@ namespace Hushian.Application.Services Role = "Exper" }).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 { return await _CompanyRepository.Get().Where(w => w.ID == CompanyID).Select(s => new CurrentUserInfo diff --git a/Presentation/Hushian.WebApi/Controllers/v1/ExperController.cs b/Presentation/Hushian.WebApi/Controllers/v1/ExperController.cs index eada0fd..5585cea 100644 --- a/Presentation/Hushian.WebApi/Controllers/v1/ExperController.cs +++ b/Presentation/Hushian.WebApi/Controllers/v1/ExperController.cs @@ -83,11 +83,12 @@ namespace Hushian.WebApi.Controllers.v1 return response != null ? Ok(response) : BadRequest(new List { "یافت نشد" }); } [HttpGet("GetCurrentUserInfo")] - [Authorize(Roles = "Exper,Company")] + [Authorize(Roles = "Exper,Company,User")] public async Task GetCurrentUserInfo() { int CompanyID = 0; int? ExperID = null; + int? UserID = null; if (User.IsInRole("Exper")) { 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(); 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 { "یافت نشد" }); } [HttpPut("ExperEditingFromManager/{ExperID}")] //ویرایش کارشناس توسط مدیرش diff --git a/Presentation/HushianWebApp/Pages/FromUserSide/UserCP.razor b/Presentation/HushianWebApp/Pages/FromUserSide/UserCP.razor index 2abfb00..24d5918 100644 --- a/Presentation/HushianWebApp/Pages/FromUserSide/UserCP.razor +++ b/Presentation/HushianWebApp/Pages/FromUserSide/UserCP.razor @@ -4,9 +4,13 @@ @using Common.Dtos.Group @using HushianWebApp.Service @using HushianWebApp.Services +@inject ChatService ChatService @inject ILocalStorageService localStorageService; @inject AuthService authService; @inject BaseController baseController; +@inject CompanyService companyService +@inject UserService userService +@inject GroupService groupService @layout UserPanelLayout
@@ -117,7 +121,7 @@ @code { [Parameter] public int CompanyID { get; set; } - ReadANDUpdate_CompanyDto CompanyInfo = new(); + ReadANDUpdate_CompanyDto? CompanyInfo = new(); Common.Dtos.CurrentUserInfo CurrentUser = new(); List CompanyGroups = new(); ChatItemDto? LastOpenChat = new(); @@ -129,6 +133,7 @@ { get { + if (CompanyInfo == null) return string.Empty; string value = $"{CompanyInfo.FullName}"; if (LastOpenChat != null) { @@ -187,18 +192,20 @@ async Task Afterlogin() { IsLogin = true; - CurrentUser = new(); + CurrentUser =await userService.GetCurrentUserInfo(); await IsCompany(); } async Task IsCompany() { - CompanyInfo = new(); - CompanyGroups = new(); + CompanyInfo = await companyService.GetCompany(CompanyID); + if (CompanyInfo!=null) + CompanyGroups = await groupService.GetGroupsCompany(CompanyID); await IsLastChat(); } async Task IsLastChat() { - LastOpenChat = null; + if (CompanyInfo != null) + LastOpenChat =await ChatService.GetLastChatInCompany(CompanyID); StateHasChanged(); } } diff --git a/Presentation/HushianWebApp/Service/BaseController.cs b/Presentation/HushianWebApp/Service/BaseController.cs index 733b080..d07bce4 100644 --- a/Presentation/HushianWebApp/Service/BaseController.cs +++ b/Presentation/HushianWebApp/Service/BaseController.cs @@ -35,7 +35,7 @@ namespace HushianWebApp.Service if (_Http.DefaultRequestHeaders.Any(t => t.Key == "Authorization")) _Http.DefaultRequestHeaders.Remove("Authorization"); } - public async Task Get(string route) + public async Task Get(string route,string From="") { var result = await _Http.GetAsync(route); return await Check(result); @@ -141,7 +141,14 @@ namespace HushianWebApp.Service else if (result.StatusCode == System.Net.HttpStatusCode.Forbidden) _ToastService.Notify(new ToastMessage(ToastType.Danger, "به این بخش دسترسی ندارید")); 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) { diff --git a/Presentation/HushianWebApp/Service/ChatService.cs b/Presentation/HushianWebApp/Service/ChatService.cs index 24bde85..3cf5b64 100644 --- a/Presentation/HushianWebApp/Service/ChatService.cs +++ b/Presentation/HushianWebApp/Service/ChatService.cs @@ -73,6 +73,9 @@ namespace HushianWebApp.Service return response.IsSuccessStatusCode; } - + public async Task GetLastChatInCompany(int CompanyID) + { + return new(); + } } }