...
This commit is contained in:
@@ -195,6 +195,8 @@ namespace Hushian.Application.Services
|
||||
|
||||
return Response;
|
||||
}
|
||||
public async Task<bool> AnyCompany(int CompanyID)
|
||||
=>await _CompanyRepository.Get().AnyAsync(a=>a.ID==CompanyID);
|
||||
private async Task<int> Verifi(string Mobile) => await _VerificationService.GenerateCodeByPhoneNumberConfirmed(Mobile);
|
||||
|
||||
}
|
||||
|
105
Hushian.Application/Services/ConversationService.cs
Normal file
105
Hushian.Application/Services/ConversationService.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
using AutoMapper;
|
||||
using Common.Dtos.Conversation;
|
||||
using Common.Enums;
|
||||
using Hushian.Application.Contracts.Persistence;
|
||||
using Hushian.Application.Models;
|
||||
using Hushian.Domain.Entites;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.VisualBasic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hushian.Application.Services
|
||||
{
|
||||
public class ConversationService
|
||||
{
|
||||
private readonly IGenericRepository<Conversation> _ConversationRepository;
|
||||
private readonly IGenericRepository<ConversationResponse> _ConversationResponseRepository;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly CompanyService _companyService;
|
||||
private readonly UserService _userService;
|
||||
private readonly GroupService _groupService;
|
||||
private readonly ExperService _experService;
|
||||
public async Task<ResponseBase<int>> NewConversation(ADD_ConversationDto dto, ConversationType type = ConversationType.UE)
|
||||
{
|
||||
var Response = new ResponseBase<int>();
|
||||
if (await _companyService.AnyCompany(dto.CompanyID))
|
||||
{
|
||||
if (await _userService.AnyUser(dto.UserID))
|
||||
{
|
||||
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 } }
|
||||
};
|
||||
Response.Value = (await _ConversationRepository.ADD(conversation)).ID;
|
||||
Response.Success = Response.Value > 0;
|
||||
}
|
||||
else Response.Errors.Add("شناسه گروه صحیح نمی باشد");
|
||||
|
||||
}
|
||||
else Response.Errors.Add("شناسه کاربر یافت نشد");
|
||||
|
||||
}
|
||||
else Response.Errors.Add("شناسه شرکت یافت نشد");
|
||||
|
||||
|
||||
return Response;
|
||||
}
|
||||
public async Task<ResponseBase<int>> NewConversationResponse(ADD_ConversationResponseDto dto, int? ExperID)
|
||||
{
|
||||
var Response = new ResponseBase<int>();
|
||||
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
|
||||
};
|
||||
Response.Value = (await _ConversationResponseRepository.ADD(response)).ID;
|
||||
Response.Success = Response.Value > 0;
|
||||
}
|
||||
else Response.Errors.Add("گفتگویی یافت نشد");
|
||||
}
|
||||
|
||||
return Response;
|
||||
}
|
||||
public async Task<List<Read_ConversationDto>> MyConversation(int CompanyID, string UserID)
|
||||
{ return new(); }
|
||||
public async Task<List<Read_ConversationDto>> MyConversationIsFinished(int CompanyID, string? ExperID = null)
|
||||
{ return new(); }
|
||||
public async Task<List<Read_ConversationDto>> MyConversationIsInProgress(int CompanyID, string ExperID)
|
||||
{ return new(); }
|
||||
public async Task<List<Read_ConversationDto>> ConversationAwaitingOurResponse(int CompanyID, string? ExperID = null)
|
||||
{ return new(); }
|
||||
}
|
||||
}
|
@@ -110,11 +110,11 @@ namespace Hushian.Application.Services
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public async Task<bool> CHeckGroupMemberCompany(int GroupID, int CompanyID)
|
||||
{
|
||||
return await _GroupRepository.Get().AnyAsync(a => a.CompanyID == CompanyID && a.ID == GroupID);
|
||||
}
|
||||
public async Task<bool> AnyGroup(int GroupID) =>
|
||||
await _GroupRepository.Get().AnyAsync(a=>a.ID==GroupID);
|
||||
public async Task<bool> CHeckGroupMemberCompany(int GroupID, int CompanyID)=>
|
||||
await _GroupRepository.Get().AnyAsync(a => a.CompanyID == CompanyID && a.ID == GroupID);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
18
Hushian.Application/Services/UserService.cs
Normal file
18
Hushian.Application/Services/UserService.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using Hushian.Application.Contracts.Persistence;
|
||||
using Hushian.Domain.Entites;
|
||||
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 UserService
|
||||
{
|
||||
private readonly IGenericRepository<User> _UserRepository;
|
||||
public async Task<bool> AnyUser(int UserID) =>await _UserRepository.Get().AnyAsync(a=>a.ID==UserID);
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user