Untitled
unknown
plain_text
a year ago
4.4 kB
12
Indexable
public OperationResult ValidateCustomerCIF(long ProcessID, bool detailed = false)
{
OperationResult operationResult = new OperationResult
{
Success = false,
Message = ""
};
try
{
using (var _db = new MBIM_WorkflowOPR_Entities())
{
var process = _db.Processes.FirstOrDefault(x => x.ProcessID == ProcessID);
Proxy.SBSI_CustomerData.PrimaryCustomerOutElement newCustomerInfo = null;
try
{
newCustomerInfo = CustomerData.GetCostumerInfoByAccountNumber(process.Account.Replace(" ", ""), process.ProcessID);
}
catch (Exception ex)
{
if (detailed)
{
operationResult.Message = $"Conta {process.Account} inválida. CIF {process.CIF}. Beneficiário {process.Beneficiary}. {ex.Message}";
}
Logger.Log(ErrorConfiguration.Importance.ERROR, "Não é possível proceder com a validação de CIF porque foi detectada uma conta inválida.", ex);
}
if (newCustomerInfo == null || ( !string.IsNullOrEmpty(process.CIF) && newCustomerInfo.CIF != process.CIF))
{
var entityProcess = new Processes
{
ProcessID = process.ProcessID.ToString(),
CIF = process.CIF,
Account = process.Account,
BranchName = process.BranchName,
BranchCode = process.BranchCode,
CreationDate = process.CreationDate.ToString("dd-MM-yyyy"),
Beneficiary = process.Beneficiary,
Currency = process.Currency,
Motive = process.Motive,
IMEXRefNo = process.IMEXRefNo,
StateID = process.StateID,
StateDescription = process.State.Description
};
var sendEmailResult = SendNotifications.SendEmailAlertForInvalidCif(entityProcess, newCustomerInfo);
if (!sendEmailResult.Success)
throw new Exception(sendEmailResult.Message);
var action = _db.Actions.FirstOrDefault(x =>
x.FromStateID == process.StateID && x.Description == Const.Actions.InvalidCifDescription);
if (action != null)
{
// Send process to state 101
var updateResult = ProcessesTransaction.UpdateProcess(ProcessID, Const.UserWfAuto, action.ActionID);
if (detailed)
{
if (newCustomerInfo != null)
{
operationResult.Message = $"Processo {ProcessID} com CIF {process.CIF} inválido (beneficiário {process.Beneficiary}). " +
$"Identificado o CIF correto {newCustomerInfo.CIF} para o beneficiário {newCustomerInfo.name}.";
}
}
else
{
operationResult.Message = "ATENÇÃO: Processo com CIF de beneficiário inválido.</br>" + updateResult.Message;
}
return operationResult;
}
else
{
var msg = "ATENÇÃO: Processo " + process + " com CIF de beneficiário inválido. Não foi possível avançar do estado " + process.StateID;
Logger.Log(ErrorConfiguration.Importance.ERROR, msg);
operationResult.Message = msg;
return operationResult;
}
}
operationResult.Success = true;
return operationResult;
}
}
catch (Exception ex)
{
Logger.LogError("ValidateCustomerInfo Exception: " + ex.Message, ex);
return operationResult;
}
}
}Editor is loading...
Leave a Comment