1667 lines
71 KiB
C#
1667 lines
71 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Security.AccessControl;
|
|
using System.Threading.Tasks;
|
|
using _0_Framework.Application;
|
|
using _0_Framework.Application.Enums;
|
|
using _0_Framework.Application.UID;
|
|
using _0_Framework.Exceptions;
|
|
using Company.Domain.empolyerAgg;
|
|
using Company.Domain.InstitutionContractAgg;
|
|
using Company.Domain.WorkshopAgg;
|
|
using CompanyManagment.App.Contracts.Checkout;
|
|
using CompanyManagment.App.Contracts.Employer;
|
|
using CompanyManagment.EFCore.Repository;
|
|
using Microsoft.Identity.Client;
|
|
|
|
namespace CompanyManagment.Application;
|
|
|
|
public class EmployerApplication : IEmployerApplication
|
|
{
|
|
private readonly IEmployerRepository _EmployerRepository;
|
|
private readonly IWorkshopRepository _workshopRepository;
|
|
public bool nationalCodValid = false;
|
|
public bool idnumberIsOk = true;
|
|
public bool nameIsOk = true;
|
|
public bool nationalcodeIsOk = true;
|
|
public bool legalNameIsOk = true;
|
|
|
|
public bool registerIdIsOk = true;
|
|
public bool nationalIdIsOk = true;
|
|
private readonly IInstitutionContractRepository _institutionContractRepository;
|
|
private readonly IUidService _uidService;
|
|
|
|
public EmployerApplication(IEmployerRepository employerRepository, IWorkshopRepository workshopRepository,
|
|
IInstitutionContractRepository institutionContractRepository, IUidService uidService)
|
|
{
|
|
_EmployerRepository = employerRepository;
|
|
_workshopRepository = workshopRepository;
|
|
_institutionContractRepository = institutionContractRepository;
|
|
_uidService = uidService;
|
|
}
|
|
|
|
|
|
|
|
public OperationResult Active(long id)
|
|
{
|
|
var opration = new OperationResult();
|
|
var employer = _EmployerRepository.Get(id);
|
|
if (employer == null)
|
|
return opration.Failed("رکورد مورد نظر یافت نشد");
|
|
|
|
employer.Active();
|
|
|
|
_EmployerRepository.SaveChanges();
|
|
return opration.Succcedded();
|
|
}
|
|
|
|
public OperationResult Create(CreateEmployer command)
|
|
{
|
|
var opration = new OperationResult();
|
|
if (_EmployerRepository.Exists(x =>
|
|
(x.FName == command.FName && x.LName == command.LName) && x.Nationalcode == command.Nationalcode &&
|
|
x.Nationalcode != null))
|
|
return opration.Failed("امکان ثبت رکورد تکراری وجود ندارد");
|
|
//if (_EmployerRepository.Exists(x => x.IdNumber == command.IdNumber && x.IdNumber != null))
|
|
// return opration.Failed("شماره شناسنامه وارد شده تکراری است");
|
|
//if (_EmployerRepository.Exists(x => x.LName == command.LName && x.FName == command.FName))
|
|
//{
|
|
// nameIsOk = false;
|
|
// return opration.Failed("نام و نام خانوادگی وارد شده تکراری است");
|
|
//}
|
|
if (string.IsNullOrWhiteSpace(command.FName))
|
|
return opration.Failed("لطفا نام را وارد کنید");
|
|
if (!string.IsNullOrWhiteSpace(command.Nationalcode))
|
|
{
|
|
try
|
|
{
|
|
char[] chArray = command.Nationalcode.ToCharArray();
|
|
int[] numArray = new int[chArray.Length];
|
|
var cunt = chArray.Length;
|
|
for (int i = 0; i < chArray.Length; i++)
|
|
{
|
|
numArray[i] = (int)char.GetNumericValue(chArray[i]);
|
|
}
|
|
|
|
int num2 = numArray[9];
|
|
switch (command.Nationalcode)
|
|
{
|
|
case "0000000000":
|
|
case "1111111111":
|
|
case "22222222222":
|
|
case "33333333333":
|
|
case "4444444444":
|
|
case "5555555555":
|
|
case "6666666666":
|
|
case "7777777777":
|
|
case "8888888888":
|
|
case "9999999999":
|
|
nationalCodValid = false;
|
|
return opration.Failed("کد ملی وارد شده صحیح نمی باشد");
|
|
}
|
|
|
|
int num3 =
|
|
((((((((numArray[0] * 10) + (numArray[1] * 9)) + (numArray[2] * 8)) + (numArray[3] * 7)) +
|
|
(numArray[4] * 6)) + (numArray[5] * 5)) + (numArray[6] * 4)) + (numArray[7] * 3)) +
|
|
(numArray[8] * 2);
|
|
int num4 = num3 - ((num3 / 11) * 11);
|
|
if ((((num4 == 0) && (num2 == num4)) || ((num4 == 1) && (num2 == 1))) ||
|
|
((num4 > 1) && (num2 == Math.Abs((int)(num4 - 11)))) && cunt <= 10)
|
|
{
|
|
nationalCodValid = true;
|
|
}
|
|
else
|
|
{
|
|
nationalCodValid = false;
|
|
return opration.Failed("کد ملی وارد شده نا معتبر است");
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
nationalCodValid = false;
|
|
return opration.Failed("لطفا کد ملی 10 رقمی وارد کنید");
|
|
}
|
|
|
|
if (_EmployerRepository.Exists(x =>
|
|
x.Nationalcode == command.Nationalcode && !string.IsNullOrWhiteSpace(command.Nationalcode)))
|
|
{
|
|
nationalcodeIsOk = false;
|
|
return opration.Failed("کد ملی وارد شده تکراری است");
|
|
}
|
|
}
|
|
|
|
string initial = "1300/10/11";
|
|
var dateOfBirth = command.DateOfBirth != null
|
|
? command.DateOfBirth.ToGeorgianDateTime()
|
|
: initial.ToGeorgianDateTime();
|
|
var dateOfIssue = command.DateOfIssue != null
|
|
? command.DateOfIssue.ToGeorgianDateTime()
|
|
: initial.ToGeorgianDateTime();
|
|
var employerData = new Employer(command.FName, command.LName, command.ContractingPartyId, command.Gender,
|
|
command.Nationalcode, command.IdNumber, command.Nationality, command.FatherName, dateOfBirth,
|
|
dateOfIssue, command.PlaceOfIssue, "*", "*", "*", "حقیقی", command.Phone,
|
|
command.AgentPhone, "true", command.MclsUserName, command.MclsPassword, command.EserviceUserName,
|
|
command.EservicePassword,
|
|
command.TaxOfficeUserName, command.TaxOfficepassword, command.SanaUserName, command.SanaPassword);
|
|
_EmployerRepository.Create(employerData);
|
|
_EmployerRepository.SaveChanges();
|
|
return opration.Succcedded();
|
|
}
|
|
|
|
public OperationResult CreateLegals(CreateEmployer command)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(command.EmployerLName))
|
|
command.EmployerLName = "#";
|
|
var opration = new OperationResult();
|
|
if (_EmployerRepository.Exists(x =>
|
|
x.LName == command.LName && x.NationalId == command.NationalId &&
|
|
x.EmployerLName == command.EmployerLName))
|
|
return opration.Failed("امکان ثبت رکورد تکراری وجود ندارد");
|
|
if (_EmployerRepository.Exists(x =>
|
|
x.NationalId == command.NationalId && !string.IsNullOrWhiteSpace(command.NationalId) &&
|
|
x.NationalId != null))
|
|
{
|
|
nationalIdIsOk = false;
|
|
return opration.Failed(" شناسه ملی وارد شده تکراری است");
|
|
}
|
|
|
|
if (_EmployerRepository.Exists(x => x.LName == command.LName))
|
|
{
|
|
nameIsOk = false;
|
|
return opration.Failed("نام شرکت وارد شده تکراری است");
|
|
}
|
|
|
|
if (_EmployerRepository.Exists(x =>
|
|
x.RegisterId == command.RegisterId && !string.IsNullOrWhiteSpace(command.RegisterId) &&
|
|
x.RegisterId != null))
|
|
{
|
|
registerIdIsOk = false;
|
|
return opration.Failed(" شماره ثبت وارد شده تکراری است");
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(command.NationalId) && command.NationalId.Length != 11)
|
|
{
|
|
return opration.Failed(" شناسه ملی باید 11 رقم باشد");
|
|
}
|
|
|
|
//if (_EmployerRepository.Exists(x => x.EmployerLName == command.EmployerLName && x.EmployerLName !="#"))
|
|
//{
|
|
// legalNameIsOk = false;
|
|
// return opration.Failed(" نام کارفرمای وارد شده تکراری است");
|
|
//}
|
|
//if (_EmployerRepository.Exists(x => x.IdNumber == command.IdNumber && x.IdNumber != null))
|
|
//{
|
|
// idnumberIsOk = false;
|
|
// return opration.Failed("شمار شناسنامه وارد شده تکراری است");
|
|
//}
|
|
if (!string.IsNullOrWhiteSpace(command.Nationalcode))
|
|
{
|
|
try
|
|
{
|
|
char[] chArray = command.Nationalcode.ToCharArray();
|
|
int[] numArray = new int[chArray.Length];
|
|
var cunt = chArray.Length;
|
|
for (int i = 0; i < chArray.Length; i++)
|
|
{
|
|
numArray[i] = (int)char.GetNumericValue(chArray[i]);
|
|
}
|
|
|
|
int num2 = numArray[9];
|
|
switch (command.Nationalcode)
|
|
{
|
|
case "0000000000":
|
|
case "1111111111":
|
|
case "22222222222":
|
|
case "33333333333":
|
|
case "4444444444":
|
|
case "5555555555":
|
|
case "6666666666":
|
|
case "7777777777":
|
|
case "8888888888":
|
|
case "9999999999":
|
|
nationalCodValid = false;
|
|
return opration.Failed("کد ملی وارد شده صحیح نمی باشد");
|
|
}
|
|
|
|
int num3 =
|
|
((((((((numArray[0] * 10) + (numArray[1] * 9)) + (numArray[2] * 8)) + (numArray[3] * 7)) +
|
|
(numArray[4] * 6)) + (numArray[5] * 5)) + (numArray[6] * 4)) + (numArray[7] * 3)) +
|
|
(numArray[8] * 2);
|
|
int num4 = num3 - ((num3 / 11) * 11);
|
|
if ((((num4 == 0) && (num2 == num4)) || ((num4 == 1) && (num2 == 1))) ||
|
|
((num4 > 1) && (num2 == Math.Abs((int)(num4 - 11)))) && cunt <= 10)
|
|
{
|
|
nationalCodValid = true;
|
|
}
|
|
else
|
|
{
|
|
nationalCodValid = false;
|
|
return opration.Failed("کد ملی وارد شده نا معتبر است");
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
nationalCodValid = false;
|
|
return opration.Failed("لطفا کد ملی 10 رقمی وارد کنید");
|
|
}
|
|
//if (_EmployerRepository.Exists(x => x.Nationalcode == command.Nationalcode))
|
|
//{
|
|
// nationalcodeIsOk = false;
|
|
// return opration.Failed(" کد ملی وارد شده تکراری است");
|
|
//}
|
|
}
|
|
|
|
string initial = "1300/10/11";
|
|
var dateOfBirth = command.DateOfBirth != null
|
|
? command.DateOfBirth.ToGeorgianDateTime()
|
|
: initial.ToGeorgianDateTime();
|
|
var dateOfIssue = command.DateOfIssue != null
|
|
? command.DateOfIssue.ToGeorgianDateTime()
|
|
: initial.ToGeorgianDateTime();
|
|
var LegalEmployerData = new Employer(command.FName, command.LName, command.ContractingPartyId, command.Gender,
|
|
command.Nationalcode, command.IdNumber, command.Nationality, command.FatherName, dateOfBirth,
|
|
dateOfIssue, command.PlaceOfIssue, command.RegisterId, command.NationalId, command.EmployerLName, "حقوقی",
|
|
command.Phone,
|
|
command.AgentPhone, "true", command.MclsUserName, command.MclsPassword, command.EserviceUserName,
|
|
command.EservicePassword,
|
|
command.TaxOfficeUserName, command.TaxOfficepassword, command.SanaUserName, command.SanaPassword);
|
|
|
|
|
|
_EmployerRepository.Create(LegalEmployerData);
|
|
_EmployerRepository.SaveChanges();
|
|
|
|
return opration.Succcedded();
|
|
}
|
|
|
|
public OperationResult DeActive(long id)
|
|
{
|
|
var opration = new OperationResult();
|
|
var employer = _EmployerRepository.Get(id);
|
|
if (employer == null)
|
|
return opration.Failed("رکورد مورد نظر یافت نشد");
|
|
|
|
employer.DeActive();
|
|
|
|
_EmployerRepository.SaveChanges();
|
|
return opration.Succcedded();
|
|
}
|
|
|
|
public OperationResult Remove_Old(long id)
|
|
{
|
|
var opration = new OperationResult();
|
|
|
|
bool result = _EmployerRepository.Remove(id);
|
|
if (result)
|
|
{
|
|
opration.Message = "حذف با موفقیت انجام شد";
|
|
opration.IsSuccedded = true;
|
|
}
|
|
else
|
|
return opration.Failed("حذف با خطا مواجه نشد");
|
|
|
|
return opration;
|
|
}
|
|
|
|
public List<EmployerViewModel> GetEmployers()
|
|
{
|
|
return _EmployerRepository.GetEmployers();
|
|
}
|
|
|
|
public OperationResult Edit(EditEmployer command)
|
|
{
|
|
var opration = new OperationResult();
|
|
var employer = _EmployerRepository.Get(command.Id);
|
|
if (employer == null)
|
|
return opration.Failed("رکورد مورد نظر یافت نشد");
|
|
|
|
if (_EmployerRepository.Exists(x =>
|
|
(x.FName == command.FName && x.LName == command.LName) && x.Nationalcode == command.Nationalcode &&
|
|
x.id != command.Id))
|
|
return opration.Failed("امکان ثبت رکورد تکراری وجود ندارد");
|
|
if (!string.IsNullOrWhiteSpace(command.Nationalcode))
|
|
{
|
|
try
|
|
{
|
|
char[] chArray = command.Nationalcode.ToCharArray();
|
|
int[] numArray = new int[chArray.Length];
|
|
var cunt = chArray.Length;
|
|
for (int i = 0; i < chArray.Length; i++)
|
|
{
|
|
numArray[i] = (int)char.GetNumericValue(chArray[i]);
|
|
}
|
|
|
|
int num2 = numArray[9];
|
|
switch (command.Nationalcode)
|
|
{
|
|
case "0000000000":
|
|
case "1111111111":
|
|
case "22222222222":
|
|
case "33333333333":
|
|
case "4444444444":
|
|
case "5555555555":
|
|
case "6666666666":
|
|
case "7777777777":
|
|
case "8888888888":
|
|
case "9999999999":
|
|
|
|
|
|
nationalCodValid = false;
|
|
return opration.Failed("کد ملی وارد شده صحیح نمی باشد");
|
|
}
|
|
|
|
int num3 =
|
|
((((((((numArray[0] * 10) + (numArray[1] * 9)) + (numArray[2] * 8)) + (numArray[3] * 7)) +
|
|
(numArray[4] * 6)) + (numArray[5] * 5)) + (numArray[6] * 4)) + (numArray[7] * 3)) +
|
|
(numArray[8] * 2);
|
|
int num4 = num3 - ((num3 / 11) * 11);
|
|
if ((((num4 == 0) && (num2 == num4)) || ((num4 == 1) && (num2 == 1))) ||
|
|
((num4 > 1) && (num2 == Math.Abs((int)(num4 - 11)))) && cunt <= 10)
|
|
{
|
|
nationalCodValid = true;
|
|
}
|
|
else
|
|
{
|
|
nationalCodValid = false;
|
|
return opration.Failed("کد ملی وارد شده نا معتبر است");
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
nationalCodValid = false;
|
|
return opration.Failed("لطفا کد ملی 10 رقمی وارد کنید");
|
|
}
|
|
|
|
if (_EmployerRepository.Exists(x =>
|
|
x.Nationalcode == command.Nationalcode && !string.IsNullOrWhiteSpace(command.Nationalcode) &&
|
|
x.id != command.Id))
|
|
{
|
|
nationalcodeIsOk = false;
|
|
|
|
return opration.Failed(" کد ملی وارد شده تکراری است");
|
|
}
|
|
}
|
|
|
|
|
|
string initial = "1300/10/11";
|
|
var dateOfBirth = command.DateOfBirth != null
|
|
? command.DateOfBirth.ToGeorgianDateTime()
|
|
: initial.ToGeorgianDateTime();
|
|
var dateOfIssue = command.DateOfIssue != null
|
|
? command.DateOfIssue.ToGeorgianDateTime()
|
|
: initial.ToGeorgianDateTime();
|
|
employer.Edit(command.FName, command.LName, command.ContractingPartyId,
|
|
command.Gender, command.Nationalcode, command.IdNumber, command.Nationality, command.FatherName,
|
|
dateOfBirth, dateOfIssue, command.PlaceOfIssue, command.Phone, command.AgentPhone,
|
|
command.MclsUserName, command.MclsPassword, command.EserviceUserName, command.EservicePassword,
|
|
command.TaxOfficeUserName, command.TaxOfficepassword, command.SanaUserName, command.SanaPassword,
|
|
command.EmployerNo);
|
|
|
|
_EmployerRepository.SaveChanges();
|
|
return opration.Succcedded();
|
|
}
|
|
|
|
public OperationResult EditEmployerNo(EditEmployer command)
|
|
{
|
|
var opration = new OperationResult();
|
|
var EmployerNumber = _EmployerRepository.Get(command.Id);
|
|
if (EmployerNumber == null)
|
|
return opration.Failed("کارفرمای مورد نظر جهت تخصخی شماره یافت نشد");
|
|
|
|
if (string.IsNullOrWhiteSpace(EmployerNumber.EmployerNo))
|
|
{
|
|
EmployerNumber.EditEmployerNo(command.EmployerNo);
|
|
_EmployerRepository.SaveChanges();
|
|
return opration.Succcedded();
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public OperationResult EditLegal(EditEmployer command)
|
|
{
|
|
var opration = new OperationResult();
|
|
var legalEmployer = _EmployerRepository.Get(command.Id);
|
|
if (legalEmployer == null)
|
|
return opration.Failed("رکورد مورد نظر یافت نشد");
|
|
|
|
if (_EmployerRepository.Exists(x =>
|
|
x.LName == command.LName && x.NationalId == command.NationalId &&
|
|
!string.IsNullOrWhiteSpace(command.NationalId) && x.id != command.Id))
|
|
return opration.Failed("امکان ثبت رکورد تکراری وجود ندارد");
|
|
|
|
|
|
if (!string.IsNullOrEmpty(command.NationalId) && command.NationalId.Length != 11)
|
|
{
|
|
return opration.Failed(" شناسه ملی باید 11 رقم باشد");
|
|
}
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(command.Nationalcode))
|
|
{
|
|
try
|
|
{
|
|
char[] chArray = command.Nationalcode.ToCharArray();
|
|
int[] numArray = new int[chArray.Length];
|
|
var cunt = chArray.Length;
|
|
for (int i = 0; i < chArray.Length; i++)
|
|
{
|
|
numArray[i] = (int)char.GetNumericValue(chArray[i]);
|
|
}
|
|
|
|
int num2 = numArray[9];
|
|
switch (command.Nationalcode)
|
|
{
|
|
case "0000000000":
|
|
case "1111111111":
|
|
case "22222222222":
|
|
case "33333333333":
|
|
case "4444444444":
|
|
case "5555555555":
|
|
case "6666666666":
|
|
case "7777777777":
|
|
case "8888888888":
|
|
case "9999999999":
|
|
|
|
|
|
nationalCodValid = false;
|
|
return opration.Failed("کد ملی وارد شده صحیح نمی باشد");
|
|
}
|
|
|
|
int num3 =
|
|
((((((((numArray[0] * 10) + (numArray[1] * 9)) + (numArray[2] * 8)) + (numArray[3] * 7)) +
|
|
(numArray[4] * 6)) + (numArray[5] * 5)) + (numArray[6] * 4)) + (numArray[7] * 3)) +
|
|
(numArray[8] * 2);
|
|
int num4 = num3 - ((num3 / 11) * 11);
|
|
if ((((num4 == 0) && (num2 == num4)) || ((num4 == 1) && (num2 == 1))) ||
|
|
((num4 > 1) && (num2 == Math.Abs((int)(num4 - 11)))) && cunt <= 10)
|
|
{
|
|
nationalCodValid = true;
|
|
}
|
|
else
|
|
{
|
|
nationalCodValid = false;
|
|
return opration.Failed("کد ملی وارد شده نا معتبر است");
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
nationalCodValid = false;
|
|
return opration.Failed("لطفا کد ملی 10 رقمی وارد کنید");
|
|
}
|
|
//if (_EmployerRepository.Exists(x => x.Nationalcode == command.Nationalcode && x.id != command.Id))
|
|
//{
|
|
// nationalcodeIsOk = false;
|
|
|
|
// return opration.Failed(" کد ملی وارد شده تکراری است");
|
|
//}
|
|
}
|
|
|
|
string initial = "1300/10/11";
|
|
var dateOfBirth = command.DateOfBirth != null
|
|
? command.DateOfBirth.ToGeorgianDateTime()
|
|
: initial.ToGeorgianDateTime();
|
|
var dateOfIssue = command.DateOfIssue != null
|
|
? command.DateOfIssue.ToGeorgianDateTime()
|
|
: initial.ToGeorgianDateTime();
|
|
legalEmployer.EditLegal(command.FName, command.LName, command.ContractingPartyId, command.Gender,
|
|
command.Nationalcode, command.IdNumber, command.Nationality, command.FatherName, dateOfBirth,
|
|
dateOfIssue, command.PlaceOfIssue, command.RegisterId, command.NationalId, command.EmployerLName,
|
|
command.Phone, command.AgentPhone, command.MclsUserName, command.MclsPassword, command.EserviceUserName,
|
|
command.EservicePassword,
|
|
command.TaxOfficeUserName, command.TaxOfficepassword, command.SanaUserName, command.SanaPassword,
|
|
command.EmployerNo);
|
|
|
|
_EmployerRepository.SaveChanges();
|
|
return opration.Succcedded();
|
|
}
|
|
|
|
public EditEmployer GetDetails(long id)
|
|
{
|
|
return _EmployerRepository.GetDetails(id);
|
|
}
|
|
|
|
public List<EmployerViewModel> Search(EmployerSearchModel searchModel)
|
|
{
|
|
var result = _EmployerRepository.Search(searchModel);
|
|
|
|
var workshopList = _workshopRepository.GetWorkshop();
|
|
var WorkshopEmployers = _workshopRepository.WorkshopEmployers();
|
|
|
|
List<long> employerList;
|
|
foreach (var item in result)
|
|
{
|
|
var workshopIds = WorkshopEmployers.Where(x => x.EmployerId == item.Id).Select(x => x.WorkshopId);
|
|
item.WorkshopList = workshopList.Where(x => workshopIds.Contains(x.Id)).ToList();
|
|
//employerList = new List<long> { item.Id };
|
|
//item.WorkshopList = _workshopRepository.GetWorkshopsByEmployerId(employerList);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public List<EmprViewModel> GetEmployerByWorkshopId(long workshopId)
|
|
{
|
|
return _EmployerRepository.GetEmployerByWorkshopId(workshopId);
|
|
}
|
|
|
|
public List<EmployerViewModel> GetEmployerByContracrtingPartyID(long id)
|
|
{
|
|
return _EmployerRepository.GetEmployerByContracrtingPartyID(id);
|
|
}
|
|
|
|
public List<EmprViewModel> GetEmployerByEmployerIds(List<long> employerIds)
|
|
{
|
|
return _EmployerRepository.GetEmployerByEmployerIds(employerIds);
|
|
}
|
|
|
|
public OperationResult CreateForClient(CreateEmployer command)
|
|
{
|
|
var opration = new OperationResult();
|
|
if (_EmployerRepository.Exists(x => x.Nationalcode == command.Nationalcode && x.Nationalcode != null))
|
|
{
|
|
if (_EmployerRepository.ExistsEmployerAccount(command.Nationalcode))
|
|
return opration.Failed("امکان ثبت رکورد تکراری وجود ندارد");
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(command.FName))
|
|
return opration.Failed("لطفا نام را وارد کنید");
|
|
if (!string.IsNullOrWhiteSpace(command.Nationalcode))
|
|
{
|
|
try
|
|
{
|
|
char[] chArray = command.Nationalcode.ToCharArray();
|
|
int[] numArray = new int[chArray.Length];
|
|
var cunt = chArray.Length;
|
|
for (int i = 0; i < chArray.Length; i++)
|
|
{
|
|
numArray[i] = (int)char.GetNumericValue(chArray[i]);
|
|
}
|
|
|
|
int num2 = numArray[9];
|
|
switch (command.Nationalcode)
|
|
{
|
|
case "0000000000":
|
|
case "1111111111":
|
|
case "22222222222":
|
|
case "33333333333":
|
|
case "4444444444":
|
|
case "5555555555":
|
|
case "6666666666":
|
|
case "7777777777":
|
|
case "8888888888":
|
|
case "9999999999":
|
|
|
|
nationalCodValid = false;
|
|
return opration.Failed("کد ملی وارد شده صحیح نمی باشد");
|
|
}
|
|
|
|
int num3 =
|
|
((((((((numArray[0] * 10) + (numArray[1] * 9)) + (numArray[2] * 8)) + (numArray[3] * 7)) +
|
|
(numArray[4] * 6)) + (numArray[5] * 5)) + (numArray[6] * 4)) + (numArray[7] * 3)) +
|
|
(numArray[8] * 2);
|
|
int num4 = num3 - ((num3 / 11) * 11);
|
|
if ((((num4 == 0) && (num2 == num4)) || ((num4 == 1) && (num2 == 1))) ||
|
|
((num4 > 1) && (num2 == Math.Abs((int)(num4 - 11)))) && cunt <= 10)
|
|
{
|
|
nationalCodValid = true;
|
|
}
|
|
else
|
|
{
|
|
nationalCodValid = false;
|
|
return opration.Failed("کد ملی وارد شده نا معتبر است");
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
nationalCodValid = false;
|
|
return opration.Failed("لطفا کد ملی 10 رقمی وارد کنید");
|
|
}
|
|
}
|
|
|
|
|
|
string initial = "1300/10/11";
|
|
var dateOfBirth = command.DateOfBirth != null
|
|
? command.DateOfBirth.ToGeorgianDateTime()
|
|
: initial.ToGeorgianDateTime();
|
|
var dateOfIssue = command.DateOfIssue != null
|
|
? command.DateOfIssue.ToGeorgianDateTime()
|
|
: initial.ToGeorgianDateTime();
|
|
var employerData = new Employer(command.FName, command.LName, command.ContractingPartyId, command.Gender,
|
|
command.Nationalcode, command.IdNumber, command.Nationality, command.FatherName, dateOfBirth,
|
|
dateOfIssue, command.PlaceOfIssue, "*", "*", "*", "حقیقی", command.Phone,
|
|
command.AgentPhone, "true", command.MclsUserName, command.MclsPassword, command.EserviceUserName,
|
|
command.EservicePassword,
|
|
command.TaxOfficeUserName, command.TaxOfficepassword, command.SanaUserName, command.SanaPassword);
|
|
|
|
|
|
bool result = _EmployerRepository.CreateForClient(employerData);
|
|
// _EmployerRepository.SaveChanges();
|
|
if (result)
|
|
return opration.Succcedded();
|
|
else
|
|
return opration.Failed("ثبت با خطا مواجه شد!");
|
|
}
|
|
|
|
public List<EmployerViewModel> SearchForClient(EmployerSearchModel searchModel)
|
|
{
|
|
return _EmployerRepository.SearchForClient(searchModel);
|
|
}
|
|
|
|
public List<EmployerViewModel> GetEmployersForClient(long acountID)
|
|
{
|
|
return _EmployerRepository.GetEmployersForClient(acountID);
|
|
}
|
|
|
|
public OperationResult CreateLegalsForClient(CreateEmployer command)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(command.EmployerLName))
|
|
command.EmployerLName = "#";
|
|
var opration = new OperationResult();
|
|
|
|
|
|
if (_EmployerRepository.Exists(x => x.NationalId == command.NationalId && x.NationalId != null))
|
|
{
|
|
if (_EmployerRepository.ExistsEmployerAccountNationalId(command.NationalId))
|
|
return opration.Failed(" شناسه ملی وارد شده تکراری است");
|
|
}
|
|
|
|
if (_EmployerRepository.Exists(x => x.LName == command.LName))
|
|
{
|
|
if (_EmployerRepository.ExistsEmployerAccountLName(command.LName))
|
|
{
|
|
nameIsOk = false;
|
|
return opration.Failed("نام شرکت وارد شده تکراری است");
|
|
}
|
|
}
|
|
|
|
if (_EmployerRepository.Exists(x => x.RegisterId == command.RegisterId && x.RegisterId != null))
|
|
{
|
|
if (_EmployerRepository.ExistsEmployerAccountRegisterId(command.RegisterId))
|
|
{
|
|
registerIdIsOk = false;
|
|
return opration.Failed(" شماره ثبت وارد شده تکراری است");
|
|
}
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(command.Nationalcode))
|
|
{
|
|
try
|
|
{
|
|
char[] chArray = command.Nationalcode.ToCharArray();
|
|
int[] numArray = new int[chArray.Length];
|
|
var cunt = chArray.Length;
|
|
for (int i = 0; i < chArray.Length; i++)
|
|
{
|
|
numArray[i] = (int)char.GetNumericValue(chArray[i]);
|
|
}
|
|
|
|
int num2 = numArray[9];
|
|
switch (command.Nationalcode)
|
|
{
|
|
case "0000000000":
|
|
case "1111111111":
|
|
case "22222222222":
|
|
case "33333333333":
|
|
case "4444444444":
|
|
case "5555555555":
|
|
case "6666666666":
|
|
case "7777777777":
|
|
case "8888888888":
|
|
case "9999999999":
|
|
|
|
|
|
nationalCodValid = false;
|
|
return opration.Failed("کد ملی وارد شده صحیح نمی باشد");
|
|
}
|
|
|
|
int num3 =
|
|
((((((((numArray[0] * 10) + (numArray[1] * 9)) + (numArray[2] * 8)) + (numArray[3] * 7)) +
|
|
(numArray[4] * 6)) + (numArray[5] * 5)) + (numArray[6] * 4)) + (numArray[7] * 3)) +
|
|
(numArray[8] * 2);
|
|
int num4 = num3 - ((num3 / 11) * 11);
|
|
if ((((num4 == 0) && (num2 == num4)) || ((num4 == 1) && (num2 == 1))) ||
|
|
((num4 > 1) && (num2 == Math.Abs((int)(num4 - 11)))) && cunt <= 10)
|
|
{
|
|
nationalCodValid = true;
|
|
}
|
|
else
|
|
{
|
|
nationalCodValid = false;
|
|
return opration.Failed("کد ملی وارد شده نا معتبر است");
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
nationalCodValid = false;
|
|
return opration.Failed("لطفا کد ملی 10 رقمی وارد کنید");
|
|
}
|
|
//if (_EmployerRepository.Exists(x => x.Nationalcode == command.Nationalcode))
|
|
//{
|
|
// nationalcodeIsOk = false;
|
|
|
|
// return opration.Failed(" کد ملی وارد شده تکراری است");
|
|
//}
|
|
}
|
|
|
|
|
|
string initial = "1300/10/11";
|
|
var dateOfBirth = command.DateOfBirth != null
|
|
? command.DateOfBirth.ToGeorgianDateTime()
|
|
: initial.ToGeorgianDateTime();
|
|
var dateOfIssue = command.DateOfIssue != null
|
|
? command.DateOfIssue.ToGeorgianDateTime()
|
|
: initial.ToGeorgianDateTime();
|
|
var LegalEmployerData = new Employer(command.FName, command.LName, command.ContractingPartyId, command.Gender,
|
|
command.Nationalcode, command.IdNumber, command.Nationality, command.FatherName, dateOfBirth,
|
|
dateOfIssue, command.PlaceOfIssue, command.RegisterId, command.NationalId, command.EmployerLName, "حقوقی",
|
|
command.Phone,
|
|
command.AgentPhone, "true", command.MclsUserName, command.MclsPassword, command.EserviceUserName,
|
|
command.EservicePassword,
|
|
command.TaxOfficeUserName, command.TaxOfficepassword, command.SanaUserName, command.SanaPassword);
|
|
|
|
|
|
//_EmployerRepository.Create(LegalEmployerData);
|
|
//_EmployerRepository.SaveChanges();
|
|
bool result = _EmployerRepository.CreateLegalsForClient(LegalEmployerData);
|
|
if (result)
|
|
return opration.Succcedded();
|
|
else
|
|
return opration.Failed("ثبت با خطا مواجه شد!");
|
|
}
|
|
|
|
public OperationResult EditForClient(EditEmployer command)
|
|
{
|
|
var opration = new OperationResult();
|
|
var employer = _EmployerRepository.Get(command.Id);
|
|
if (employer == null)
|
|
return opration.Failed("رکورد مورد نظر یافت نشد");
|
|
|
|
if (_EmployerRepository.Exists(x =>
|
|
x.LName == command.LName && x.Nationalcode == command.Nationalcode && x.id != command.Id))
|
|
{
|
|
if (_EmployerRepository.ExistsEmployerAccountById(command.Nationalcode, command.Id))
|
|
return opration.Failed("امکان ثبت رکورد تکراری وجود ندارد");
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(command.Nationalcode))
|
|
{
|
|
try
|
|
{
|
|
char[] chArray = command.Nationalcode.ToCharArray();
|
|
int[] numArray = new int[chArray.Length];
|
|
var cunt = chArray.Length;
|
|
for (int i = 0; i < chArray.Length; i++)
|
|
{
|
|
numArray[i] = (int)char.GetNumericValue(chArray[i]);
|
|
}
|
|
|
|
int num2 = numArray[9];
|
|
switch (command.Nationalcode)
|
|
{
|
|
case "0000000000":
|
|
case "1111111111":
|
|
case "22222222222":
|
|
case "33333333333":
|
|
case "4444444444":
|
|
case "5555555555":
|
|
case "6666666666":
|
|
case "7777777777":
|
|
case "8888888888":
|
|
case "9999999999":
|
|
nationalCodValid = false;
|
|
return opration.Failed("کد ملی وارد شده صحیح نمی باشد");
|
|
}
|
|
|
|
int num3 =
|
|
((((((((numArray[0] * 10) + (numArray[1] * 9)) + (numArray[2] * 8)) + (numArray[3] * 7)) +
|
|
(numArray[4] * 6)) + (numArray[5] * 5)) + (numArray[6] * 4)) + (numArray[7] * 3)) +
|
|
(numArray[8] * 2);
|
|
int num4 = num3 - ((num3 / 11) * 11);
|
|
if ((((num4 == 0) && (num2 == num4)) || ((num4 == 1) && (num2 == 1))) ||
|
|
((num4 > 1) && (num2 == Math.Abs((int)(num4 - 11)))) && cunt <= 10)
|
|
{
|
|
nationalCodValid = true;
|
|
}
|
|
else
|
|
{
|
|
nationalCodValid = false;
|
|
return opration.Failed("کد ملی وارد شده نا معتبر است");
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
nationalCodValid = false;
|
|
return opration.Failed("لطفا کد ملی 10 رقمی وارد کنید");
|
|
}
|
|
|
|
if (_EmployerRepository.Exists(x =>
|
|
x.Nationalcode == command.Nationalcode && !string.IsNullOrWhiteSpace(command.Nationalcode) &&
|
|
x.id != command.Id))
|
|
{
|
|
nationalcodeIsOk = false;
|
|
|
|
return opration.Failed(" کد ملی وارد شده تکراری است");
|
|
}
|
|
}
|
|
|
|
|
|
string initial = "1300/10/11";
|
|
var dateOfBirth = command.DateOfBirth != null
|
|
? command.DateOfBirth.ToGeorgianDateTime()
|
|
: initial.ToGeorgianDateTime();
|
|
var dateOfIssue = command.DateOfIssue != null
|
|
? command.DateOfIssue.ToGeorgianDateTime()
|
|
: initial.ToGeorgianDateTime();
|
|
employer.Edit(command.FName, command.LName, command.ContractingPartyId,
|
|
command.Gender, command.Nationalcode, command.IdNumber, command.Nationality, command.FatherName,
|
|
dateOfBirth, dateOfIssue, command.PlaceOfIssue, command.Phone, command.AgentPhone,
|
|
command.MclsUserName, command.MclsPassword, command.EserviceUserName, command.EservicePassword,
|
|
command.TaxOfficeUserName, command.TaxOfficepassword, command.SanaUserName, command.SanaPassword,
|
|
command.EmployerNo);
|
|
|
|
_EmployerRepository.SaveChanges();
|
|
return opration.Succcedded();
|
|
}
|
|
|
|
public OperationResult EditLegalForClient(EditEmployer command)
|
|
{
|
|
var opration = new OperationResult();
|
|
var legalEmployer = _EmployerRepository.Get(command.Id);
|
|
if (legalEmployer == null)
|
|
return opration.Failed("رکورد مورد نظر یافت نشد");
|
|
|
|
if (_EmployerRepository.Exists(x =>
|
|
x.LName == command.LName && x.NationalId == command.NationalId && x.id != command.Id))
|
|
{
|
|
if (_EmployerRepository.ExistsEmployerAccountNationalIdEmployerId(command.Nationalcode, command.Id))
|
|
return opration.Failed("امکان ثبت رکورد تکراری وجود ندارد");
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(command.Nationalcode))
|
|
{
|
|
try
|
|
{
|
|
char[] chArray = command.Nationalcode.ToCharArray();
|
|
int[] numArray = new int[chArray.Length];
|
|
var cunt = chArray.Length;
|
|
for (int i = 0; i < chArray.Length; i++)
|
|
{
|
|
numArray[i] = (int)char.GetNumericValue(chArray[i]);
|
|
}
|
|
|
|
int num2 = numArray[9];
|
|
switch (command.Nationalcode)
|
|
{
|
|
case "0000000000":
|
|
case "1111111111":
|
|
case "22222222222":
|
|
case "33333333333":
|
|
case "4444444444":
|
|
case "5555555555":
|
|
case "6666666666":
|
|
case "7777777777":
|
|
case "8888888888":
|
|
case "9999999999":
|
|
|
|
|
|
nationalCodValid = false;
|
|
return opration.Failed("کد ملی وارد شده صحیح نمی باشد");
|
|
}
|
|
|
|
int num3 =
|
|
((((((((numArray[0] * 10) + (numArray[1] * 9)) + (numArray[2] * 8)) + (numArray[3] * 7)) +
|
|
(numArray[4] * 6)) + (numArray[5] * 5)) + (numArray[6] * 4)) + (numArray[7] * 3)) +
|
|
(numArray[8] * 2);
|
|
int num4 = num3 - ((num3 / 11) * 11);
|
|
if ((((num4 == 0) && (num2 == num4)) || ((num4 == 1) && (num2 == 1))) ||
|
|
((num4 > 1) && (num2 == Math.Abs((int)(num4 - 11)))) && cunt <= 10)
|
|
{
|
|
nationalCodValid = true;
|
|
}
|
|
else
|
|
{
|
|
nationalCodValid = false;
|
|
return opration.Failed("کد ملی وارد شده نا معتبر است");
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
nationalCodValid = false;
|
|
return opration.Failed("لطفا کد ملی 10 رقمی وارد کنید");
|
|
}
|
|
//if (_EmployerRepository.Exists(x => x.Nationalcode == command.Nationalcode && x.id != command.Id))
|
|
//{
|
|
// nationalcodeIsOk = false;
|
|
|
|
// return opration.Failed(" کد ملی وارد شده تکراری است");
|
|
//}
|
|
}
|
|
|
|
string initial = "1300/10/11";
|
|
var dateOfBirth = command.DateOfBirth != null
|
|
? command.DateOfBirth.ToGeorgianDateTime()
|
|
: initial.ToGeorgianDateTime();
|
|
var dateOfIssue = command.DateOfIssue != null
|
|
? command.DateOfIssue.ToGeorgianDateTime()
|
|
: initial.ToGeorgianDateTime();
|
|
legalEmployer.EditLegal(command.FName, command.LName, command.ContractingPartyId, command.Gender,
|
|
command.Nationalcode, command.IdNumber, command.Nationality, command.FatherName, dateOfBirth,
|
|
dateOfIssue, command.PlaceOfIssue, command.RegisterId, command.NationalId, command.EmployerLName,
|
|
command.Phone, command.AgentPhone, command.MclsUserName, command.MclsPassword, command.EserviceUserName,
|
|
command.EservicePassword,
|
|
command.TaxOfficeUserName, command.TaxOfficepassword, command.SanaUserName, command.SanaPassword,
|
|
command.EmployerNo);
|
|
|
|
_EmployerRepository.SaveChanges();
|
|
return opration.Succcedded();
|
|
}
|
|
|
|
#region Mahan
|
|
|
|
public List<EmployerViewModel> GetEmployersHasWorkshop()
|
|
{
|
|
return _EmployerRepository.GetEmployersHasWorkshop();
|
|
}
|
|
|
|
//public async Task<List<EmployerSelectListViewModel>> GetSelectList(string search)
|
|
//{
|
|
// return await _EmployerRepository.GetSelectList(search);
|
|
//}
|
|
|
|
#endregion
|
|
|
|
#region NewByHeydari
|
|
|
|
public OperationResult DeleteEmployer(long id)
|
|
{
|
|
var opration = new OperationResult();
|
|
var ids = new List<long>();
|
|
ids.Add(id);
|
|
var workshops = _workshopRepository.GetWorkshopsByEmployerId(ids);
|
|
|
|
if (workshops != null && workshops.Count > 0)
|
|
{
|
|
return _EmployerRepository.DeActiveAll(id);
|
|
}
|
|
else
|
|
{
|
|
opration = _EmployerRepository.DeleteEmployer(id);
|
|
}
|
|
|
|
return opration;
|
|
}
|
|
|
|
public List<EmployerViewModel> GetEmployerWithFNameOrLName(string searchText)
|
|
{
|
|
return _EmployerRepository.GetEmployerWithFNameOrLName(searchText);
|
|
}
|
|
|
|
public List<EmployerViewModel> GetEmployerWithIdNumberOrRegisterId(string searchText)
|
|
{
|
|
return _EmployerRepository.GetEmployerWithIdNumberOrRegisterId(searchText);
|
|
}
|
|
|
|
public List<EmployerViewModel> GetEmployerWithNationalcodeOrNationalId(string searchText)
|
|
{
|
|
return _EmployerRepository.GetEmployerWithNationalcodeOrNationalId(searchText);
|
|
}
|
|
|
|
public OperationResult ActiveAll(long id)
|
|
{
|
|
return _EmployerRepository.ActiveAll(id);
|
|
}
|
|
|
|
public List<EmployerViewModel> GetAllEmployers()
|
|
{
|
|
return _EmployerRepository.GetAllEmployers();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Insurance
|
|
|
|
public (string employerName, bool isLegal) InsuranceEmployerByWorkshopId(long workshopId)
|
|
{
|
|
return _EmployerRepository.InsuranceEmployerByWorkshopId(workshopId);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Api
|
|
|
|
public async Task<List<GetEmployerListViewModel>> GetEmployerList(GetEmployerSearchModel searchModel)
|
|
{
|
|
return await _EmployerRepository.GetEmployerList(searchModel);
|
|
}
|
|
|
|
public async Task<GetLegalEmployerDetailViewModel> GetLegalEmployerDetail(long id)
|
|
{
|
|
var employer = await _EmployerRepository.GetLegalEmployerDetail(id);
|
|
if (employer == null)
|
|
{
|
|
throw new NotFoundException("کارفرمای مورد نطر یافت نشد");
|
|
}
|
|
|
|
return employer;
|
|
}
|
|
|
|
public async Task<GetRealEmployerDetailViewModel> GetRealEmployerDetail(long id)
|
|
{
|
|
var employer = await _EmployerRepository.GetRealEmployerDetail(id);
|
|
if (employer == null)
|
|
{
|
|
throw new NotFoundException("کارفرمای مورد نطر یافت نشد");
|
|
}
|
|
|
|
return employer;
|
|
}
|
|
|
|
public async Task<OperationResult> CreateReal(CreateRealEmployer command)
|
|
{
|
|
var opration = new OperationResult();
|
|
if (_EmployerRepository.Exists(x =>
|
|
(x.FName == command.FName && x.LName == command.LName) && x.Nationalcode == command.NationalCode &&
|
|
x.Nationalcode != null))
|
|
return opration.Failed("امکان ثبت رکورد تکراری وجود ندارد");
|
|
|
|
if (string.IsNullOrWhiteSpace(command.FName))
|
|
return opration.Failed("لطفا نام را وارد کنید");
|
|
|
|
if (!string.IsNullOrWhiteSpace(command.NationalCode))
|
|
{
|
|
if (command.NationalCode.NationalCodeValid() != "valid")
|
|
{
|
|
return opration.Failed("کدملی وارد شده نامعتبر است");
|
|
}
|
|
|
|
if (_EmployerRepository.Exists(x =>
|
|
x.Nationalcode == command.NationalCode && !string.IsNullOrWhiteSpace(command.NationalCode)))
|
|
{
|
|
return opration.Failed("کد ملی وارد شده تکراری است");
|
|
}
|
|
}
|
|
|
|
string initial = "1300/10/11";
|
|
var dateOfBirth = command.DateOfBirth?.ToGeorgianDateTime() ?? initial.ToGeorgianDateTime();
|
|
var dateOfIssue = command.DateOfIssue?.ToGeorgianDateTime() ?? initial.ToGeorgianDateTime();
|
|
|
|
var gender = command.Gender switch
|
|
{
|
|
Gender.Male => "مرد",
|
|
Gender.Female => "زن",
|
|
Gender.None => null,
|
|
_ => throw new BadRequestException("جنسیت وارد شده نامعتبر است")
|
|
};
|
|
|
|
var employerData = new Employer(command.FName, command.LName, command.ContractingPartyId, gender,
|
|
command.NationalCode, command.IdNumber, "ایرانی", command.FatherName, dateOfBirth,
|
|
dateOfIssue, command.PlaceOfIssue, "*", "*", "*", "حقیقی", command.PhoneNumber,
|
|
command.Telephone, "true", command.GovernmentSystemInfo.MclUsername,
|
|
command.GovernmentSystemInfo.MclPassword, command.GovernmentSystemInfo.EServiceUsername,
|
|
command.GovernmentSystemInfo.EServicePassword,
|
|
command.GovernmentSystemInfo.TaxUsername, command.GovernmentSystemInfo.TaxPassword,
|
|
command.GovernmentSystemInfo.SanaUsername, command.GovernmentSystemInfo.SanaPassword);
|
|
|
|
await _EmployerRepository.CreateAsync(employerData);
|
|
await _EmployerRepository.SaveChangesAsync();
|
|
|
|
return opration.Succcedded();
|
|
}
|
|
|
|
public async Task<OperationResult> CreateLegal(CreateLegalEmployer command)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(command.EmployerLName))
|
|
command.EmployerLName = "#";
|
|
var opration = new OperationResult();
|
|
if (_EmployerRepository.Exists(x =>
|
|
x.LName == command.CompanyName && x.NationalId == command.NationalId &&
|
|
x.EmployerLName == command.EmployerLName))
|
|
return opration.Failed("امکان ثبت رکورد تکراری وجود ندارد");
|
|
|
|
if (_EmployerRepository.Exists(x =>
|
|
x.NationalId == command.NationalId && !string.IsNullOrWhiteSpace(command.NationalId) &&
|
|
x.NationalId != null))
|
|
{
|
|
return opration.Failed(" شناسه ملی وارد شده تکراری است");
|
|
}
|
|
|
|
if (_EmployerRepository.Exists(x => x.LName == command.CompanyName))
|
|
{
|
|
return opration.Failed("نام شرکت وارد شده تکراری است");
|
|
}
|
|
|
|
if (_EmployerRepository.Exists(x =>
|
|
x.RegisterId == command.RegisterId && !string.IsNullOrWhiteSpace(command.RegisterId) &&
|
|
x.RegisterId != null))
|
|
{
|
|
return opration.Failed(" شماره ثبت وارد شده تکراری است");
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(command.NationalId) && command.NationalId.Length != 11)
|
|
{
|
|
return opration.Failed(" شناسه ملی باید 11 رقم باشد");
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(command.EmployerNationalCode))
|
|
{
|
|
if (command.EmployerNationalCode.NationalCodeValid() != "valid")
|
|
{
|
|
return opration.Failed("کد ملی وارد شده نا معتبر است");
|
|
}
|
|
}
|
|
|
|
string initial = "1300/10/11";
|
|
var dateOfBirth = command.EmployerDateOfBirth?.ToGeorgianDateTime() ?? initial.ToGeorgianDateTime();
|
|
var dateOfIssue = command.EmployerDateOfIssue?.ToGeorgianDateTime() ?? initial.ToGeorgianDateTime();
|
|
|
|
var gender = command.EmployerGender switch
|
|
{
|
|
Gender.Male => "مرد",
|
|
Gender.Female => "زن",
|
|
Gender.None => null,
|
|
_ => throw new BadRequestException("جنسیت وارد شده نامعتبر است")
|
|
};
|
|
|
|
|
|
var legalEmployerData = new Employer(command.EmployerFName, command.CompanyName, command.ContractingPartyId,
|
|
gender,
|
|
command.EmployerNationalCode, command.EmployerIdNumber, "ایرانی", command.EmployerFatherName, dateOfBirth,
|
|
dateOfIssue, command.EmployerPlaceOfIssue, command.RegisterId, command.NationalId, command.EmployerLName,
|
|
"حقوقی", command.PhoneNumber,
|
|
command.TelephoneNumber, "true", command.GovernmentSystemInfo.MclUsername,
|
|
command.GovernmentSystemInfo.MclPassword,
|
|
command.GovernmentSystemInfo.EServiceUsername, command.GovernmentSystemInfo.EServicePassword,
|
|
command.GovernmentSystemInfo.TaxUsername, command.GovernmentSystemInfo.TaxPassword,
|
|
command.GovernmentSystemInfo.SanaUsername, command.GovernmentSystemInfo.SanaPassword);
|
|
|
|
await _EmployerRepository.CreateAsync(legalEmployerData);
|
|
await _EmployerRepository.SaveChangesAsync();
|
|
|
|
return opration.Succcedded();
|
|
}
|
|
|
|
public async Task<OperationResult> EditReal(EditRealEmployer command)
|
|
{
|
|
var opration = new OperationResult();
|
|
var employer = _EmployerRepository.Get(command.Id);
|
|
if (employer == null)
|
|
return opration.Failed("رکورد مورد نظر یافت نشد");
|
|
|
|
if (_EmployerRepository.Exists(x =>
|
|
(x.FName == command.FName && x.LName == command.LName) && x.Nationalcode == command.NationalCode &&
|
|
x.id != command.Id))
|
|
return opration.Failed("امکان ثبت رکورد تکراری وجود ندارد");
|
|
if (!string.IsNullOrWhiteSpace(command.NationalCode))
|
|
{
|
|
if (command.NationalCode.NationalCodeValid() != "valid")
|
|
{
|
|
return opration.Failed("کد ملی وارد شده نا معتبر است");
|
|
}
|
|
}
|
|
|
|
if (_EmployerRepository.Exists(x =>
|
|
x.Nationalcode == command.NationalCode && !string.IsNullOrWhiteSpace(command.NationalCode) &&
|
|
x.id != command.Id))
|
|
{
|
|
return opration.Failed(" کد ملی وارد شده تکراری است");
|
|
}
|
|
|
|
|
|
string initial = "1300/10/11";
|
|
|
|
var dateOfBirth = command.DateOfBirth?.ToGeorgianDateTime() ?? initial.ToGeorgianDateTime();
|
|
var dateOfIssue = command.DateOfIssue?.ToGeorgianDateTime() ?? initial.ToGeorgianDateTime();
|
|
|
|
var gender = command.Gender switch
|
|
{
|
|
Gender.Male => "مرد",
|
|
Gender.Female => "زن",
|
|
Gender.None => null,
|
|
_ => throw new BadRequestException("جنسیت وارد شده نامعتبر است")
|
|
};
|
|
|
|
employer.Edit(command.FName, command.LName, command.ContractingPartyId,
|
|
gender, command.NationalCode, command.IdNumber, "ایرانی", command.FatherName,
|
|
dateOfBirth, dateOfIssue, command.PlaceOfIssue, command.PhoneNumber, command.Telephone,
|
|
command.GovernmentSystemInfo.MclUsername, command.GovernmentSystemInfo.MclPassword,
|
|
command.GovernmentSystemInfo.EServiceUsername, command.GovernmentSystemInfo.EServicePassword,
|
|
command.GovernmentSystemInfo.TaxUsername, command.GovernmentSystemInfo.TaxPassword,
|
|
command.GovernmentSystemInfo.SanaUsername, command.GovernmentSystemInfo.SanaPassword, null);
|
|
|
|
await _EmployerRepository.SaveChangesAsync();
|
|
return opration.Succcedded();
|
|
}
|
|
|
|
public async Task<OperationResult> EditLegal(EditLegalEmployer command)
|
|
{
|
|
var opration = new OperationResult();
|
|
var legalEmployer = _EmployerRepository.Get(command.Id);
|
|
if (legalEmployer == null)
|
|
return opration.Failed("رکورد مورد نظر یافت نشد");
|
|
|
|
if (_EmployerRepository.Exists(x =>
|
|
x.LName == command.CompanyName && x.NationalId == command.NationalId &&
|
|
!string.IsNullOrWhiteSpace(command.NationalId) && x.id != command.Id))
|
|
return opration.Failed("امکان ثبت رکورد تکراری وجود ندارد");
|
|
|
|
|
|
if (!string.IsNullOrEmpty(command.NationalId) && command.NationalId.Length != 11)
|
|
{
|
|
return opration.Failed(" شناسه ملی باید 11 رقم باشد");
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(command.EmployerNationalCode))
|
|
{
|
|
if (command.EmployerNationalCode.NationalCodeValid() != "valid")
|
|
{
|
|
return opration.Failed("کد ملی وارد شده نا معتبر است");
|
|
}
|
|
}
|
|
|
|
var gender = command.EmployerGender switch
|
|
{
|
|
Gender.Male => "مرد",
|
|
Gender.Female => "زن",
|
|
Gender.None => null,
|
|
_ => throw new BadRequestException("جنسیت وارد شده نامعتبر است")
|
|
};
|
|
|
|
string initial = "1300/10/11";
|
|
var dateOfBirth = command.EmployerDateOfBirth?.ToGeorgianDateTime() ?? initial.ToGeorgianDateTime();
|
|
var dateOfIssue = command.EmployerDateOfIssue?.ToGeorgianDateTime() ?? initial.ToGeorgianDateTime();
|
|
legalEmployer.EditLegal(command.EmployerFName, command.CompanyName, command.ContractingPartyId, gender,
|
|
command.EmployerNationalCode, command.EmployerIdNumber, "ایرانی", command.EmployerFatherName, dateOfBirth,
|
|
dateOfIssue, command.EmployerPlaceOfIssue, command.RegisterId, command.NationalId, command.EmployerLName,
|
|
command.PhoneNumber, command.TelephoneNumber, command.GovernmentSystemInfo.MclUsername,
|
|
command.GovernmentSystemInfo.MclUsername, command.GovernmentSystemInfo.EServiceUsername,
|
|
command.GovernmentSystemInfo.EServicePassword,
|
|
command.GovernmentSystemInfo.TaxUsername, command.GovernmentSystemInfo.TaxPassword,
|
|
command.GovernmentSystemInfo.SanaUsername, command.GovernmentSystemInfo.SanaPassword, null);
|
|
|
|
await _EmployerRepository.SaveChangesAsync();
|
|
return opration.Succcedded();
|
|
}
|
|
|
|
public async Task<List<EmployerSelectListViewModel>> GetSelectList(string search, long id)
|
|
{
|
|
return await _EmployerRepository.GetSelectList(search, id);
|
|
}
|
|
|
|
async Task<OperationResult<string>> IEmployerApplication.Remove(long id)
|
|
{
|
|
var employer = _EmployerRepository.Get(id);
|
|
if (employer == null)
|
|
throw new NotFoundException("دیتای مورد نظر یافت نشد");
|
|
|
|
var workshops = _workshopRepository.GetWorkshopsByEmployerId([id]);
|
|
|
|
if (workshops.Any())
|
|
{
|
|
return await _EmployerRepository.DeactivateWithSubordinates(id);
|
|
}
|
|
|
|
_EmployerRepository.Remove(id);
|
|
|
|
return new OperationResult<string>().Succcedded("Deleted");
|
|
}
|
|
|
|
public async Task<OperationResult> CreateWorkflowRegistration(CreateEmployerWorkflowRegistration command)
|
|
{
|
|
var operation = new OperationResult();
|
|
|
|
OperationResult<Employer> createEmployerResult = command.LegalType switch
|
|
{
|
|
LegalType.Real => await CreateRealEmployerRegistration(command.RealEmployer, command.ContractingPartyId),
|
|
LegalType.Legal => await CreateLegalEmployerRegistration(command.LegalEmployer, command.ContractingPartyId),
|
|
_ => throw new ArgumentOutOfRangeException()
|
|
};
|
|
var employer = createEmployerResult.Data;
|
|
|
|
if (!createEmployerResult.IsSuccedded)
|
|
return operation.Failed(createEmployerResult.Message);
|
|
|
|
var workshopDetails =
|
|
await _institutionContractRepository.GetInstitutionWorkshopDetails(command.InstitutionWorkshopDetailsId);
|
|
workshopDetails.AddEmployer(employer.id);
|
|
|
|
await _institutionContractRepository.SaveChangesAsync();
|
|
return operation.Succcedded();
|
|
}
|
|
|
|
public async Task<OperationResult> EditWorkflowRegistration(EditEmployerWorkflowRegistration command)
|
|
{
|
|
var operation = new OperationResult();
|
|
|
|
// Get the existing employer
|
|
var employer = _EmployerRepository.Get(command.EmployerId);
|
|
if (employer == null)
|
|
return operation.Failed("کارفرمای مورد نظر یافت نشد");
|
|
|
|
OperationResult editEmployerResult = command.LegalType switch
|
|
{
|
|
LegalType.Real => await EditRealEmployerRegistration(command.RealEmployer, command.EmployerId),
|
|
LegalType.Legal => await EditLegalEmployerRegistration(command.LegalEmployer, command.EmployerId),
|
|
_ => throw new ArgumentOutOfRangeException()
|
|
};
|
|
|
|
if (!editEmployerResult.IsSuccedded)
|
|
return operation.Failed(editEmployerResult.Message);
|
|
|
|
await _institutionContractRepository.SaveChangesAsync();
|
|
return operation.Succcedded();
|
|
}
|
|
|
|
/// <summary>
|
|
/// حذف کارفرما از گردش کار ثبت نام
|
|
/// </summary>
|
|
/// <param name="employerId">شناسه کارفرما</param>
|
|
/// <param name="institutionWorkshopDetailsId">شناسه جزئیات کارگاه موسسه</param>
|
|
/// <returns></returns>
|
|
public async Task<OperationResult> DeleteWorkflowRegistration(long employerId, long institutionWorkshopDetailsId)
|
|
{
|
|
var operation = new OperationResult();
|
|
|
|
// Check if employer exists
|
|
var employer = _EmployerRepository.Get(employerId);
|
|
if (employer == null)
|
|
return operation.Failed("کارفرمای مورد نظر یافت نشد");
|
|
|
|
// Get workshop details
|
|
var workshopDetails = await _institutionContractRepository.GetInstitutionWorkshopDetails(institutionWorkshopDetailsId);
|
|
if (workshopDetails == null)
|
|
return operation.Failed("جزئیات کارگاه موسسه یافت نشد");
|
|
|
|
// Find and remove the employer from workshop details
|
|
var employerDetail = workshopDetails.Employers.FirstOrDefault(e => e.EmployerId == employerId);
|
|
if (employerDetail == null)
|
|
return operation.Failed("کارفرما در لیست کارگاه یافت نشد");
|
|
|
|
// Remove the employer from the list
|
|
workshopDetails.Employers.Remove(employerDetail);
|
|
|
|
await _institutionContractRepository.SaveChangesAsync();
|
|
|
|
// Delete the employer
|
|
_EmployerRepository.Remove(employerId);
|
|
await _EmployerRepository.SaveChangesAsync();
|
|
|
|
return operation.Succcedded();
|
|
}
|
|
|
|
public async Task<OperationResult<AuthenticateUserViewModel>> AuthenticateEmployer(string nationalCode,
|
|
string dateOfBirth,
|
|
string mobile)
|
|
{
|
|
var op = new OperationResult<AuthenticateUserViewModel>();
|
|
|
|
var dateOfBirthGr = dateOfBirth.ToGeorgianDateTime();
|
|
|
|
var isMachMobilAndNationalCode = await _uidService.IsMachPhoneWithNationalCode(nationalCode, mobile);
|
|
if (isMachMobilAndNationalCode == null)
|
|
return op.Failed("خطا در سرویس احراز هویت");
|
|
if (!isMachMobilAndNationalCode.IsMatched)
|
|
return op.Failed("شماره همراه وارد شده با کد ملی مطابقت ندارد");
|
|
var apiRespons = await _uidService.GetPersonalInfo(nationalCode, dateOfBirth);
|
|
|
|
if (apiRespons == null)
|
|
throw new InternalServerException("سیستم احراز هویت در دسترس نمی باشد");
|
|
|
|
if (apiRespons.ResponseContext.Status.Code ==14)
|
|
throw new InternalServerException("سیستم احراز هویت در دسترس نمی باشد");
|
|
|
|
if (apiRespons.ResponseContext.Status.Code != 0)
|
|
return op.Failed($"{apiRespons.ResponseContext.Status.Message}");
|
|
|
|
var idNumber = apiRespons.IdentificationInformation.ShenasnamehNumber == "0"
|
|
? apiRespons.IdentificationInformation.NationalId
|
|
: apiRespons.IdentificationInformation.ShenasnamehNumber;
|
|
|
|
var res = new AuthenticateUserViewModel()
|
|
{
|
|
DateOfBirth = dateOfBirth,
|
|
FatherName = apiRespons.BasicInformation.FatherName,
|
|
FName = apiRespons.BasicInformation.FirstName,
|
|
Gender = apiRespons.BasicInformation.GenderEnum,
|
|
IdNumber = apiRespons.IdentificationInformation.ShenasnamehNumber,
|
|
IdNumberSeri = apiRespons.IdentificationInformation.ShenasnameSeri,
|
|
IdNumberSerial = apiRespons.IdentificationInformation.ShenasnameSerial,
|
|
LName = apiRespons.BasicInformation.LastName,
|
|
NationalCode = nationalCode,
|
|
Phone = mobile,
|
|
};
|
|
return op.Succcedded(res);
|
|
}
|
|
|
|
private async Task<OperationResult<Employer>> CreateLegalEmployerRegistration(
|
|
CreateLegalEmployerWorkflowRegistration command, long contractingPartyId)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(command.CeoLName))
|
|
command.CeoLName = "#";
|
|
var opration = new OperationResult<Employer>();
|
|
if (_EmployerRepository.Exists(x =>
|
|
x.LName == command.CompanyName && x.NationalId == command.NationalId &&
|
|
x.EmployerLName == command.CeoLName))
|
|
return opration.Failed("امکان ثبت رکورد تکراری وجود ندارد");
|
|
|
|
if (_EmployerRepository.Exists(x =>
|
|
x.NationalId == command.NationalId && !string.IsNullOrWhiteSpace(command.NationalId) &&
|
|
x.NationalId != null))
|
|
{
|
|
return opration.Failed(" شناسه ملی وارد شده تکراری است");
|
|
}
|
|
|
|
if (_EmployerRepository.Exists(x => x.LName == command.CompanyName))
|
|
{
|
|
return opration.Failed("نام شرکت وارد شده تکراری است");
|
|
}
|
|
|
|
if (_EmployerRepository.Exists(x =>
|
|
x.RegisterId == command.RegisterId && !string.IsNullOrWhiteSpace(command.RegisterId) &&
|
|
x.RegisterId != null))
|
|
{
|
|
return opration.Failed(" شماره ثبت وارد شده تکراری است");
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(command.NationalId) && command.NationalId.Length != 11)
|
|
{
|
|
return opration.Failed(" شناسه ملی باید 11 رقم باشد");
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(command.CeoNationalCode))
|
|
{
|
|
if (command.CeoNationalCode.NationalCodeValid() != "valid")
|
|
{
|
|
return opration.Failed("کد ملی وارد شده نا معتبر است");
|
|
}
|
|
}
|
|
|
|
string initial = "1300/10/11";
|
|
var dateOfBirth = command.CeoDateOfBirth?.ToGeorgianDateTime() ?? initial.ToGeorgianDateTime();
|
|
var dateOfIssue = command.CeoDateOfBirth?.ToGeorgianDateTime() ?? initial.ToGeorgianDateTime();
|
|
|
|
var gender = command.Gender switch
|
|
{
|
|
Gender.Male => "مرد",
|
|
Gender.Female => "زن",
|
|
Gender.None => null,
|
|
_ => throw new BadRequestException("جنسیت وارد شده نامعتبر است")
|
|
};
|
|
|
|
|
|
var legalEmployerData = new Employer(command.CeoFName, command.CompanyName, contractingPartyId,
|
|
gender,
|
|
command.CeoNationalCode, command.CeoIdNumber, "ایرانی", command.CeoFatherName, dateOfBirth,
|
|
dateOfIssue, command.CeoPlaceOfIssue, command.RegisterId, command.NationalId, command.CeoLName,
|
|
"حقوقی", command.PhoneNumber,
|
|
command.TelephoneNumber, "true", command.GovernmentSystemInfo.MclUsername,
|
|
command.GovernmentSystemInfo.MclPassword,
|
|
command.GovernmentSystemInfo.EServiceUsername, command.GovernmentSystemInfo.EServicePassword,
|
|
command.GovernmentSystemInfo.TaxUsername, command.GovernmentSystemInfo.TaxPassword,
|
|
command.GovernmentSystemInfo.SanaUsername, command.GovernmentSystemInfo.SanaPassword);
|
|
|
|
await _EmployerRepository.CreateAsync(legalEmployerData);
|
|
await _EmployerRepository.SaveChangesAsync();
|
|
|
|
return opration.Succcedded(legalEmployerData);
|
|
}
|
|
|
|
private async Task<OperationResult<Employer>> CreateRealEmployerRegistration(
|
|
CreateRealEmployerWorkflowRegistration command, long contractingPartyId)
|
|
{
|
|
var opration = new OperationResult<Employer>();
|
|
if (_EmployerRepository.Exists(x =>
|
|
(x.FName == command.FName && x.LName == command.LName) && x.Nationalcode == command.NationalCode &&
|
|
x.Nationalcode != null))
|
|
return opration.Failed("امکان ثبت رکورد تکراری وجود ندارد");
|
|
|
|
if (string.IsNullOrWhiteSpace(command.FName))
|
|
return opration.Failed("لطفا نام را وارد کنید");
|
|
|
|
if (!string.IsNullOrWhiteSpace(command.NationalCode))
|
|
{
|
|
if (command.NationalCode.NationalCodeValid() != "valid")
|
|
{
|
|
return opration.Failed("کدملی وارد شده نامعتبر است");
|
|
}
|
|
|
|
if (_EmployerRepository.Exists(x =>
|
|
x.Nationalcode == command.NationalCode && !string.IsNullOrWhiteSpace(command.NationalCode)))
|
|
{
|
|
return opration.Failed("کد ملی وارد شده تکراری است");
|
|
}
|
|
}
|
|
|
|
string initial = "1300/10/11";
|
|
var dateOfBirth = command.DateOfBirth?.ToGeorgianDateTime() ?? initial.ToGeorgianDateTime();
|
|
var dateOfIssue = command.DateOfIssue?.ToGeorgianDateTime() ?? initial.ToGeorgianDateTime();
|
|
|
|
var gender = command.Gender switch
|
|
{
|
|
Gender.Male => "مرد",
|
|
Gender.Female => "زن",
|
|
Gender.None => null,
|
|
_ => throw new BadRequestException("جنسیت وارد شده نامعتبر است")
|
|
};
|
|
|
|
var employerData = new Employer(command.FName, command.LName, contractingPartyId, gender,
|
|
command.NationalCode, command.IdNumber, "ایرانی", command.FatherName, dateOfBirth,
|
|
dateOfIssue, command.PlaceOfIssue, "*", "*", "*", "حقیقی", command.PhoneNumber,
|
|
command.Telephone, "true", command.GovernmentSystemInfo.MclUsername,
|
|
command.GovernmentSystemInfo.MclPassword, command.GovernmentSystemInfo.EServiceUsername,
|
|
command.GovernmentSystemInfo.EServicePassword,
|
|
command.GovernmentSystemInfo.TaxUsername, command.GovernmentSystemInfo.TaxPassword,
|
|
command.GovernmentSystemInfo.SanaUsername, command.GovernmentSystemInfo.SanaPassword);
|
|
|
|
await _EmployerRepository.CreateAsync(employerData);
|
|
await _EmployerRepository.SaveChangesAsync();
|
|
|
|
return opration.Succcedded(employerData);
|
|
}
|
|
|
|
private async Task<OperationResult> EditRealEmployerRegistration(
|
|
CreateRealEmployerWorkflowRegistration command, long employerId)
|
|
{
|
|
var operation = new OperationResult();
|
|
var employer = _EmployerRepository.Get(employerId);
|
|
if (employer == null)
|
|
return operation.Failed("رکورد مورد نظر یافت نشد");
|
|
|
|
if (_EmployerRepository.Exists(x =>
|
|
(x.FName == command.FName && x.LName == command.LName) && x.Nationalcode == command.NationalCode &&
|
|
x.id != employerId))
|
|
return operation.Failed("امکان ثبت رکورد تکراری وجود ندارد");
|
|
|
|
if (!string.IsNullOrWhiteSpace(command.NationalCode))
|
|
{
|
|
if (command.NationalCode.NationalCodeValid() != "valid")
|
|
{
|
|
return operation.Failed("کد ملی وارد شده نا معتبر است");
|
|
}
|
|
}
|
|
|
|
if (_EmployerRepository.Exists(x =>
|
|
x.Nationalcode == command.NationalCode && !string.IsNullOrWhiteSpace(command.NationalCode) &&
|
|
x.id != employerId))
|
|
{
|
|
return operation.Failed(" کد ملی وارد شده تکراری است");
|
|
}
|
|
|
|
string initial = "1300/10/11";
|
|
var dateOfBirth = command.DateOfBirth?.ToGeorgianDateTime() ?? initial.ToGeorgianDateTime();
|
|
var dateOfIssue = command.DateOfIssue?.ToGeorgianDateTime() ?? initial.ToGeorgianDateTime();
|
|
|
|
var gender = command.Gender switch
|
|
{
|
|
Gender.Male => "مرد",
|
|
Gender.Female => "زن",
|
|
Gender.None => null,
|
|
_ => throw new BadRequestException("جنسیت وارد شده نامعتبر است")
|
|
};
|
|
|
|
employer.Edit(command.FName, command.LName, employer.ContractingPartyId,
|
|
gender, command.NationalCode, command.IdNumber, "ایرانی", command.FatherName,
|
|
dateOfBirth, dateOfIssue, command.PlaceOfIssue, command.PhoneNumber, command.Telephone,
|
|
command.GovernmentSystemInfo.MclUsername, command.GovernmentSystemInfo.MclPassword,
|
|
command.GovernmentSystemInfo.EServiceUsername, command.GovernmentSystemInfo.EServicePassword,
|
|
command.GovernmentSystemInfo.TaxUsername, command.GovernmentSystemInfo.TaxPassword,
|
|
command.GovernmentSystemInfo.SanaUsername, command.GovernmentSystemInfo.SanaPassword, null);
|
|
|
|
await _EmployerRepository.SaveChangesAsync();
|
|
return operation.Succcedded();
|
|
}
|
|
|
|
private async Task<OperationResult> EditLegalEmployerRegistration(
|
|
CreateLegalEmployerWorkflowRegistration command, long employerId)
|
|
{
|
|
var operation = new OperationResult();
|
|
var legalEmployer = _EmployerRepository.Get(employerId);
|
|
if (legalEmployer == null)
|
|
return operation.Failed("رکورد مورد نظر یافت نشد");
|
|
|
|
if (_EmployerRepository.Exists(x =>
|
|
x.LName == command.CompanyName && x.NationalId == command.NationalId &&
|
|
!string.IsNullOrWhiteSpace(command.NationalId) && x.id != employerId))
|
|
return operation.Failed("امکان ثبت رکورد تکراری وجود ندارد");
|
|
|
|
if (!string.IsNullOrEmpty(command.NationalId) && command.NationalId.Length != 11)
|
|
{
|
|
return operation.Failed(" شناسه ملی باید 11 رقم باشد");
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(command.CeoNationalCode))
|
|
{
|
|
if (command.CeoNationalCode.NationalCodeValid() != "valid")
|
|
{
|
|
return operation.Failed("کد ملی وارد شده نا معتبر است");
|
|
}
|
|
}
|
|
|
|
var gender = command.Gender switch
|
|
{
|
|
Gender.Male => "مرد",
|
|
Gender.Female => "زن",
|
|
Gender.None => null,
|
|
_ => throw new BadRequestException("جنسیت وارد شده نامعتبر است")
|
|
};
|
|
|
|
string initial = "1300/10/11";
|
|
var dateOfBirth = command.CeoDateOfBirth?.ToGeorgianDateTime() ?? initial.ToGeorgianDateTime();
|
|
var dateOfIssue = command.CeoDateOfIssue?.ToGeorgianDateTime() ?? initial.ToGeorgianDateTime();
|
|
|
|
legalEmployer.EditLegal(command.CeoFName, command.CompanyName, legalEmployer.ContractingPartyId, gender,
|
|
command.CeoNationalCode, command.CeoIdNumber, "ایرانی", command.CeoFatherName, dateOfBirth,
|
|
dateOfIssue, command.CeoPlaceOfIssue, command.RegisterId, command.NationalId, command.CeoLName,
|
|
command.PhoneNumber, command.TelephoneNumber, command.GovernmentSystemInfo.MclUsername,
|
|
command.GovernmentSystemInfo.MclPassword, command.GovernmentSystemInfo.EServiceUsername,
|
|
command.GovernmentSystemInfo.EServicePassword,
|
|
command.GovernmentSystemInfo.TaxUsername, command.GovernmentSystemInfo.TaxPassword,
|
|
command.GovernmentSystemInfo.SanaUsername, command.GovernmentSystemInfo.SanaPassword, null);
|
|
|
|
await _EmployerRepository.SaveChangesAsync();
|
|
return operation.Succcedded();
|
|
}
|
|
#endregion
|
|
} |