...
This commit is contained in:
31
Common/Dtos/Conversation/ChatItemDto.cs
Normal file
31
Common/Dtos/Conversation/ChatItemDto.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using Common.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Common.Dtos.Conversation
|
||||
{
|
||||
public class ChatItemDto
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public string LastText { get; set; }
|
||||
public ConversationType LastMsgType { get; set; }
|
||||
public ConversationStatus status { get; set; }
|
||||
|
||||
public int? GroupID { get; set; }
|
||||
public string? GroupName { get; set; }
|
||||
|
||||
public int UserID { get; set; }
|
||||
public string? UserFullName { get; set; }
|
||||
|
||||
public int? ExperID { get; set; }
|
||||
public string? ExperFullName { get; set; }
|
||||
|
||||
public string LastMsgdate { get; set; }
|
||||
public string LastMsgtime { get; set; }
|
||||
|
||||
public List<ChatItemResponseDto> Responses { get; set; }
|
||||
}
|
||||
}
|
23
Common/Dtos/Conversation/ChatItemResponseDto.cs
Normal file
23
Common/Dtos/Conversation/ChatItemResponseDto.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Common.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Common.Dtos.Conversation
|
||||
{
|
||||
public class ChatItemResponseDto
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public int ChatItemID { get; set; }
|
||||
public int? ExperID { get; set; }
|
||||
public bool IsRead { get; set; } = false;
|
||||
public string ExperName { get; set; }
|
||||
public ConversationType Type { get; set; }
|
||||
public string text { get; set; }
|
||||
public string FileName { get; set; }
|
||||
public string FileType { get; set; }
|
||||
public byte[] FileContent { get; set; }
|
||||
}
|
||||
}
|
16
Common/Dtos/CurrentUserInfo.cs
Normal file
16
Common/Dtos/CurrentUserInfo.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Common.Dtos
|
||||
{
|
||||
public class CurrentUserInfo
|
||||
{
|
||||
public int CompanyID { get; set; }= 0;
|
||||
public int? ExperID { get; set; }
|
||||
public string Username { get; set; } = "";
|
||||
public string Role { get; set; }= "";
|
||||
}
|
||||
}
|
246
Hushian.Application/Services/ChatService.cs
Normal file
246
Hushian.Application/Services/ChatService.cs
Normal file
@@ -0,0 +1,246 @@
|
||||
using Common.Dtos.Conversation;
|
||||
using Common.Enums;
|
||||
using Hushian.Application.Contracts.Persistence;
|
||||
using Hushian.Application.Models;
|
||||
using Hushian.Domain.Entites;
|
||||
using Hushian.WebApi;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hushian.Application.Services
|
||||
{
|
||||
public class ChatService
|
||||
{
|
||||
private readonly IGenericRepository<Conversation> _ConversationRepository;
|
||||
private readonly IGenericRepository<ConversationResponse> _ConversationResponseRepository;
|
||||
private readonly CompanyService _companyService;
|
||||
private readonly UserService _userService;
|
||||
private readonly GroupService _groupService;
|
||||
private readonly ExperService _experService;
|
||||
private readonly IHubContext<ChatNotificationHub> _hubContext;
|
||||
public async Task<List<ChatItemDto>> GeChatsByExperID(int ExperID, ConversationStatus status)
|
||||
=> await _ConversationRepository.Get()
|
||||
.Include(inc => inc.Group)
|
||||
.Include(inc => inc.ConversationResponses).ThenInclude(tinc => tinc.Exper)
|
||||
.Where(w => w.ConversationResponses.Any(a => a.ExperID == ExperID) && w.Status == status)
|
||||
.Select(s => new ChatItemDto()
|
||||
{
|
||||
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,
|
||||
GroupName = s.Group.Name,
|
||||
LastText = s.ConversationResponses.OrderBy(o => o.ID).Last().Text,
|
||||
LastMsgdate = s.Cdatetime.GetDatePersian(),
|
||||
LastMsgtime = s.Cdatetime.GetTime(),
|
||||
LastMsgType = s.ConversationResponses.OrderBy(o => o.ID).Last().Type,
|
||||
status = s.Status,
|
||||
UserID = s.UserID,
|
||||
UserFullName = string.IsNullOrEmpty(s.User.FullName) ? s.User.Mobile : s.User.FullName,
|
||||
Responses = s.ConversationResponses.Select(ss=>new ChatItemResponseDto()
|
||||
{
|
||||
ChatItemID = ss.ConversationID,
|
||||
ExperID = ss.ExperID,
|
||||
ExperName = ss.Exper.FullName,
|
||||
FileContent = ss.FileContent,
|
||||
FileName = ss.FileName,
|
||||
FileType = ss.FileType,
|
||||
ID = ss.ID,
|
||||
IsRead = ss.IsRead,
|
||||
text = ss.Text,
|
||||
Type = ss.Type
|
||||
})
|
||||
|
||||
}).ToListAsync();
|
||||
public async Task<List<ChatItemDto>> GetChatsByCompanyID(int CompanyID, ConversationStatus status)
|
||||
=> await _ConversationRepository.Get()
|
||||
.Include(inc => inc.Group)
|
||||
.Include(inc => inc.ConversationResponses).ThenInclude(tinc => tinc.Exper)
|
||||
.Where(w => w.CompanyID == CompanyID && w.Status == status)
|
||||
.Select(s => new ChatItemDto()
|
||||
{
|
||||
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,
|
||||
GroupName = s.Group.Name,
|
||||
LastText = s.ConversationResponses.OrderBy(o => o.ID).Last().Text,
|
||||
LastMsgdate = s.Cdatetime.GetDatePersian(),
|
||||
LastMsgtime = s.Cdatetime.GetTime(),
|
||||
LastMsgType = s.ConversationResponses.OrderBy(o => o.ID).Last().Type,
|
||||
status = s.Status,
|
||||
UserID = s.UserID,
|
||||
UserFullName = string.IsNullOrEmpty(s.User.FullName) ? s.User.Mobile : s.User.FullName,
|
||||
Responses = s.ConversationResponses.Select(ss => new ChatItemResponseDto()
|
||||
{
|
||||
ChatItemID = ss.ConversationID,
|
||||
ExperID = ss.ExperID,
|
||||
ExperName = ss.Exper.FullName,
|
||||
FileContent = ss.FileContent,
|
||||
FileName = ss.FileName,
|
||||
FileType = ss.FileType,
|
||||
ID = ss.ID,
|
||||
IsRead = ss.IsRead,
|
||||
text = ss.Text,
|
||||
Type = ss.Type
|
||||
})
|
||||
|
||||
}).ToListAsync();
|
||||
public async Task<List<ChatItemDto>> ChatsAwaitingOurResponse(int CompanyID)
|
||||
=> await _ConversationRepository.Get()
|
||||
.Include(inc => inc.Group)
|
||||
.Include(inc => inc.ConversationResponses).ThenInclude(tinc => tinc.Exper)
|
||||
.Where(w => w.Status == ConversationStatus.Recorded && w.CompanyID == CompanyID)
|
||||
.Select(s => new ChatItemDto()
|
||||
{
|
||||
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,
|
||||
GroupName = s.Group.Name,
|
||||
LastText = s.ConversationResponses.OrderBy(o => o.ID).Last().Text,
|
||||
LastMsgdate = s.Cdatetime.GetDatePersian(),
|
||||
LastMsgtime = s.Cdatetime.GetTime(),
|
||||
LastMsgType = s.ConversationResponses.OrderBy(o => o.ID).Last().Type,
|
||||
status = s.Status,
|
||||
UserID = s.UserID,
|
||||
UserFullName = string.IsNullOrEmpty(s.User.FullName) ? s.User.Mobile : s.User.FullName,
|
||||
Responses = s.ConversationResponses.Select(ss => new ChatItemResponseDto()
|
||||
{
|
||||
ChatItemID = ss.ConversationID,
|
||||
ExperID = ss.ExperID,
|
||||
ExperName = ss.Exper.FullName,
|
||||
FileContent = ss.FileContent,
|
||||
FileName = ss.FileName,
|
||||
FileType = ss.FileType,
|
||||
ID = ss.ID,
|
||||
IsRead = ss.IsRead,
|
||||
text = ss.Text,
|
||||
Type = ss.Type
|
||||
})
|
||||
|
||||
}).ToListAsync();
|
||||
//------------------------
|
||||
public async Task<ResponseBase<ChatItemDto>> NewChat(ADD_ConversationDto dto, ConversationType type = ConversationType.UE)
|
||||
{
|
||||
var Response = new ResponseBase<ChatItemDto>();
|
||||
if (await _companyService.AnyCompany(dto.CompanyID))
|
||||
{
|
||||
if (await _userService.AnyUser(dto.UserID))
|
||||
{
|
||||
if (type == ConversationType.Bot)
|
||||
{
|
||||
if (!await _companyService.AllowBot(dto.CompanyID))
|
||||
{
|
||||
Response.Errors.Add("دستیار گفتگو هوشمند برای این شرکت در دسترس نمی باشد");
|
||||
return Response;
|
||||
}
|
||||
}
|
||||
|
||||
if (!dto.GroupID.HasValue || (dto.GroupID.HasValue
|
||||
&& await _groupService.AnyGroup(dto.GroupID.Value)
|
||||
&& await _groupService.CHeckGroupMemberCompany(dto.GroupID.Value, dto.CompanyID)))
|
||||
{
|
||||
Conversation conversation = new Conversation()
|
||||
{
|
||||
CompanyID = dto.CompanyID,
|
||||
UserID = dto.UserID,
|
||||
GroupID = dto.GroupID,
|
||||
ConversationResponses = new List<ConversationResponse>() { new() { Text = dto.Question, Type = type } }
|
||||
};
|
||||
var mi = await _ConversationRepository.ADD(conversation);
|
||||
Response.Value = new ChatItemDto()
|
||||
{
|
||||
ID = mi.ID,
|
||||
ExperID = mi.ConversationResponses.OrderBy(o => o.ID).Last().ExperID,
|
||||
ExperFullName = /*mi.ConversationResponses.OrderBy(o => o.ID).Last().Exper.FullName*/ "",
|
||||
GroupID = mi.GroupID,
|
||||
GroupName = /*mi.Group.Name*/ "",
|
||||
LastText = mi.ConversationResponses.OrderBy(o => o.ID).Last().Text,
|
||||
LastMsgdate = mi.Cdatetime.GetDatePersian(),
|
||||
LastMsgtime = mi.Cdatetime.GetTime(),
|
||||
LastMsgType = mi.ConversationResponses.OrderBy(o => o.ID).Last().Type,
|
||||
status = mi.Status,
|
||||
UserID = mi.UserID,
|
||||
UserFullName = /*string.IsNullOrEmpty(mi.User.FullName) ? mi.User.Mobile : mi.User.FullName*/ ""
|
||||
|
||||
};
|
||||
Response.Success = mi.ID > 0;
|
||||
}
|
||||
else Response.Errors.Add("شناسه گروه صحیح نمی باشد");
|
||||
|
||||
|
||||
|
||||
}
|
||||
else Response.Errors.Add("شناسه کاربر یافت نشد");
|
||||
|
||||
}
|
||||
else Response.Errors.Add("شناسه شرکت یافت نشد");
|
||||
|
||||
|
||||
return Response;
|
||||
}
|
||||
public async Task<ResponseBase<ChatItemResponseDto>> ADDChatResponse(ADD_ConversationResponseDto dto, int? ExperID)
|
||||
{
|
||||
var Response = new ResponseBase<ChatItemResponseDto>();
|
||||
if (dto.Type == ConversationType.EU && !ExperID.HasValue)
|
||||
{
|
||||
Response.Errors.Add("کارشناس گفتگو را مشخص گنید");
|
||||
}
|
||||
else
|
||||
{
|
||||
var convModel = await _ConversationRepository.Get()
|
||||
.Include(inc => inc.ConversationResponses)
|
||||
.FirstOrDefaultAsync(w => w.ID == dto.ConversationID);
|
||||
|
||||
if (convModel != null)
|
||||
{
|
||||
if (ExperID.HasValue && !await _experService.CheckExperInCompany(convModel.CompanyID, ExperID.Value))
|
||||
{
|
||||
Response.Errors.Add("کارشناس گفتگو صحیح نمی باشد");
|
||||
return Response;
|
||||
}
|
||||
ConversationResponse response = new ConversationResponse()
|
||||
{
|
||||
ConversationID = convModel.ID,
|
||||
Text = dto.Text,
|
||||
Type = dto.Type,
|
||||
ExperID = ExperID,
|
||||
FileContent = dto.FileContent,
|
||||
FileType = dto.FileType,
|
||||
FileName = dto.FileName
|
||||
};
|
||||
var statuschangedb = await _ConversationResponseRepository.ADD(response);
|
||||
Response.Value = new ChatItemResponseDto()
|
||||
{
|
||||
ChatItemID = statuschangedb.ConversationID,
|
||||
ExperID = statuschangedb.ExperID,
|
||||
ExperName = /*statuschangedb.Exper.FullName*/ "",
|
||||
FileContent = statuschangedb.FileContent,
|
||||
FileName = statuschangedb.FileName,
|
||||
FileType = statuschangedb.FileType,
|
||||
ID = statuschangedb.ID,
|
||||
IsRead = statuschangedb.IsRead,
|
||||
text = statuschangedb.Text,
|
||||
Type = statuschangedb.Type
|
||||
};
|
||||
Response.Success = statuschangedb.ID > 0;
|
||||
|
||||
if (convModel.Status == ConversationStatus.Recorded && Response.Success)
|
||||
{
|
||||
convModel.Status = ConversationStatus.InProgress;
|
||||
await _ConversationRepository.UPDATE(convModel);
|
||||
}
|
||||
}
|
||||
else Response.Errors.Add("گفتگویی یافت نشد");
|
||||
}
|
||||
|
||||
return Response;
|
||||
}
|
||||
}
|
||||
}
|
@@ -11,6 +11,7 @@ namespace Hushian.Application.Services
|
||||
{
|
||||
public class ExperService
|
||||
{
|
||||
private readonly IGenericRepository<Company> _CompanyRepository;
|
||||
private readonly IGenericRepository<Exper> _ExperRepository;
|
||||
private readonly VerificationService _VerificationService;
|
||||
private readonly IMapper _mapper;
|
||||
@@ -62,6 +63,30 @@ namespace Hushian.Application.Services
|
||||
}
|
||||
public async Task<Read_ExperDto?> GetInfoExper(int ExperID)
|
||||
=> _mapper.Map<Read_ExperDto>(await _ExperRepository.Get().FirstOrDefaultAsync(w => w.ID == ExperID));
|
||||
public async Task<CurrentUserInfo?> GetCurrentUserInfo(int CompanyID, int? ExperID)
|
||||
{
|
||||
if (ExperID.HasValue)
|
||||
{
|
||||
return await _ExperRepository.Get().Where(w => w.ID == ExperID).Select(s => new CurrentUserInfo
|
||||
{
|
||||
CompanyID = CompanyID,
|
||||
ExperID = ExperID,
|
||||
Username = s.UserName,
|
||||
Role = "Exper"
|
||||
}).FirstOrDefaultAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
return await _CompanyRepository.Get().Where(w => w.ID == CompanyID).Select(s => new CurrentUserInfo
|
||||
{
|
||||
CompanyID = CompanyID,
|
||||
ExperID = null,
|
||||
Username = s.Mobile,
|
||||
Role = "Company"
|
||||
}).FirstOrDefaultAsync();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<Read_ExperDto>> GetExpersInCompany(int companyID)
|
||||
=> _mapper.Map<List<Read_ExperDto>>(await _ExperRepository.Get().Where(w => w.CompanyID == companyID).ToListAsync());
|
||||
public async Task<Read_ExperDto?> GetExpersInGroup(int GroupID)
|
||||
@@ -72,15 +97,15 @@ namespace Hushian.Application.Services
|
||||
exper.FullName = model.FullName;
|
||||
return await _ExperRepository.UPDATEBool(exper);
|
||||
}
|
||||
public async Task<bool> ChangeAvailableExper(int ExperID,int CompanyID,bool Available)
|
||||
public async Task<bool> ChangeAvailableExper(int ExperID, int CompanyID, bool Available)
|
||||
{
|
||||
var exper = await _ExperRepository.Get().FirstOrDefaultAsync(w => w.ID == ExperID && w.CompanyID==CompanyID);
|
||||
var exper = await _ExperRepository.Get().FirstOrDefaultAsync(w => w.ID == ExperID && w.CompanyID == CompanyID);
|
||||
if (exper == null) return false;
|
||||
exper.Available = Available;
|
||||
return await _ExperRepository.UPDATEBool(exper);
|
||||
}
|
||||
public async Task<bool> CheckExperInCompany(int CompanyID, int ExperID)
|
||||
=>await _ExperRepository.Get().AnyAsync(w => w.ID == ExperID && w.CompanyID==CompanyID);
|
||||
=> await _ExperRepository.Get().AnyAsync(w => w.ID == ExperID && w.CompanyID == CompanyID);
|
||||
public async Task<bool> DeleteExper(int ExperID, int CompanyID)
|
||||
{
|
||||
var exper = await _ExperRepository.Get().FirstOrDefaultAsync(w => w.ID == ExperID && w.CompanyID == CompanyID);
|
||||
@@ -151,7 +176,7 @@ namespace Hushian.Application.Services
|
||||
}
|
||||
public async Task<bool> AvailableExperInCompany(int ExperID)
|
||||
{
|
||||
return await _ExperRepository.Get().AnyAsync(w => w.ID == ExperID && w.Available);
|
||||
return await _ExperRepository.Get().AnyAsync(w => w.ID == ExperID && w.Available);
|
||||
|
||||
}
|
||||
}
|
||||
|
97
Presentation/Hushian.WebApi/Controllers/v1/ChatController.cs
Normal file
97
Presentation/Hushian.WebApi/Controllers/v1/ChatController.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using Common.Dtos.Conversation;
|
||||
using Common.Enums;
|
||||
using Hushian.Application.Constants;
|
||||
using Hushian.Application.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Hushian.WebApi.Controllers.v1
|
||||
{
|
||||
[Route("api/v1/[controller]")]
|
||||
[ApiController]
|
||||
public class ChatController : ControllerBase
|
||||
{
|
||||
private readonly ChatService _chatService; private readonly ExperService _experService;
|
||||
[HttpPost("MyChats")]
|
||||
[Authorize(Roles = "Company,Exper")]
|
||||
public async Task<ActionResult> MyChats([FromBody] ConversationStatus status)
|
||||
{
|
||||
if (User.IsInRole("Exper"))
|
||||
{
|
||||
string strExperID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
|
||||
int ExperID = Convert.ToInt32(strExperID);
|
||||
var response = await _chatService.GeChatsByExperID(ExperID, status);
|
||||
return Ok(response);
|
||||
}
|
||||
else if (User.IsInRole("Company"))
|
||||
{
|
||||
string strCompanyID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
|
||||
int CompanyID = Convert.ToInt32(strCompanyID);
|
||||
|
||||
var response = await _chatService.GetChatsByCompanyID(CompanyID, status);
|
||||
return Ok(response);
|
||||
}
|
||||
return Forbid();
|
||||
|
||||
}
|
||||
[HttpGet("ChatsAwaitingOurResponse")]
|
||||
[Authorize(Roles = "Company,Exper")]
|
||||
public async Task<ActionResult> ChatsAwaitingOurResponse()
|
||||
{
|
||||
int CompanyID = 0;
|
||||
if (User.IsInRole("Exper"))
|
||||
{
|
||||
string strExperID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
|
||||
int ExperID = Convert.ToInt32(strExperID);
|
||||
|
||||
CompanyID = await _experService.GetCompanyIDExper(ExperID);
|
||||
}
|
||||
else if (User.IsInRole("Company"))
|
||||
{
|
||||
string strCompanyID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
|
||||
CompanyID = Convert.ToInt32(strCompanyID);
|
||||
}
|
||||
|
||||
var response = await _chatService.ChatsAwaitingOurResponse(CompanyID);
|
||||
return Ok(response);
|
||||
}
|
||||
[HttpPost("NewChatFromCurrentUser")]
|
||||
public async Task<ActionResult> NewChatFromCurrentUser(ADD_ConversationDto conversation)
|
||||
{
|
||||
conversation.UserID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => Convert.ToInt32(s.Value)).First();
|
||||
var response = await _chatService.NewChat(conversation);
|
||||
return response.Success ? Ok(response.Value)
|
||||
: BadRequest(response.Errors);
|
||||
}
|
||||
[HttpPost("ADDChatResponse")]
|
||||
[Authorize(Roles = "Company,User,Exper")]
|
||||
public async Task<ActionResult> ADDChatResponse([FromBody] ADD_ConversationResponseDto ConversationItem)
|
||||
{
|
||||
|
||||
int? ExperID = null;
|
||||
if (User.IsInRole("Exper"))
|
||||
{
|
||||
string strExperID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
|
||||
ExperID = Convert.ToInt32(strExperID);
|
||||
ConversationItem.Type = ConversationType.EU;
|
||||
}
|
||||
|
||||
else if (User.IsInRole("User"))
|
||||
{
|
||||
ConversationItem.Type = ConversationType.UE;
|
||||
}
|
||||
else if (User.IsInRole("Company"))
|
||||
{
|
||||
ConversationItem.Type = ConversationType.CU;
|
||||
|
||||
}
|
||||
else return Unauthorized();
|
||||
|
||||
|
||||
var Response = await _chatService.ADDChatResponse(ConversationItem, ExperID);
|
||||
return Response.Success ? Ok(Response.Value)
|
||||
: BadRequest(Response.Errors);
|
||||
}
|
||||
}
|
||||
}
|
@@ -23,6 +23,7 @@ namespace Hushian.WebApi.Controllers.v1
|
||||
_experService = experService;
|
||||
}
|
||||
|
||||
//*
|
||||
[HttpPost("MyConversation")]
|
||||
[Authorize(Roles = "Company,Exper")]
|
||||
public async Task<ActionResult> MyConversation([FromBody]ConversationStatus status)
|
||||
@@ -45,7 +46,7 @@ namespace Hushian.WebApi.Controllers.v1
|
||||
return Forbid();
|
||||
|
||||
}
|
||||
|
||||
//*
|
||||
[HttpGet("ConversationAwaitingOurResponse")]
|
||||
[Authorize(Roles = "Company,Exper")]
|
||||
public async Task<ActionResult> ConversationAwaitingOurResponse()
|
||||
@@ -67,12 +68,14 @@ namespace Hushian.WebApi.Controllers.v1
|
||||
var response = await _conversationService.ConversationAwaitingOurResponse(CompanyID);
|
||||
return Ok(response);
|
||||
}
|
||||
//*
|
||||
[HttpGet("ConversationItems/{ConversationID}")]
|
||||
[Authorize(Roles = "Company,Exper,User")]
|
||||
public async Task<ActionResult> GetConversationItems(int ConversationID)
|
||||
{
|
||||
return Ok(await _conversationService.GetConversationItems(ConversationID));
|
||||
}
|
||||
//*
|
||||
[HttpPost("NewConversationFromCurrentUser")]
|
||||
public async Task<ActionResult> NewConversationFromCurrentUser(ADD_ConversationDto conversation)
|
||||
{
|
||||
@@ -81,6 +84,7 @@ namespace Hushian.WebApi.Controllers.v1
|
||||
return response.Success ? Ok(response.Value)
|
||||
: BadRequest(response.Errors);
|
||||
}
|
||||
//*
|
||||
[HttpPost("ADDConversationResponse")]
|
||||
[Authorize(Roles = "Company,User,Exper")]
|
||||
public async Task<ActionResult> ADDConversationResponse([FromBody] ADD_ConversationResponseDto ConversationItem)
|
||||
@@ -110,6 +114,7 @@ namespace Hushian.WebApi.Controllers.v1
|
||||
return Response.Success ? Ok(Response.Value)
|
||||
: BadRequest(Response.Errors);
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
[HttpPut("MarkAsReadConversationItem/{ConversationItemID}")]
|
||||
[Authorize(Roles = "Company,User,Exper")]
|
||||
public async Task<ActionResult> MarkAsReadConversationItem(int ConversationItemID)
|
||||
|
@@ -82,6 +82,27 @@ namespace Hushian.WebApi.Controllers.v1
|
||||
var response = await _experService.GetInfoExper(ExperID);
|
||||
return response != null ? Ok(response) : BadRequest(new List<string> { "یافت نشد" });
|
||||
}
|
||||
[HttpGet("GetCurrentUserInfo")]
|
||||
[Authorize(Roles = "Exper,Company")]
|
||||
public async Task<ActionResult> GetCurrentUserInfo()
|
||||
{
|
||||
int CompanyID = 0;
|
||||
int? ExperID = null;
|
||||
if (User.IsInRole("Exper"))
|
||||
{
|
||||
string strExperID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
|
||||
ExperID = Convert.ToInt32(strExperID);
|
||||
|
||||
}
|
||||
else if (User.IsInRole("Company"))
|
||||
{
|
||||
string strCompanyID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
|
||||
CompanyID = Convert.ToInt32(strCompanyID);
|
||||
}
|
||||
|
||||
var response = await _experService.GetCurrentUserInfo(CompanyID,ExperID);
|
||||
return response != null ? Ok(response) : BadRequest(new List<string> { "یافت نشد" });
|
||||
}
|
||||
[HttpPut("ExperEditingFromManager/{ExperID}")] //ویرایش کارشناس توسط مدیرش
|
||||
[Authorize(Roles = "Company")]
|
||||
public async Task<ActionResult> ExperEditingFromManager(int ExperID, [FromBody] Update_ExperDto editUser)
|
||||
|
@@ -80,12 +80,12 @@ namespace Hushian.WebApi.Controllers.v1
|
||||
{
|
||||
string strExperID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
|
||||
int ExperID = Convert.ToInt32(strExperID);
|
||||
CompanyID =await _experService.GetCompanyIDExper(ExperID);
|
||||
CompanyID = await _experService.GetCompanyIDExper(ExperID);
|
||||
}
|
||||
else if (User.IsInRole("Company"))
|
||||
{
|
||||
string strCompanyID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
|
||||
CompanyID = Convert.ToInt32(strCompanyID);
|
||||
CompanyID = Convert.ToInt32(strCompanyID);
|
||||
|
||||
|
||||
}
|
||||
@@ -100,6 +100,27 @@ namespace Hushian.WebApi.Controllers.v1
|
||||
var response = await _groupService.GetGroupsExper(ExperID);
|
||||
return Ok(response);
|
||||
}
|
||||
[HttpGet("GetGroups")]
|
||||
[Authorize]
|
||||
public async Task<ActionResult<List<Read_GroupDto>>> GetGroupsAnon()
|
||||
{
|
||||
if (User.IsInRole("Exper"))
|
||||
{
|
||||
string strExperID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
|
||||
int ExperID = Convert.ToInt32(strExperID);
|
||||
var response = await _groupService.GetGroupsExper(ExperID);
|
||||
return Ok(response);
|
||||
}
|
||||
else if (User.IsInRole("Company"))
|
||||
{
|
||||
string strCompanyID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
|
||||
int CompanyID = Convert.ToInt32(strCompanyID);
|
||||
var response = await _groupService.GetGroupsCompany(CompanyID);
|
||||
return Ok(response);
|
||||
|
||||
}
|
||||
return NotFound();
|
||||
}
|
||||
[HttpGet("GetExpersFromGroupID/{GroupID}")]
|
||||
public async Task<ActionResult<List<Read_ExperDto>>> GetExpersGroup(int GroupID)
|
||||
{
|
||||
@@ -121,9 +142,9 @@ namespace Hushian.WebApi.Controllers.v1
|
||||
string strCompanyID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
|
||||
int CompanyID = Convert.ToInt32(strCompanyID);
|
||||
var response = await _groupService.ChangeAvailableGroup(new Common.Dtos.Exper.ChangeAvailable_GroupDto()
|
||||
{ Available=Available,ID=GroupID}, CompanyID);
|
||||
return response? NoContent()
|
||||
: BadRequest(new List<string> { "یافت نشد"});
|
||||
{ Available = Available, ID = GroupID }, CompanyID);
|
||||
return response ? NoContent()
|
||||
: BadRequest(new List<string> { "یافت نشد" });
|
||||
}
|
||||
|
||||
}
|
||||
|
114
Presentation/HushianWebApp/Pages/Chat.razor
Normal file
114
Presentation/HushianWebApp/Pages/Chat.razor
Normal file
@@ -0,0 +1,114 @@
|
||||
@page "/Chant"
|
||||
@using Common.Dtos.Conversation
|
||||
@using Common.Dtos.Group
|
||||
@using HushianWebApp.Service
|
||||
@inject ChatService chatService
|
||||
@inject GroupService groupService
|
||||
@inject UserService userService
|
||||
@inject IJSRuntime JS
|
||||
@code {
|
||||
public Common.Dtos.CurrentUserInfo CurrentUser { get; set; }
|
||||
List<Read_GroupDto> _Group = new List<Read_GroupDto>();
|
||||
//-------------------------------------
|
||||
bool isSelectedInbox1 = false;
|
||||
public List<ChatItemDto> Inbox1Items { get; set; } = new();
|
||||
bool isSelectedInbox2 = true;
|
||||
public List<ChatItemDto> Inbox2Items { get; set; } = new();
|
||||
bool isSelectedInbox3 = false;
|
||||
public List<ChatItemDto> Inbox3Items { get; set; } = new();
|
||||
/////////////
|
||||
public ChatItemDto? ChatCurrent { get; set; } = null;
|
||||
public string MsgInput { get; set; }
|
||||
}
|
||||
@functions {
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
CurrentUser =await userService.GetCurrentUserInfo();
|
||||
_Group = await groupService.GetGroups();
|
||||
Inbox1Items = await chatService.ChatAwaitingOurResponse();
|
||||
Inbox2Items = await chatService.MyChatsIsInProgress();
|
||||
Inbox3Items = await chatService.MyChatsIsFinished();
|
||||
await base.OnInitializedAsync();
|
||||
}
|
||||
async Task OnclickInbox(int ID)
|
||||
{
|
||||
switch (ID)
|
||||
{
|
||||
case 1:
|
||||
isSelectedInbox1 = true;
|
||||
isSelectedInbox2 = false;
|
||||
isSelectedInbox3 = false;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
isSelectedInbox2 = true;
|
||||
isSelectedInbox1 = false;
|
||||
isSelectedInbox3 = false;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
isSelectedInbox3 = true;
|
||||
isSelectedInbox2 = false;
|
||||
isSelectedInbox1 = false;
|
||||
break;
|
||||
}
|
||||
ChatCurrent = null;
|
||||
|
||||
}
|
||||
async Task SendMsg()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(MsgInput) && ChatCurrent != null)
|
||||
{
|
||||
Common.Enums.ConversationType type = CurrentUser.Role == "Company" ? Common.Enums.ConversationType.CU : Common.Enums.ConversationType.EU;
|
||||
await chatService.ADDChatResponse(ChatCurrent.ID, MsgInput, type);
|
||||
ChatCurrent?.Responses.Add(new() { text = MsgInput, Type = type });
|
||||
ChatCurrent.LastText = MsgInput;
|
||||
await Task.Yield();
|
||||
await JS.InvokeVoidAsync("scrollToBottom", "B1");
|
||||
MsgInput = string.Empty;
|
||||
}
|
||||
}
|
||||
async Task onClickSelectedCon(int InboxID, Read_ConversationDto conversationDto)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
<style>
|
||||
|
||||
.input-group-text-chat {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: .375rem .75rem;
|
||||
font-size: 1rem;
|
||||
font-weight: 400;
|
||||
line-height: 1.5;
|
||||
color: var(--bs-body-color);
|
||||
text-align: center;
|
||||
white-space: nowrap;
|
||||
border-radius: var(--bs-border-radius);
|
||||
}
|
||||
|
||||
</style>
|
||||
<script>
|
||||
window.getWindowSize = () => {
|
||||
return {
|
||||
width: window.innerWidth,
|
||||
height: window.innerHeight
|
||||
};
|
||||
};
|
||||
|
||||
window.registerResizeCallback = (dotNetHelper) => {
|
||||
window.onresize = () => {
|
||||
dotNetHelper.invokeMethodAsync("OnResize");
|
||||
};
|
||||
};
|
||||
|
||||
window.scrollToBottom = (elementId) => {
|
||||
const el = document.getElementById(elementId);
|
||||
if (el) {
|
||||
el.scrollTop = el.scrollHeight;
|
||||
}
|
||||
};
|
||||
</script>
|
62
Presentation/HushianWebApp/Service/ChatService.cs
Normal file
62
Presentation/HushianWebApp/Service/ChatService.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using Common.Dtos.Conversation;
|
||||
using Common.Enums;
|
||||
using System.Net.Http.Json;
|
||||
|
||||
namespace HushianWebApp.Service
|
||||
{
|
||||
public class ChatService
|
||||
{
|
||||
private readonly BaseController _baseController;
|
||||
const string BaseRoute = "v1/Chat/";
|
||||
|
||||
//Inbox1
|
||||
public async Task<List<ChatItemDto>> ChatAwaitingOurResponse()
|
||||
{
|
||||
var response = await _baseController.Get($"{BaseRoute}ChatsAwaitingOurResponse");
|
||||
if (response.IsSuccessStatusCode)
|
||||
return await response.Content.ReadFromJsonAsync<List<ChatItemDto>>();
|
||||
|
||||
return new();
|
||||
}
|
||||
//Inbox2
|
||||
public async Task<List<ChatItemDto>> MyChatsIsInProgress()
|
||||
{
|
||||
var response = await _baseController.Post($"{BaseRoute}MyChats", ConversationStatus.InProgress);
|
||||
if (response.IsSuccessStatusCode)
|
||||
return await response.Content.ReadFromJsonAsync<List<ChatItemDto>>();
|
||||
|
||||
return new();
|
||||
}
|
||||
//Inbox3
|
||||
public async Task<List<ChatItemDto>> MyChatsIsFinished()
|
||||
{
|
||||
var response = await _baseController.Post($"{BaseRoute}MyChats", ConversationStatus.Finished);
|
||||
if (response.IsSuccessStatusCode)
|
||||
return await response.Content.ReadFromJsonAsync<List<ChatItemDto>>();
|
||||
|
||||
return new();
|
||||
}
|
||||
public async Task<ChatItemDto> NewChatFromCurrentUser(ADD_ConversationDto conversation)
|
||||
{
|
||||
var response = await _baseController.Post($"{BaseRoute}NewChatFromCurrentUser", conversation);
|
||||
if (response.IsSuccessStatusCode)
|
||||
return await response.Content.ReadFromJsonAsync<ChatItemDto>();
|
||||
|
||||
return null;
|
||||
}
|
||||
public async Task<ChatItemResponseDto?> ADDChatResponse(int ConversationID, string text, ConversationType type)
|
||||
{
|
||||
var response = await _baseController.Post($"{BaseRoute}ADDChatResponse", new ADD_ConversationResponseDto()
|
||||
{
|
||||
ConversationID = ConversationID,
|
||||
Text = text,
|
||||
Type = type
|
||||
});
|
||||
if (response.IsSuccessStatusCode)
|
||||
return await response.Content.ReadFromJsonAsync<ChatItemResponseDto>();
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -39,6 +39,15 @@ namespace HushianWebApp.Service
|
||||
var response = await _baseController.Delete ($"{BaseRoute}DeleteGroup/{GroupID}");
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
public async Task<List<Read_GroupDto>?> GetGroups()
|
||||
{
|
||||
var response = await _baseController.Get($"{BaseRoute}GetGroups");
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
return await response.Content.ReadFromJsonAsync<List<Read_GroupDto>>();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public async Task<List<Read_GroupDto>?> GetGroupsCompany()
|
||||
{
|
||||
var response = await _baseController.Get($"{BaseRoute}GetGroupsCompany");
|
||||
|
@@ -92,6 +92,15 @@ namespace HushianWebApp.Service
|
||||
var response = await _baseController.Delete($"{BaseRoute}DeleteExperFromManager/{ExperID}");
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
public async Task<CurrentUserInfo> GetCurrentUserInfo()
|
||||
{
|
||||
var response = await _baseController.Get($"{BaseRoute}GetCurrentUserInfo");
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
return await response.Content.ReadFromJsonAsync<CurrentUserInfo>();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user