Merge branch 'Feature/InstitutionContract/Create-Api' into Main
This commit is contained in:
@@ -31,15 +31,30 @@ public interface IInstitutionContractApplication
|
||||
|
||||
List<InstitutionContractViewModel> PrintAll(List<long> id);
|
||||
InstitutionContractViewModel PrintOne(long id);
|
||||
|
||||
OperationResult Active(long id);
|
||||
|
||||
|
||||
OperationResult DeActive(long id);
|
||||
|
||||
|
||||
OperationResult DeActiveBlue(long id);
|
||||
|
||||
|
||||
OperationResult DeActiveAllConnections(long id);
|
||||
|
||||
|
||||
OperationResult ReActiveAllConnections(long id);
|
||||
|
||||
void ReActiveAllAfterCreateNew(long contractingPartyId);
|
||||
|
||||
|
||||
void RemoveContract(long id);
|
||||
|
||||
|
||||
OperationResult Sign(long id);
|
||||
|
||||
|
||||
OperationResult UnSign(long id);
|
||||
void CreateContractingPartyAccount(long contractingPartyid, long accountId);
|
||||
|
||||
@@ -57,7 +72,22 @@ public interface IInstitutionContractApplication
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// ایجاد
|
||||
/// </summary>
|
||||
/// <param name="command"></param>
|
||||
/// <returns></returns>
|
||||
Task<OperationResult> CreateAsync(CreateInstitutionContractRequest command);
|
||||
/// <summary>
|
||||
/// ویرایش
|
||||
/// </summary>
|
||||
/// <param name="command"></param>
|
||||
/// <returns></returns>
|
||||
Task<OperationResult> EditAsync(EditInstitutionContractRequest command);
|
||||
}
|
||||
public class EditInstitutionContractRequest:CreateInstitutionContractRequest
|
||||
{
|
||||
public long Id { get; set; }
|
||||
}
|
||||
public class CreateInstitutionContractRequest
|
||||
{
|
||||
|
||||
@@ -1032,6 +1032,101 @@ public class InstitutionContractApplication : IInstitutionContractApplication
|
||||
_institutionContractRepository.SaveChanges();
|
||||
return opration.Succcedded(createContract.id);
|
||||
}
|
||||
|
||||
public async Task<OperationResult> EditAsync(EditInstitutionContractRequest command)
|
||||
{
|
||||
bool dateMessages = false;
|
||||
string dateMaessageResult = String.Empty;
|
||||
var opration = new OperationResult();
|
||||
var ContractEdit = _institutionContractRepository.Get(command.Id);
|
||||
if (ContractEdit == null)
|
||||
opration.Failed("رکورد مورد نظر وجود ندارد");
|
||||
|
||||
var contractStartGr = command.ContractStartFa.ToGeorgianDateTime();
|
||||
var contractEndGr = command.ContractEndFa.ToGeorgianDateTime();
|
||||
|
||||
var contractDateGr = command.ContractDateFa.ToGeorgianDateTime();
|
||||
|
||||
if (_institutionContractRepository.Exists(x =>
|
||||
x.ContractingPartyId == ContractEdit.ContractingPartyId &&
|
||||
((contractStartGr >= x.ContractStartGr && contractStartGr <= x.ContractEndGr) ||
|
||||
(contractEndGr >= x.ContractStartGr && contractEndGr <= x.ContractEndGr)) && x.id != command.Id &&
|
||||
x.TypeOfContract == command.TypeOfContract))
|
||||
return opration.Failed("در بازه تاریخ وارد شده قرارداد دیگری وجود دارد");
|
||||
//if (_institutionContractRepository.Exists(x =>
|
||||
// x.ContractingPartyId == ContractEdit.ContractingPartyId && (x.ContractStartGr <= contractDateGr || x.ContractDateGr <= contractDateGr) && x.id != command.Id))
|
||||
// return opration.Failed("تاریخ عقد قرارداد با قرارداد دیگری تداخل دارد");
|
||||
if (string.IsNullOrWhiteSpace(command.ContractDateFa))
|
||||
{
|
||||
dateMaessageResult = "تاریخ قراراداد اجباری است. ";
|
||||
dateMessages = true;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(command.ContractStartFa))
|
||||
{
|
||||
dateMaessageResult += "تاریخ شروع قراراداد اجباری است. ";
|
||||
dateMessages = true;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(command.ContractEndFa))
|
||||
{
|
||||
dateMaessageResult += "تاریخ پایان قراراداد اجباری است. ";
|
||||
dateMessages = true;
|
||||
}
|
||||
|
||||
if (dateMessages)
|
||||
return opration.Failed(dateMaessageResult);
|
||||
if (command.Address != null && command.State == null)
|
||||
{
|
||||
return opration.Failed("لطفا استان و شهر را انتخاب کنید");
|
||||
}
|
||||
|
||||
if ((command.Address != null && command.State != null) && command.City == "شهرستان")
|
||||
{
|
||||
return opration.Failed("لطفا شهر را انتخاب کنید");
|
||||
}
|
||||
|
||||
if (command.Address == null && command.State != null)
|
||||
{
|
||||
return opration.Failed("لطفا آدرس را وارد کنید");
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(command.OfficialCompany))
|
||||
return opration.Failed("رسمی یا غیر رسمی بودن پرداخت را مشخص کنید");
|
||||
if (command.OfficialCompany == "Official" && string.IsNullOrWhiteSpace(command.HasValueAddedTax))
|
||||
return opration.Failed("وضعیت ارزش افزوده را مشخص کنید");
|
||||
if (string.IsNullOrWhiteSpace(command.TypeOfContract))
|
||||
return opration.Failed("عنوان قرارداد را انتخاب کنید");
|
||||
|
||||
if (string.IsNullOrWhiteSpace(command.ContractAmountString))
|
||||
command.ContractAmountString = "0";
|
||||
if (string.IsNullOrWhiteSpace(command.DailyCompenseationString))
|
||||
command.DailyCompenseationString = "0";
|
||||
if (string.IsNullOrWhiteSpace(command.ObligationString))
|
||||
command.ObligationString = "0";
|
||||
if (string.IsNullOrWhiteSpace(command.TotalAmountString))
|
||||
command.TotalAmountString = "0";
|
||||
|
||||
var valueAddedTax = command.ValueAddedTaxStr.MoneyToDouble();
|
||||
var contractAmountStr = command.ContractAmountString.ToDoubleMoney();
|
||||
var contractAmount = Convert.ToDouble(contractAmountStr);
|
||||
var DailyCompenseationStr = command.DailyCompenseationString.ToDoubleMoney();
|
||||
var dailyCompenseation = Convert.ToDouble(DailyCompenseationStr);
|
||||
var ObligationStr = command.ObligationString.ToDoubleMoney();
|
||||
var obligation = Convert.ToDouble(ObligationStr);
|
||||
var TotalAmountStr = command.TotalAmountString.ToDoubleMoney();
|
||||
var totalAmount = Convert.ToDouble(TotalAmountStr);
|
||||
|
||||
ContractEdit.Edit(contractDateGr, command.ContractDateFa, command.State, command.City, command.Address,
|
||||
contractStartGr,
|
||||
command.ContractStartFa, contractEndGr, command.ContractEndFa, contractAmount,
|
||||
dailyCompenseation,
|
||||
obligation, totalAmount, command.WorkshopManualCount, command.EmployeeManualCount,
|
||||
command.Description, command.OfficialCompany, command.TypeOfContract, valueAddedTax,
|
||||
command.HasValueAddedTax);
|
||||
await _institutionContractRepository.SaveChangesAsync();
|
||||
return opration.Succcedded(command.Id);
|
||||
}
|
||||
}
|
||||
|
||||
#region CustomViewModels
|
||||
|
||||
@@ -8,7 +8,6 @@ using ServiceHost.BaseControllers;
|
||||
|
||||
namespace ServiceHost.Areas.Admin.Controllers;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// کنترلر قرارداد های مالی موسسه
|
||||
/// </summary>
|
||||
@@ -18,14 +17,16 @@ public class institutionContractController : AdminBaseController
|
||||
private readonly IPersonalContractingPartyApp _contractingPartyApplication;
|
||||
private readonly IContactInfoApplication _contactInfoApplication;
|
||||
private readonly IAccountApplication _accountApplication;
|
||||
|
||||
|
||||
public institutionContractController(IInstitutionContractApplication institutionContractApplication, IPersonalContractingPartyApp contractingPartyApplication, IContactInfoApplication contactInfoApplication, IAccountApplication accountApplication)
|
||||
|
||||
public institutionContractController(IInstitutionContractApplication institutionContractApplication,
|
||||
IPersonalContractingPartyApp contractingPartyApplication, IContactInfoApplication contactInfoApplication,
|
||||
IAccountApplication accountApplication)
|
||||
{
|
||||
_institutionContractApplication = institutionContractApplication;
|
||||
_contractingPartyApplication = contractingPartyApplication;
|
||||
_contactInfoApplication = contactInfoApplication;
|
||||
_accountApplication = accountApplication;
|
||||
_institutionContractApplication = institutionContractApplication;
|
||||
_contractingPartyApplication = contractingPartyApplication;
|
||||
_contactInfoApplication = contactInfoApplication;
|
||||
_accountApplication = accountApplication;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -33,7 +34,8 @@ public class institutionContractController : AdminBaseController
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<GetInstitutionContractListViewModel>> GetList(InstitutionContractListSearchModel searchModel)
|
||||
public async Task<ActionResult<GetInstitutionContractListViewModel>> GetList(
|
||||
InstitutionContractListSearchModel searchModel)
|
||||
{
|
||||
return await _institutionContractApplication.GetList(searchModel);
|
||||
}
|
||||
@@ -44,62 +46,253 @@ public class institutionContractController : AdminBaseController
|
||||
/// <param name="command"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<OperationResult>>Create([FromBody]CreateInstitutionContractRequest command)
|
||||
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);
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
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);
|
||||
return new JsonResult(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ویرایش
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
public async Task<ActionResult<OperationResult>> Edit([FromBody] EditInstitutionContractRequest command)
|
||||
{
|
||||
var op = new OperationResult();
|
||||
var phoneNumber = 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("شناسه ملی طرف حساب وجود ندارد"));
|
||||
if (phoneNumber == null)
|
||||
return new JsonResult(op.Failed("تعیین شماره همراه با سمت طرف قرارداد اجباریست"));
|
||||
//if (string.IsNullOrWhiteSpace(command.HasValueAddedTax))
|
||||
// command.HasValueAddedTax = "false";
|
||||
var result = await _institutionContractApplication.EditAsync(command);
|
||||
var contractingPartyId = _institutionContractApplication.GetDetails(result.SendId);
|
||||
var counter = command.ContactInfos.Count;
|
||||
var getOldContarct = _institutionContractApplication.NewSearch(new InstitutionContractSearchModel()
|
||||
{ ContractingPartyId = contractingPartyId.ContractingPartyId, IsActiveString = "both" })
|
||||
.Where(x => x.IsActiveString == "false" || x.IsActiveString == "blue").ToList();
|
||||
if (result.IsSuccedded && counter > 0)
|
||||
{
|
||||
if (getOldContarct.Count > 0)
|
||||
{
|
||||
foreach (var item in getOldContarct)
|
||||
{
|
||||
_contactInfoApplication.RemoveContactInfo(item.Id);
|
||||
foreach (var phone in command.ContactInfos)
|
||||
{
|
||||
if (phone.PhoneNumber != null)
|
||||
{
|
||||
var contactinfo = new CreateContactInfo
|
||||
{
|
||||
InstitutionContractId = item.Id,
|
||||
PhoneType = phone.PhoneType,
|
||||
Position = phone.Position,
|
||||
PhoneNumber = phone.PhoneNumber,
|
||||
FnameLname = phone.FnameLname,
|
||||
SendSms = phone.SendSmsString == "true" ? true : false
|
||||
};
|
||||
_contactInfoApplication.Create(contactinfo);
|
||||
}
|
||||
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_contactInfoApplication.RemoveContactInfo(command.Id);
|
||||
foreach (var item in command.ContactInfos)
|
||||
{
|
||||
if (item.PhoneNumber != null)
|
||||
{
|
||||
var contactinfo = new CreateContactInfo
|
||||
{
|
||||
InstitutionContractId = result.SendId,
|
||||
PhoneType = item.PhoneType,
|
||||
Position = item.Position,
|
||||
PhoneNumber = item.PhoneNumber,
|
||||
FnameLname = item.FnameLname,
|
||||
SendSms = item.SendSmsString == "true" ? true : false
|
||||
};
|
||||
_contactInfoApplication.Create(contactinfo);
|
||||
}
|
||||
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
|
||||
|
||||
//ساخت اکانت کلاینت
|
||||
var userPass = conractingParty.IsLegal == "حقیقی"
|
||||
? conractingParty.Nationalcode
|
||||
: conractingParty.NationalId;
|
||||
var checkExistAccount = _accountApplication.CheckExistClientAccount(userPass);
|
||||
if (!checkExistAccount)
|
||||
{
|
||||
var createAcc = new RegisterAccount
|
||||
{
|
||||
Fullname = conractingParty.LName,
|
||||
Username = userPass,
|
||||
Password = userPass,
|
||||
Mobile = phoneNumber.PhoneNumber,
|
||||
NationalCode = userPass
|
||||
};
|
||||
var res = _accountApplication.RegisterClient(createAcc);
|
||||
if (res.IsSuccedded)
|
||||
_institutionContractApplication.CreateContractingPartyAccount(command.ContractingPartyId,
|
||||
res.SendId);
|
||||
}
|
||||
}
|
||||
//Thread.Sleep(500);
|
||||
//for (int i = 0; i <= counter - 1; i++)
|
||||
//{
|
||||
// if (command.ContactInformationList[i].PhoneNumber != null)
|
||||
// {
|
||||
|
||||
// var contactinfo = new CreateContactInfo()
|
||||
// {
|
||||
// InstitutionContractId = result.SendId,
|
||||
// PhoneType = command.ContactInformationList[i].PhoneType,
|
||||
// Position = command.ContactInformationList[i].Position,
|
||||
// PhoneNumber = command.ContactInformationList[i].PhoneNumber,
|
||||
// FnameLname = command.ContactInformationList[i].FnameLname,
|
||||
// SendSms = command.ContactInformationList[i].SendSmsString == "true" ? true : false
|
||||
// };
|
||||
// _contactInfoApplication.Create(contactinfo);
|
||||
|
||||
// }
|
||||
// Thread.Sleep(500);
|
||||
//}
|
||||
|
||||
|
||||
return new JsonResult(result);
|
||||
}
|
||||
|
||||
[HttpPost("deActive")]
|
||||
public ActionResult<OperationResult> DeActive(long id, string balance)
|
||||
{
|
||||
var result = new OperationResult();
|
||||
if (balance == "0")
|
||||
{
|
||||
result = _institutionContractApplication.DeActive(id);
|
||||
if (result.IsSuccedded) result = _institutionContractApplication.DeActiveAllConnections(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = _institutionContractApplication.DeActiveBlue(id);
|
||||
if (result.IsSuccedded)
|
||||
result = _institutionContractApplication.DeActiveAllConnections(id);
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// غیر فعال
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("active")]
|
||||
public ActionResult<OperationResult> IsActive(long id)
|
||||
{
|
||||
var result = _institutionContractApplication.Active(id);
|
||||
if (result.IsSuccedded)
|
||||
{
|
||||
result = _institutionContractApplication.ReActiveAllConnections(id);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[HttpPost("sign")]
|
||||
public ActionResult<OperationResult> Sign(long Id)
|
||||
{
|
||||
var result = _institutionContractApplication.Sign(Id);
|
||||
if (result.IsSuccedded)
|
||||
return new JsonResult(new
|
||||
{
|
||||
isSuccedded = true
|
||||
});
|
||||
return new JsonResult(new
|
||||
{
|
||||
isSuccedded = false
|
||||
});
|
||||
}
|
||||
|
||||
[HttpPost("unsign")]
|
||||
public ActionResult<OperationResult> UnSign(long Id)
|
||||
{
|
||||
var id = Convert.ToInt64(Id);
|
||||
var result = _institutionContractApplication.UnSign(Id);
|
||||
if (result.IsSuccedded)
|
||||
return new JsonResult(new
|
||||
{
|
||||
isSuccedded = true
|
||||
});
|
||||
return new JsonResult(new
|
||||
{
|
||||
isSuccedded = false
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user