public void UpdateRejected() { // get all batches not older than 120 days StratcolDataAccess.SCGSAStratcolPortalEntities entity = new StratcolDataAccess.SCGSAStratcolPortalEntities(); DateTime startDate = DateTime.Now.AddDays(-10); DateTime rejectDate = DateTime.Now.Date; var batches = entity.tblBatches.Where(x => x.iDate > startDate && rejectDate > x.iDate && x.BatchRejectedRequested == 0 && x.BatchProcessID != 5); foreach (var batch in batches.ToList()) { var origin = entity.tblOrigins.Where(o => o.OriginID == batch.OriginID).FirstOrDefault(); authRejected.key = origin.AuthKey; authRejected.mode = origin.TestMode; parameterRejected.file_code = batch.FileCode; try { resultRejected = clientRejected.rejectedStandardTrans(authRejected, parameterRejected); foreach (var item in resultRejected.ToList()) { var existingResult = entity.tblResults.Where(r => r.acb_reason_code == item.acb_reason_code && r.batch_ref == item.batch_ref && r.reference == item.reference).FirstOrDefault(); if (existingResult == null) { StratcolDataAccess.tblResult result = new StratcolDataAccess.tblResult(); result.BacthID = batch.BatchID; result.user_id = item.user_id; result.acb_reason = item.acb_reason.Substring(0, (item.acb_reason.Length < 150) ? item.acb_reason.Length : 150); result.acb_reason_code = item.acb_reason_code; result.acb_status = item.acb_status; result.account_no = item.account_no; result.action_date = item.action_date; result.batch_ref = item.batch_ref; result.dbt_cdt_id = item.dbt_cdt_id; result.tran_type = item.tran_type; result.trans_status = item.tran_status; result.status_date = item.status_date; result.action_date = item.action_date; result.account_no = item.account_no; result.name = item.name; result.batch_ref = item.batch_ref; result.reference = item.reference; result.otid = item.otid; result.value = item.value; result.uDate = DateTime.Now; result.iDate = DateTime.Now; entity.AddTotblResults(result); } else { existingResult.UpdateCount++; existingResult.uDate = DateTime.Now; } batch.BatchRejectedRequested = 1; } entity.SaveChanges(); } catch (Exception ex) { // not processed yet eventLog.WriteEntry("Rejection: " + batch.FileCode + " " + xml.lastResponseText); if (xml.lastResponseText.Contains("Parameter:No rejected transactions available.")) { batch.BatchRejectedRequested = 1; entity.SaveChanges(); } } } }
public void UpdateOutputs(bool ThreeMonthCheck) { // get all batches not older than 90 days StratcolDataAccess.SCGSAStratcolPortalEntities entity = new StratcolDataAccess.SCGSAStratcolPortalEntities(); DateTime startDate = DateTime.Now.AddDays(-90); DateTime rejectDate = DateTime.Now.Date; List<StratcolDataAccess.tblBatch> batches; if (!ThreeMonthCheck) batches = entity.tblBatches.Where(x => x.iDate > startDate && rejectDate > x.iDate && x.BatchProcessID != 4 && x.BatchProcessID != 5 && (x.BatchCount > 1 || x.BatchContainsAHV == 0) && x.BatchID >= 1010).ToList(); else batches = entity.tblBatches.Where(x => x.iDate > startDate && rejectDate > x.iDate && x.BatchProcessID != 5 && (x.BatchCount > 1 || x.BatchContainsAHV == 0)).ToList(); foreach (var batch in batches) { #if DEBUG System.Diagnostics.Debug.Print(batch.BatchID + "\r\n"); #endif var origin = entity.tblOrigins.Where(o => o.OriginID == batch.OriginID).FirstOrDefault(); authOutput.key = origin.AuthKey; authOutput.mode = origin.TestMode; param.file_code = batch.FileCode; try { resultOutput = clientOutput.outputStandardTrans(authOutput, param); foreach (var item in resultOutput.ToList()) { var existingResult = entity.tblResults.Where(r => r.acb_status == item.acb_status && r.batch_ref == item.batch_ref && r.reference == item.reference).FirstOrDefault(); if (existingResult == null) { StratcolDataAccess.tblResult result = new StratcolDataAccess.tblResult(); result.BacthID = batch.BatchID; result.user_id = item.user_id; result.acb_reason = item.acb_reason.Substring(0, (item.acb_reason.Length < 150)?item.acb_reason.Length:150); result.acb_reason_code = item.acb_reason_code.Substring(0, (item.acb_reason_code.Length < 50) ? item.acb_reason_code.Length : 50); result.acb_status = item.acb_status.Substring(0, (item.acb_status.Length < 50) ? item.acb_status.Length : 50); result.account_no = item.account_no; result.action_date = item.action_date; result.batch_ref = item.batch_ref; result.dbt_cdt_id = item.dbt_cdt_id; result.tran_type = item.tran_type; result.trans_status = item.tran_status.Substring(0, (item.tran_status.Length < 50) ? item.tran_status.Length : 50); result.status_date = item.status_date; result.action_date = item.action_date; result.account_no = item.account_no; result.name = item.name; result.batch_ref = item.batch_ref; result.reference = item.reference; result.otid = item.otid; result.value = item.value; result.iDate = DateTime.Now; result.uDate = DateTime.Now; result.UpdateCount = 1; entity.AddTotblResults(result); } else { existingResult.UpdateCount++; existingResult.status_date = item.status_date; existingResult.uDate = DateTime.Now; } } entity.SaveChanges(); } catch (Exception ex) { // not processed yet eventLog.WriteEntry("Output: " + batch.FileCode + " " + xml.lastResponseText.Substring(0, xml.lastResponseText.Length > 1000 ? 1000 : xml.lastResponseText.Length)); #if DEBUG System.Diagnostics.Debug.Print("Output: " + batch.FileCode + " " + xml.lastResponseText.Substring(0, xml.lastResponseText.Length > 1000 ? 1000 : xml.lastResponseText.Length)); #endif } System.Threading.Thread.Sleep(5000); } }