Files
Backend-Api/CompanyManagment.Application/FileEmployerApplication.cs
2024-07-05 21:36:15 +03:30

491 lines
18 KiB
C#

using System;
using System.Collections.Generic;
using _0_Framework.Application;
using Company.Domain.FileEmployerAgg;
using CompanyManagment.App.Contracts.FileEmployer;
using CompanyManagment.App.Contracts.Representative;
namespace CompanyManagment.Application;
public class FileEmployerApplication:IFileEmployerApplication
{
private readonly IFileEmployerRepository _fileEmployerRepository;
private readonly IRepresentativeApplication _representativeApplication;
public FileEmployerApplication(IFileEmployerRepository fileEmployerRepository, IRepresentativeApplication representativeApplication)
{
_fileEmployerRepository = fileEmployerRepository;
_representativeApplication = representativeApplication;
}
public OperationResult CreateReal(CreateFileEmployer command)
{
var nationalCode = string.Empty;
var opration = new OperationResult();
if (_fileEmployerRepository.Exists(x =>
x.LName == command.LName && x.FName == command.FName))
return opration.Failed("امکان ثبت رکورد تکراری وجود ندارد");
if (command.RepresentativeId == 0)
return opration.Failed("لطفا معرف را انتخاب کنبد");
if (string.IsNullOrWhiteSpace(command.FName) || string.IsNullOrWhiteSpace(command.LName))
return opration.Failed("وارد کردن نام و نام خانوادگی اجباری است");
if (!string.IsNullOrWhiteSpace(command.NationalCode))
{
if (_fileEmployerRepository.Exists(x => x.NationalCode == command.NationalCode))
{
return opration.Failed("کد ملی وارد شده تکراری است");
}
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":
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)
{
nationalCode = command.NationalCode;
}
else
{
return opration.Failed("کد ملی وارد شده نا معتبر است");
}
}
catch (Exception)
{
return opration.Failed("لطفا کد ملی 10 رقمی وارد کنید");
}
}
else
{
nationalCode = "";
}
string initial = "1300/10/11";
var dateOfBirth = command.DateOfBirth != null ? command.DateOfBirth.ToGeorgianDateTime() : initial.ToGeorgianDateTime();
var representative = _representativeApplication.GetDetails(command.RepresentativeId);
var employerData = new FileEmployer(command.FName, command.LName, "*", command.RepresentativeId,
representative.FullName, dateOfBirth,
command.InsuranceWorkshopCode, nationalCode, command.LevelOfEducation, command.FieldOfStudy,
command.IdNumber, command.Gender,
command.MaritalStatus, "*", "*", "false", command.Phone, command.OfficePhone, command.MclsUserName,
command.MclsPassword,
command.EserviceUserName, command.EservicePassword, command.TaxOfficeUserName,
command.TaxOfficepassword, command.SanaUserName, command.SanaPassword);
_fileEmployerRepository.Create(employerData);
_fileEmployerRepository.SaveChanges();
return opration.Succcedded();
}
public OperationResult EditReal(EditFileEmployer command)
{
var nationalCode = string.Empty;
var opration = new OperationResult();
var employer = _fileEmployerRepository.Get(command.Id);
if (employer == null)
return opration.Failed("رکورد مورد نظر یافت نشد");
if (_fileEmployerRepository.Exists(x =>
x.LName == command.LName && x.FName == command.FName && x.id != command.Id))
return opration.Failed("امکان ثبت رکورد تکراری وجود ندارد");
if (command.RepresentativeId == 0)
return opration.Failed("لطفا معرف را انتخاب کنبد");
if (string.IsNullOrWhiteSpace(command.FName) || string.IsNullOrWhiteSpace(command.LName))
return opration.Failed("وارد کردن نام و نام خانوادگی اجباری است");
if (!string.IsNullOrWhiteSpace(command.NationalCode))
{
if (_fileEmployerRepository.Exists(x => x.NationalCode == command.NationalCode && x.id != command.Id))
{
return opration.Failed("کد ملی وارد شده تکراری است");
}
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":
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)
{
nationalCode = command.NationalCode;
}
else
{
return opration.Failed("کد ملی وارد شده نا معتبر است");
}
}
catch (Exception)
{
return opration.Failed("لطفا کد ملی 10 رقمی وارد کنید");
}
}
else
{
nationalCode = "";
}
string initial = "1300/10/11";
var dateOfBirth = command.DateOfBirth != null ? command.DateOfBirth.ToGeorgianDateTime() : initial.ToGeorgianDateTime();
var representative = _representativeApplication.GetDetails(command.RepresentativeId);
employer.EditReal(command.FName, command.LName, command.RepresentativeId,
representative.FullName, dateOfBirth,
command.InsuranceWorkshopCode, nationalCode, command.LevelOfEducation, command.FieldOfStudy,
command.IdNumber, command.Gender,
command.MaritalStatus, command.Phone, command.OfficePhone, command.MclsUserName,
command.MclsPassword,
command.EserviceUserName, command.EservicePassword, command.TaxOfficeUserName,
command.TaxOfficepassword, command.SanaUserName, command.SanaPassword);
_fileEmployerRepository.SaveChanges();
return opration.Succcedded();
}
public OperationResult CreateLegal(CreateFileEmployer command)
{
var nationalCode = string.Empty;
var opration = new OperationResult();
if (_fileEmployerRepository.Exists(x =>
x.LegalName == command.LegalName))
return opration.Failed("امکان ثبت رکورد تکراری وجود ندارد");
if (command.RepresentativeId == 0)
return opration.Failed("لطفا معرف را انتخاب کنبد");
if (string.IsNullOrWhiteSpace(command.LegalName))
return opration.Failed("لطفا نام موسسه یا شرکت حقوق را وارد کنید");
if (!string.IsNullOrWhiteSpace(command.NationalCode))
{
if (_fileEmployerRepository.Exists(x => x.NationalCode == command.NationalCode))
{
return opration.Failed("کد ملی وارد شده تکراری است");
}
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":
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)
{
nationalCode = command.NationalCode;
}
else
{
return opration.Failed("کد ملی وارد شده نا معتبر است");
}
}
catch (Exception)
{
return opration.Failed("لطفا کد ملی 10 رقمی وارد کنید");
}
}
else
{
nationalCode = "";
}
string initial = "1300/10/11";
var dateOfBirth = command.DateOfBirth != null ? command.DateOfBirth.ToGeorgianDateTime() : initial.ToGeorgianDateTime();
var representative = _representativeApplication.GetDetails(command.RepresentativeId);
var employerData = new FileEmployer(command.FName, command.LName, command.LegalName, command.RepresentativeId,
representative.FullName, dateOfBirth,
command.InsuranceWorkshopCode, nationalCode, command.LevelOfEducation, command.FieldOfStudy,
command.IdNumber, "*",
"*", command.RegisterId, command.NationalId, "true", command.Phone, command.OfficePhone, command.MclsUserName,
command.MclsPassword,
command.EserviceUserName, command.EservicePassword, command.TaxOfficeUserName,
command.TaxOfficepassword, command.SanaUserName, command.SanaPassword);
_fileEmployerRepository.Create(employerData);
_fileEmployerRepository.SaveChanges();
return opration.Succcedded();
}
public OperationResult EditLegal(EditFileEmployer command)
{
var nationalCode = string.Empty;
var opration = new OperationResult();
var employer = _fileEmployerRepository.Get(command.Id);
if (employer == null)
return opration.Failed("رکورد مورد نظر یافت نشد");
if (_fileEmployerRepository.Exists(x =>
x.LegalName == command.LegalName && x.id != command.Id))
return opration.Failed("امکان ثبت رکورد تکراری وجود ندارد");
if (command.RepresentativeId == 0)
return opration.Failed("لطفا معرف را انتخاب کنبد");
if (string.IsNullOrWhiteSpace(command.LegalName))
return opration.Failed("لطفا نام موسسه یا شرکت را وارد کنید");
if (!string.IsNullOrWhiteSpace(command.NationalCode))
{
if (_fileEmployerRepository.Exists(x => x.NationalCode == command.NationalCode && x.id != command.Id))
{
return opration.Failed("کد ملی وارد شده تکراری است");
}
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":
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)
{
nationalCode = command.NationalCode;
}
else
{
return opration.Failed("کد ملی وارد شده نا معتبر است");
}
}
catch (Exception)
{
return opration.Failed("لطفا کد ملی 10 رقمی وارد کنید");
}
}
else
{
nationalCode = "";
}
string initial = "1300/10/11";
var dateOfBirth = command.DateOfBirth != null ? command.DateOfBirth.ToGeorgianDateTime() : initial.ToGeorgianDateTime();
var representative = _representativeApplication.GetDetails(command.RepresentativeId);
employer.EditLegal(command.FName, command.LName, command.LegalName,command.RepresentativeId,
representative.FullName, dateOfBirth,
command.InsuranceWorkshopCode, nationalCode, command.LevelOfEducation, command.FieldOfStudy,
command.IdNumber, "*",
"*",command.RegisterId,command.NationalId,"true", command.Phone, command.OfficePhone, command.MclsUserName,
command.MclsPassword,
command.EserviceUserName, command.EservicePassword, command.TaxOfficeUserName,
command.TaxOfficepassword, command.SanaUserName, command.SanaPassword);
_fileEmployerRepository.SaveChanges();
return opration.Succcedded();
}
public List<FileEmployerViewModel> GetRepresentatives()
{
return _fileEmployerRepository.GetFileEmployee();
}
public EditFileEmployer GetDetails(long id)
{
return _fileEmployerRepository.GetDetails(id);
}
public OperationResult Active(long id)
{
var opration = new OperationResult();
var employer = _fileEmployerRepository.Get(id);
if (employer == null)
return opration.Failed("رکورد مورد نظر یافت نشد");
employer.Active();
_fileEmployerRepository.SaveChanges();
return opration.Succcedded();
}
public OperationResult DeActive(long id)
{
var opration = new OperationResult();
var employer = _fileEmployerRepository.Get(id);
if (employer == null)
return opration.Failed("رکورد مورد نظر یافت نشد");
employer.DeActive();
_fileEmployerRepository.SaveChanges();
return opration.Succcedded();
}
public List<FileEmployerViewModel> Search(FileEmployerSearchModel searchModel)
{
return _fileEmployerRepository.Search(searchModel);
}
}