diff --git a/Hushian.Application/Services/ConversationService.cs b/Hushian.Application/Services/ConversationService.cs index a87a473..d2dae44 100644 --- a/Hushian.Application/Services/ConversationService.cs +++ b/Hushian.Application/Services/ConversationService.cs @@ -61,7 +61,8 @@ namespace Hushian.Application.Services GroupID = dto.GroupID, ConversationResponses = new List() { new() { Text = dto.Question, Type = type } } }; - Response.Value = (await _ConversationRepository.ADD(conversation)).ID; + var mi = await _ConversationRepository.ADD(conversation); + Response.Value = mi.ID; Response.Success = Response.Value > 0; } else Response.Errors.Add("شناسه گروه صحیح نمی باشد"); @@ -139,7 +140,7 @@ namespace Hushian.Application.Services NoReadCount = s.ConversationResponses.Count(c => !c.IsRead), status = s.Status, UserID = s.UserID, - UserFullName = s.User.FullName + UserFullName = string.IsNullOrEmpty(s.User.FullName) ? s.User.Mobile : s.User.FullName }).ToListAsync(); public async Task> GetConversationItems(int ConversationID) @@ -170,6 +171,7 @@ namespace Hushian.Application.Services .Where(w => w.ConversationResponses.Any(a => a.ExperID == ExperID) && w.Status == status) .Select(s => new Read_ConversationDto() { + ID=s.ID, ExperID = s.ConversationResponses.OrderBy(o => o.ID).Last().ExperID, ExperFullName = s.ConversationResponses.OrderBy(o => o.ID).Last().Exper.FullName, GroupID = s.GroupID, @@ -181,7 +183,7 @@ namespace Hushian.Application.Services NoReadCount = s.ConversationResponses.Count(c => !c.IsRead), status = s.Status, UserID = s.UserID, - UserFullName = s.User.FullName + UserFullName = string.IsNullOrEmpty(s.User.FullName) ? s.User.Mobile : s.User.FullName }).ToListAsync(); public async Task> GetConversationByCompanyID(int CompanyID, ConversationStatus status) @@ -191,6 +193,7 @@ namespace Hushian.Application.Services .Where(w => w.CompanyID==CompanyID && w.Status ==status) .Select(s => new Read_ConversationDto() { + ID = s.ID, ExperID = s.ConversationResponses.OrderBy(o => o.ID).Last().ExperID, ExperFullName = s.ConversationResponses.OrderBy(o => o.ID).Last().Exper.FullName, GroupID = s.GroupID, @@ -202,7 +205,7 @@ namespace Hushian.Application.Services NoReadCount = s.ConversationResponses.Count(c => !c.IsRead), status = s.Status, UserID = s.UserID, - UserFullName = s.User.FullName + UserFullName = string.IsNullOrEmpty(s.User.FullName) ? s.User.Mobile : s.User.FullName }).ToListAsync(); public async Task> ConversationAwaitingOurResponse(int CompanyID) @@ -212,6 +215,7 @@ namespace Hushian.Application.Services .Where(w => w.Status== ConversationStatus.Recorded && w.CompanyID == CompanyID) .Select(s => new Read_ConversationDto() { + ID = s.ID, ExperID = s.ConversationResponses.OrderBy(o=>o.ID).Last().ExperID, ExperFullName = s.ConversationResponses.OrderBy(o => o.ID).Last().Exper.FullName, GroupID = s.GroupID, @@ -223,7 +227,7 @@ namespace Hushian.Application.Services NoReadCount = s.ConversationResponses.Count(c => !c.IsRead), status = s.Status, UserID = s.UserID, - UserFullName = s.User.FullName + UserFullName = string.IsNullOrEmpty(s.User.FullName) ? s.User.Mobile : s.User.FullName }).ToListAsync(); public async Task FinishConversation(int ConversationID) diff --git a/Infrastructure/Persistence/GenericRepository.cs b/Infrastructure/Persistence/GenericRepository.cs index 201074e..bd3aa1b 100644 --- a/Infrastructure/Persistence/GenericRepository.cs +++ b/Infrastructure/Persistence/GenericRepository.cs @@ -24,7 +24,7 @@ namespace Hushian.Persistence.Repositories try { await _context.AddAsync(entity); - if ((await _context.SaveChangesAsync() == 1)) + if ((await _context.SaveChangesAsync() >= 1)) return entity; return null; diff --git a/Presentation/Hushian.WebApi/Controllers/v1/ConversationController.cs b/Presentation/Hushian.WebApi/Controllers/v1/ConversationController.cs index 088f304..c512150 100644 --- a/Presentation/Hushian.WebApi/Controllers/v1/ConversationController.cs +++ b/Presentation/Hushian.WebApi/Controllers/v1/ConversationController.cs @@ -25,7 +25,7 @@ namespace Hushian.WebApi.Controllers.v1 [HttpPost("MyConversation")] [Authorize(Roles = "Company,Exper")] - public async Task MyConversation(ConversationStatus status) + public async Task MyConversation([FromBody]ConversationStatus status) { if (User.IsInRole("Exper")) { @@ -76,7 +76,7 @@ namespace Hushian.WebApi.Controllers.v1 [HttpPost("NewConversationFromCurrentUser")] public async Task NewConversationFromCurrentUser(ADD_ConversationDto conversation) { - string UserID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First(); + conversation.UserID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => Convert.ToInt32( s.Value)).First(); var response = await _conversationService.NewConversation(conversation); return response.Success ? Ok(response.Value) : BadRequest(response.Errors); @@ -156,7 +156,7 @@ namespace Hushian.WebApi.Controllers.v1 { string strUserID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First(); int UserID = Convert.ToInt32(strUserID); - var response = await _conversationService.GEtConversation(CompanyID, UserID); + var response = await _conversationService.GEtConversation(UserID,CompanyID ); return Ok(response) ; } } diff --git a/Presentation/HushianWebApp/Components/UserPanel/ConversionHistoryComponent.razor b/Presentation/HushianWebApp/Components/UserPanel/ConversionHistoryComponent.razor index da71bd8..6cdb28f 100644 --- a/Presentation/HushianWebApp/Components/UserPanel/ConversionHistoryComponent.razor +++ b/Presentation/HushianWebApp/Components/UserPanel/ConversionHistoryComponent.razor @@ -22,7 +22,7 @@ VisuallyHiddenText="unread messages">@item.NoReadCount } - } + diff --git a/Presentation/HushianWebApp/Pages/Conversation.razor b/Presentation/HushianWebApp/Pages/Conversation.razor index 77242d6..3bf56be 100644 --- a/Presentation/HushianWebApp/Pages/Conversation.razor +++ b/Presentation/HushianWebApp/Pages/Conversation.razor @@ -239,11 +239,11 @@ @functions{ protected override async Task OnInitializedAsync() { - Role = await localStorageService.GetItem("Role"); + Role = await localStorageService.GetItem("C/Role"); - UserID= await localStorageService.GetItem("UserID"); + UserID= await localStorageService.GetItem("C/UserID"); convloading = true; await LoadSessionB(); Inbox1Items =await conversationService.ConversationAwaitingOurResponse(); diff --git a/Presentation/HushianWebApp/Pages/FromUserSide/UserPanel.razor b/Presentation/HushianWebApp/Pages/FromUserSide/UserPanel.razor index ce19302..a938e75 100644 --- a/Presentation/HushianWebApp/Pages/FromUserSide/UserPanel.razor +++ b/Presentation/HushianWebApp/Pages/FromUserSide/UserPanel.razor @@ -20,10 +20,10 @@ @CompanyName / @groups.FirstOrDefault(f => f.ID == SelectedGroup)?.Name / @SelectedConversation?.ExperFullName
+ Position="Position.Absolute" + Placement="BadgePlacement.TopRight" + IndicatorType="BadgeIndicatorType.RoundedPill" + VisuallyHiddenText="status"> پاسخگویی سوالات شما هستیم
@@ -39,7 +39,7 @@ @if (SelectedConversation == null) { @GCContent @@ -75,14 +75,14 @@ @@ -180,17 +180,17 @@ CompanyID=CompanyID OnMultipleOfThree="EventCallback.Factory.Create(this, CallBackSelectedGroup)" /> ; - Conversations = await conversationService.MyConversationUserSide(CompanyID); - if (Conversations.Count > 0) - ConversationsContent =@ - ; + } else { // ex Groups Company } - + Conversations = await conversationService.MyConversationUserSide(CompanyID); + if (Conversations.Count > 0) + ConversationsContent =@ + ; } } @@ -235,7 +235,15 @@ GroupID = SelectedGroup, Question = InputMessage }; + var convID= await conversationService.NewConversationFromCurrentUser(Item); + if (convID >0) + { + ConversationID = convID; + await SelectedConv(ConversationID.Value); + } + } + InputMessage = string.Empty; Sending = false; } } diff --git a/Presentation/HushianWebApp/Service/ConversationService.cs b/Presentation/HushianWebApp/Service/ConversationService.cs index 478e159..2f7c1b4 100644 --- a/Presentation/HushianWebApp/Service/ConversationService.cs +++ b/Presentation/HushianWebApp/Service/ConversationService.cs @@ -1,5 +1,6 @@ using Common.Dtos.Conversation; using Common.Enums; +using System.ComponentModel.Design; using System.Net.Http.Json; namespace HushianWebApp.Service @@ -82,5 +83,13 @@ namespace HushianWebApp.Service return new(); } + public async Task NewConversationFromCurrentUser(ADD_ConversationDto conversation) + { + var response = await _baseController.Post($"{BaseRoute}NewConversationFromCurrentUser", conversation); + if (response.IsSuccessStatusCode) + return await response.Content.ReadFromJsonAsync(); + + return -1; + } } }