/// <summary> /// This method gets the data or current status for a request /// </summary> /// <param name="dataRequestLogObj"></param> /// <returns></returns> public static DOBPenaltiesAndViolationsSummaryData ReRun(DataRequestLog dataRequestLogObj) { DOBPenaltiesAndViolationsSummaryData dPenaltiesAndViolations = new DOBPenaltiesAndViolationsSummaryData(); dPenaltiesAndViolations.BBL = dataRequestLogObj.BBL; dPenaltiesAndViolations.requestId = dataRequestLogObj.RequestId; dPenaltiesAndViolations.externalReferenceId = dataRequestLogObj.ExternalReferenceId; dPenaltiesAndViolations.status = ((RequestStatus)dataRequestLogObj.RequestStatusTypeId).ToString();; dPenaltiesAndViolations.civilPenaltyAmount = null; dPenaltiesAndViolations.violationAmount = null; try { Parameters parameters = JSONToParameters(dataRequestLogObj.RequestParameters); using (WebDataEntities webDBEntities = new WebDataEntities()) { if (dataRequestLogObj.RequestStatusTypeId == (int)RequestStatus.Success) { //check if data available WebDataDB.DOBViolation dCivilPenaltiesObj = webDBEntities.DOBViolations.FirstOrDefault(i => i.BBL == parameters.BBL); if (dCivilPenaltiesObj != null && DateTime.UtcNow.Subtract(dCivilPenaltiesObj.LastUpdated).Days <= 30) { dPenaltiesAndViolations.civilPenaltyAmount = dCivilPenaltiesObj.DOBCivilPenalties; dPenaltiesAndViolations.violationAmount = dCivilPenaltiesObj.ECBViolationAmount; } else { dPenaltiesAndViolations.status = RequestStatus.Error.ToString(); } } } return(dPenaltiesAndViolations); } catch (Exception e) { Common.Logs.log().Error(string.Format("Exception encountered processing request log for {0} with externalRefId {1}{2}", dataRequestLogObj.BBL, dataRequestLogObj.ExternalReferenceId, Common.Logs.FormatException(e))); return(null); } }
/// <summary> /// This method updates the dCivilPenalties table based on the information received from the Request Object /// </summary> public static bool UpdateData(Common.Context appContext, Request requestObj) { using (WebDataEntities webDBEntities = new WebDataEntities()) { using (var webDBEntitiestransaction = webDBEntities.Database.BeginTransaction()) { try { List <DataRequestLog> logs = null; decimal?penaltyAmount = null, violationAmount = null; switch (requestObj.RequestStatusTypeId) { case (int)RequestStatus.Error: logs = DAL.DataRequestLog.SetAsError(webDBEntities, requestObj.RequestId); break; case (int)RequestStatus.Success: { DataRequestLog dataRequestLogObj = DAL.DataRequestLog.GetFirst(webDBEntities, requestObj.RequestId); if (dataRequestLogObj != null) { decimal dobTotalPenaltyAmount = 0; decimal dobTotalViolationAmount = 0; foreach (var row in ResponseData.ParseECBviolationAndDOBCivilPenalty(requestObj.ResponseData).DOBCivilPenalties) { dobTotalPenaltyAmount += row.DOBCivilPenaltyAmount.GetValueOrDefault(); } foreach (var row in ResponseData.ParseECBviolationAndDOBCivilPenalty(requestObj.ResponseData).ECBViolations) { dobTotalViolationAmount += row.ECBPenaltyDue.GetValueOrDefault(); } penaltyAmount = dobTotalPenaltyAmount; violationAmount = dobTotalViolationAmount; Parameters parameters = JSONToParameters(dataRequestLogObj.RequestParameters); //check if data available WebDataDB.DOBViolation dobPenaltiesAndViolationsObj = webDBEntities.DOBViolations.FirstOrDefault(i => i.BBL == parameters.BBL); if (dobPenaltiesAndViolationsObj != null) { dobPenaltiesAndViolationsObj.DOBCivilPenalties = dobTotalPenaltyAmount; dobPenaltiesAndViolationsObj.ECBViolationAmount = dobTotalViolationAmount; dobPenaltiesAndViolationsObj.LastUpdated = requestObj.DateTimeEnded.GetValueOrDefault(); } else { dobPenaltiesAndViolationsObj = new WebDataDB.DOBViolation(); dobPenaltiesAndViolationsObj.BBL = parameters.BBL; dobPenaltiesAndViolationsObj.DOBCivilPenalties = dobTotalPenaltyAmount; dobPenaltiesAndViolationsObj.ECBViolationAmount = dobTotalViolationAmount; dobPenaltiesAndViolationsObj.LastUpdated = requestObj.DateTimeEnded.GetValueOrDefault(); webDBEntities.DOBViolations.Add(dobPenaltiesAndViolationsObj); } webDBEntities.SaveChanges(); logs = DAL.DataRequestLog.SetAsSuccess(webDBEntities, requestObj.RequestId); } else { throw (new Exception("Cannot locate Request Log Record(s)")); } break; } default: Common.Logs.log().Warn(string.Format("Update called for a Request Object Id {0} with incorrect Status Id {1}", requestObj.RequestId, requestObj.RequestStatusTypeId)); break; } webDBEntitiestransaction.Commit(); if (logs != null) { MakeCallBacks(appContext, logs, penaltyAmount, violationAmount); } return(true); } catch (Exception e) { webDBEntitiestransaction.Rollback(); Common.Logs.log().Error(string.Format("Exception encountered updating request with id {0}{1}", requestObj.RequestId, Common.Logs.FormatException(e))); return(false); } } } }
/// <summary> /// This method deals with all the details associated with either returning the DOB Penalties and Violations details or creating the /// request for getting it scrapped from the web /// </summary> public static DOBPenaltiesAndViolationsSummaryData Get(string propertyBBL, string externalReferenceId, int priority, string jobId) { DOBPenaltiesAndViolationsSummaryData dPenaltiesAndViolations = new DOBPenaltiesAndViolationsSummaryData(); dPenaltiesAndViolations.BBL = propertyBBL; dPenaltiesAndViolations.externalReferenceId = externalReferenceId; dPenaltiesAndViolations.status = RequestStatus.Pending.ToString(); dPenaltiesAndViolations.civilPenaltyAmount = null; dPenaltiesAndViolations.violationAmount = null; string parameters = ParametersToJSON(propertyBBL); using (WebDataEntities webDBEntities = new WebDataEntities()) { using (var webDBEntitiestransaction = webDBEntities.Database.BeginTransaction()) { try { //check if data available WebDataDB.DOBViolation dobViolationObj = webDBEntities.DOBViolations.FirstOrDefault(i => i.BBL == propertyBBL); // record in database and data is not stale if (dobViolationObj != null && DateTime.UtcNow.Subtract(dobViolationObj.LastUpdated).Days <= 15) { dPenaltiesAndViolations.civilPenaltyAmount = dobViolationObj.DOBCivilPenalties; dPenaltiesAndViolations.violationAmount = dobViolationObj.ECBViolationAmount; dPenaltiesAndViolations.status = RequestStatus.Success.ToString(); DAL.DataRequestLog.InsertForCacheAccess(webDBEntities, propertyBBL, RequestTypeId, externalReferenceId, jobId, parameters); } else { //check if pending request in queue DataRequestLog dataRequestLogObj = DAL.DataRequestLog.GetPendingRequest(webDBEntities, propertyBBL, RequestTypeId, parameters); if (dataRequestLogObj == null) //No Pending Request Create New Request { string requestStr = RequestResponseBuilder.RequestObjects.RequestData.ECBviolationAndDOBCivilPenalties(propertyBBL); Request requestObj = DAL.Request.Insert(webDBEntities, requestStr, RequestTypeId, priority, jobId); dataRequestLogObj = DAL.DataRequestLog.InsertForWebDataRequest(webDBEntities, propertyBBL, RequestTypeId, requestObj.RequestId, externalReferenceId, jobId, parameters); dPenaltiesAndViolations.status = RequestStatus.Pending.ToString(); dPenaltiesAndViolations.requestId = requestObj.RequestId; } else //Pending request in queue { dPenaltiesAndViolations.status = RequestStatus.Pending.ToString(); //Send the RequestId for the pending request back dPenaltiesAndViolations.requestId = dataRequestLogObj.RequestId; dataRequestLogObj = DAL.DataRequestLog.InsertForWebDataRequest(webDBEntities, propertyBBL, RequestTypeId, dataRequestLogObj.RequestId.GetValueOrDefault(), externalReferenceId, jobId, parameters); } } webDBEntitiestransaction.Commit(); } catch (Exception e) { webDBEntitiestransaction.Rollback(); dPenaltiesAndViolations.status = RequestStatus.Error.ToString(); DAL.DataRequestLog.InsertForFailure(propertyBBL, RequestTypeId, externalReferenceId, jobId, parameters); Common.Logs.log().Error(string.Format("Exception encountered processing {0} with externalRefId {1}{2}", propertyBBL, externalReferenceId, Common.Logs.FormatException(e))); } } } return(dPenaltiesAndViolations); }