[DataContractAttribute]
class ABCUserProfilesBulkDeleteContract
{
UserId userId;
[DataMemberAttribute('UserId')]
public UserId parmUserId(UserId _userId = userId)
{
userId = _userId;
return userId;
}
}
==controller class================
internal final class ABCUserProfilesBulkDeleteController extends SysOperationServiceController
{
protected void new()
{
super(classStr(ABCUserProfilesBulkDeleteService),
methodStr(ABCUserProfilesBulkDeleteService, process),
SysOperationExecutionMode::Synchronous);
this.parmShowDialog(false);
this.parmLoadFromSysLastValue(false);
}
public static ABCUserProfilesBulkDeleteController construct()
{
return new ABCUserProfilesBulkDeleteController();
}
public static void main(Args _args)
{
ABCUserProfilesBulkDeleteController controller;
ABCUserProfilesBulkDeleteContract contract;
UserInfo userInfo;
userInfo = _args.record();
if (!userInfo || !userInfo.id)
{
throw error("@ABCFinanceLabel:SelectedUserInfoRecordIsNotValid");
}
controller = ABCUserProfilesBulkDeleteController::construct();
controller.parmArgs(_args);
contract = controller.getDataContractObject() as ABCUserProfilesBulkDeleteContract;
if (!contract)
{
throw error("@ABCFinanceLabel:UnableToInitializeContractClass");
}
contract.parmUserId(userInfo.id);
controller.startOperation();
}
/// <summary>
///
/// </summary>
/// <param name = "_executionMode"></param>
/// <param name = "_asyncResult"></param>
protected void afterOperation(SysOperationExecutionMode _executionMode, AifAsyncResult _asyncResult)
{
super(_executionMode, _asyncResult);
FormRun callerForm;
FormDataSource associationDs,userInfoDS;
callerForm = this.parmArgs().caller() as FormRun;
if (callerForm)
{
associationDs = callerForm.dataSource(formDataSourceStr(SysUserManagement, CARM_JobProfileSysUserAssociation));
userInfoDS = callerForm.dataSource(formDataSourceStr(SysUserManagement, UserInfo));
if (associationDs)
{
associationDs.research(true);
associationDs.refresh();
userInfoDS.research(true);
userInfoDS.refresh();
}
}
}
}
============service class======
[SysEntryPoint(true)]
class ABCUserProfilesBulkDeleteService
{
public void process(ABCUserProfilesBulkDeleteContract _contract)
{
UserId userId;
UserInfo userInfo;
CARM_JobProfileSysUserAssociation association;
int64 recordsToDelete;
userId = _contract.parmUserId();
if (!userId)
{
throw error("@ABCFinanceLabel:UserIDIsRequired");
}
select firstonly RecId
from userInfo
where userInfo.id == userId;
if (!userInfo.RecId)
{
throw error(strFmt("@ABCFinanceLabel:UserDoesNotExistInUserInfo", userId));
}
select count(RecId)
from association
where association.UserId == userId;
recordsToDelete = association.RecId;
if (recordsToDelete == 0)
{
info(strFmt("@ABCFinanceLabel:NoJobProfileAssociationRecordsFoundForUser", userId));
return;
}
ttsbegin;
delete_from association
where association.UserId == userId;
ttscommit;
info(strFmt("@ABCFinanceLabel:JobProfileAssociationRecordsDeletedForUser",recordsToDelete,userId));
}
}