105 lines
4.0 KiB
C#
105 lines
4.0 KiB
C#
using _0_Framework.Application;
|
|
using AccountManagement.Application.Contracts.Account;
|
|
using CompanyManagment.App.Contracts.InstitutionContract;
|
|
using CompanyManagment.App.Contracts.InstitutionContractContactinfo;
|
|
using CompanyManagment.App.Contracts.PersonalContractingParty;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using ServiceHost.BaseControllers;
|
|
|
|
namespace ServiceHost.Areas.Admin.Controllers;
|
|
|
|
|
|
/// <summary>
|
|
/// کنترلر قرارداد های مالی موسسه
|
|
/// </summary>
|
|
public class institutionContractController : AdminBaseController
|
|
{
|
|
private readonly IInstitutionContractApplication _institutionContractApplication;
|
|
private readonly IPersonalContractingPartyApp _contractingPartyApplication;
|
|
private readonly IContactInfoApplication _contactInfoApplication;
|
|
private readonly IAccountApplication _accountApplication;
|
|
|
|
|
|
public institutionContractController(IInstitutionContractApplication institutionContractApplication, IPersonalContractingPartyApp contractingPartyApplication, IContactInfoApplication contactInfoApplication, IAccountApplication accountApplication)
|
|
{
|
|
_institutionContractApplication = institutionContractApplication;
|
|
_contractingPartyApplication = contractingPartyApplication;
|
|
_contactInfoApplication = contactInfoApplication;
|
|
_accountApplication = accountApplication;
|
|
}
|
|
|
|
/// <summary>
|
|
/// لیست قرارداد های مالی
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<ActionResult<GetInstitutionContractListViewModel>> GetList(InstitutionContractListSearchModel searchModel)
|
|
{
|
|
return await _institutionContractApplication.GetList(searchModel);
|
|
}
|
|
|
|
/// <summary>
|
|
/// ایجاد
|
|
/// </summary>
|
|
/// <param name="command"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<ActionResult<OperationResult>>Create([FromBody]CreateInstitutionContractRequest command)
|
|
{
|
|
var op = new OperationResult();
|
|
var counter = command.ContactInfos.Count;
|
|
//if (string.IsNullOrWhiteSpace(command.HasValueAddedTax))
|
|
// command.HasValueAddedTax = "false";
|
|
var phone = command.ContactInfos.FirstOrDefault(x =>
|
|
x.SendSmsString == "true" && x.Position == "طرف قرارداد" && x.PhoneType == "شماره همراه");
|
|
var conractingParty = _contractingPartyApplication.GetDetails(command.ContractingPartyId);
|
|
if (conractingParty.IsLegal == "حقیقی" && string.IsNullOrWhiteSpace(conractingParty.Nationalcode))
|
|
return new JsonResult(op.Failed("کد ملی طرف حساب وجود ندارد"));
|
|
if (conractingParty.IsLegal == "حقوقی" && string.IsNullOrWhiteSpace(conractingParty.NationalId))
|
|
return new JsonResult(op.Failed("شناسه ملی طرف حساب وجود ندارد"));
|
|
var result =await _institutionContractApplication.CreateAsync(command);
|
|
|
|
if (result.IsSuccedded && counter > 0)
|
|
{
|
|
for (var i = 0; i <= counter - 1; i++)
|
|
{
|
|
if (command.ContactInfos[i].PhoneNumber != null)
|
|
{
|
|
var contactinfo = new CreateContactInfo
|
|
{
|
|
InstitutionContractId = result.SendId,
|
|
PhoneType = command.ContactInfos[i].PhoneType,
|
|
Position = command.ContactInfos[i].Position,
|
|
PhoneNumber = command.ContactInfos[i].PhoneNumber,
|
|
FnameLname = command.ContactInfos[i].FnameLname,
|
|
SendSms = command.ContactInfos[i].SendSmsString == "true" ? true : false
|
|
};
|
|
_contactInfoApplication.Create(contactinfo);
|
|
}
|
|
|
|
Thread.Sleep(500);
|
|
}
|
|
|
|
|
|
if (phone != null)
|
|
{
|
|
var userPass = conractingParty.IsLegal == "حقیقی"
|
|
? conractingParty.Nationalcode
|
|
: conractingParty.NationalId;
|
|
var createAcc = new RegisterAccount
|
|
{
|
|
Fullname = conractingParty.LName,
|
|
Username = userPass,
|
|
Password = userPass,
|
|
Mobile = phone.PhoneNumber,
|
|
NationalCode = userPass
|
|
};
|
|
var res = _accountApplication.RegisterClient(createAcc);
|
|
if (res.IsSuccedded)
|
|
_institutionContractApplication.CreateContractingPartyAccount(command.ContractingPartyId, res.SendId);
|
|
}
|
|
}
|
|
|
|
return new JsonResult(result);
|
|
}
|
|
} |