feat: add API for editing old institution contracts with new properties
This commit is contained in:
@@ -87,6 +87,10 @@ public class GetInstitutionContractListItemsViewModel
|
||||
public long ContractingPartyId { get; set; }
|
||||
|
||||
public List<InstitutionContractListWorkshop> Workshops { get; set; }
|
||||
|
||||
public bool IsInPersonContract { get; set; }
|
||||
|
||||
public bool IsOldContract { get; set; }
|
||||
}
|
||||
|
||||
public class InstitutionContractListWorkshop
|
||||
|
||||
@@ -1310,7 +1310,11 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
ListStatus = status,
|
||||
IsExpired = x.contract.ContractEndGr <= endThisMontGr,
|
||||
ContractingPartyId = x.contractingParty.id,
|
||||
Workshops = workshopDetails
|
||||
Workshops = workshopDetails,
|
||||
IsInPersonContract = x.contract.WorkshopGroup?.CurrentWorkshops
|
||||
.Any(y=>y.Services.ContractInPerson)??true,
|
||||
IsOldContract = x.contract.WorkshopGroup?.CurrentWorkshops
|
||||
.Any(y=>y.Price == 0)??true
|
||||
};
|
||||
}).ToList()
|
||||
};
|
||||
|
||||
@@ -534,6 +534,196 @@ public class institutionContractController : AdminBaseController
|
||||
var res = await _institutionContractApplication.ResendVerifyLink(institutionContractId);
|
||||
return res;
|
||||
}
|
||||
|
||||
[HttpGet("edit-old/{id}")]
|
||||
public ActionResult<EditInstitutionContract> GetEditOldDetails(long id)
|
||||
{
|
||||
var representativList = new List<RepresentativeViewModel>();
|
||||
var contractingPartyList = new List<PersonalContractingPartyViewModel>();
|
||||
var res = _institutionContractApplication.GetDetails(id);
|
||||
|
||||
var representative = new RepresentativeViewModel
|
||||
{
|
||||
Id = res.RepresentativeId,
|
||||
FullName = res.RepresentativeName
|
||||
};
|
||||
representativList.Add(representative);
|
||||
var contractingParty = new PersonalContractingPartyViewModel
|
||||
{
|
||||
id = res.ContractingPartyId,
|
||||
FullName = _contractingPartyApplication.GetFullName(res.ContractingPartyId)
|
||||
};
|
||||
contractingPartyList.Add(contractingParty);
|
||||
res.RepresentativeSelectList =
|
||||
new SelectList(representativList, "Id", "FullName");
|
||||
res.ContractingPartiesSelectList =
|
||||
new SelectList(contractingPartyList, "id", "FullName");
|
||||
|
||||
var employer = _employerApplication.GetEmployerByContracrtingPartyID(res.ContractingPartyId);
|
||||
var emplId = employer.Select(x => x.Id).ToList();
|
||||
|
||||
var w = _workshopApplication.GetWorkshopsByEmployerId(emplId);
|
||||
var workshopIds = w.Select(x => x.Id).ToList();
|
||||
var workshopCount = Convert.ToString(w.Count);
|
||||
var pCount = 0;
|
||||
if (workshopIds.Count > 0)
|
||||
{
|
||||
foreach (var workshopId in workshopIds)
|
||||
{
|
||||
var p = _workshopApplication.PersonnelCount(workshopId);
|
||||
pCount += p;
|
||||
}
|
||||
|
||||
res.EmployeeCount = Convert.ToString(pCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
res.EmployeeCount = "0";
|
||||
}
|
||||
|
||||
res.WorkshopCount = workshopCount;
|
||||
|
||||
|
||||
var contactInfo = _contactInfoApplication.GetContactInfolist(id);
|
||||
if (contactInfo.Count > 0)
|
||||
{
|
||||
res.ContactInfoCounter = contactInfo.Count;
|
||||
res.ContactInformationList = contactInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
res.ContactInfoCounter = 0;
|
||||
}
|
||||
|
||||
if (res.HasValueAddedTax == "true")
|
||||
{
|
||||
res.ContractAmount -= res.ValueAddedTax;
|
||||
res.ContractAmountOAlone = res.ContractAmount.ToMoney();
|
||||
res.ValueAddedTaxStr = res.ValueAddedTax.ToMoney();
|
||||
}
|
||||
else
|
||||
{
|
||||
res.ContractAmountOAlone = res.ContractAmountString;
|
||||
res.ValueAddedTaxStr = "0";
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
[HttpPost("edit-old")]
|
||||
public ActionResult<OperationResult> EditOld([FromBody] EditInstitutionContract command)
|
||||
{
|
||||
var op = new OperationResult();
|
||||
var phoneNumber = command.ContactInformationList.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 = _institutionContractApplication.Edit(command);
|
||||
var contractingPartyId = _institutionContractApplication.GetDetails(result.SendId);
|
||||
var counter = command.ContactInformationList.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.ContactInformationList)
|
||||
{
|
||||
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.ContactInformationList)
|
||||
{
|
||||
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 result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user