2025-07-03 16:38:14 +03:30
|
|
|
|
using Common.Dtos;
|
|
|
|
|
using Common.Dtos.Exper;
|
2025-06-29 16:14:42 +03:30
|
|
|
|
using Hushian.Application.Contracts.Persistence;
|
|
|
|
|
using Hushian.Application.Models;
|
|
|
|
|
using Hushian.Application.Validation;
|
|
|
|
|
using Hushian.Domain.Entites;
|
2025-07-03 16:38:14 +03:30
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2025-06-29 16:14:42 +03:30
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Hushian.Application.Services
|
|
|
|
|
{
|
|
|
|
|
public class ExperService
|
|
|
|
|
{
|
|
|
|
|
private readonly IGenericRepository<Company> _CompanyRepository;
|
|
|
|
|
private readonly IGenericRepository<Exper> _ExperRepository;
|
2025-07-03 16:38:14 +03:30
|
|
|
|
private readonly VerificationService _VerificationService;
|
|
|
|
|
public async Task<ResponseBase<bool>> ADDExper(ADD_ExperDto dto, int CompanyID)
|
2025-06-29 16:14:42 +03:30
|
|
|
|
{
|
2025-07-03 16:38:14 +03:30
|
|
|
|
var Response = new ResponseBase<bool>();
|
2025-06-29 16:14:42 +03:30
|
|
|
|
|
|
|
|
|
#region Validation
|
|
|
|
|
bool validate = true;
|
|
|
|
|
var errors = new List<string>();
|
|
|
|
|
|
|
|
|
|
validate = dto.Password.CheckLawPassword(ref errors);
|
2025-07-03 16:38:14 +03:30
|
|
|
|
|
2025-06-29 16:14:42 +03:30
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
if (validate)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string UserName = $"E/{CompanyID.ToString("00")}/{_ExperRepository.Get().Count(c => c.CompanyID == CompanyID).ToString("0000")}";
|
|
|
|
|
Response.Success = Response.Value = await _ExperRepository.ADDBool(new Exper()
|
|
|
|
|
{
|
|
|
|
|
CompanyID = CompanyID,
|
|
|
|
|
FullName = dto.FullName,
|
|
|
|
|
Password = dto.Password.GetHash(),
|
|
|
|
|
UserName = UserName
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Response.Errors.Add("خطای سیستمی کد 01");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Response.Errors.AddRange(errors);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Response;
|
|
|
|
|
}
|
2025-07-03 16:38:14 +03:30
|
|
|
|
//Get Info
|
|
|
|
|
// Update
|
|
|
|
|
public async Task<ResponseBase<bool>> ChangePasswordExperFromExper(ChangePasswordDto model, int ExperID)
|
|
|
|
|
{
|
|
|
|
|
ResponseBase<bool> Response = new();
|
|
|
|
|
|
|
|
|
|
var exper = await _ExperRepository.Get().FirstOrDefaultAsync(f => f.ID == ExperID);
|
|
|
|
|
if (string.IsNullOrEmpty(model.OldPassWord) || model.OldPassWord.GetHash() != exper.Password)
|
|
|
|
|
{
|
|
|
|
|
Response.Errors.Add("کلمه عبور فعلی صحیح نمی باشد");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
exper.Password = model.NewPassWord.GetHash();
|
|
|
|
|
Response.Value = await _ExperRepository.UPDATEBool(exper);
|
|
|
|
|
if (!Response.Value) Response.Errors.Add("خطا در ذخیره سازی");
|
|
|
|
|
else Response.Success = true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return Response;
|
|
|
|
|
}
|
|
|
|
|
public async Task<ResponseBase<bool>> ChangePasswordExperFromCompanyManaget(ChangePasswordDto model, int ExperID, int CompanyID)
|
|
|
|
|
{
|
|
|
|
|
ResponseBase<bool> Response = new();
|
|
|
|
|
var exper = await _ExperRepository.Get().FirstOrDefaultAsync(f => f.ID == ExperID);
|
|
|
|
|
|
|
|
|
|
if (exper.CompanyID == CompanyID)
|
|
|
|
|
{
|
|
|
|
|
exper.Password = model.NewPassWord.GetHash();
|
|
|
|
|
Response.Value = await _ExperRepository.UPDATEBool(exper);
|
|
|
|
|
if (!Response.Value) Response.Errors.Add("خطا در ذخیره سازی");
|
|
|
|
|
else Response.Success = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Response.Errors.Add("کاربری یافت نشد");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Response;
|
|
|
|
|
}
|
|
|
|
|
public async Task<ResponseBase<int>> ForgetPasswordExper(string UserName)
|
|
|
|
|
{
|
|
|
|
|
ResponseBase<int> Response = new();
|
|
|
|
|
|
|
|
|
|
var company = await _ExperRepository.Get().FirstOrDefaultAsync(f => f.UserName == UserName);
|
|
|
|
|
if (company == null)
|
|
|
|
|
{
|
|
|
|
|
Response.Errors.Add("کاربری یافت نشد");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Response.Value = await _VerificationService.GenerateCodeByForgetPassword(UserName);
|
|
|
|
|
Response.Success = true;
|
|
|
|
|
}
|
|
|
|
|
return Response;
|
|
|
|
|
}
|
2025-06-29 16:14:42 +03:30
|
|
|
|
}
|
|
|
|
|
}
|