/// <summary> /// This method gets the data or current status for a request /// </summary> /// <param name="dataRequestLogObj"></param> /// <returns></returns> public static MortgageServicerDetails ReRun(DataRequestLog dataRequestLogObj) { MortgageServicerDetails mServicerDetails = new MortgageServicerDetails(); mServicerDetails.BBL = dataRequestLogObj.BBL; mServicerDetails.requestId = dataRequestLogObj.RequestId; mServicerDetails.externalReferenceId = dataRequestLogObj.ExternalReferenceId; mServicerDetails.status = ((RequestStatus)dataRequestLogObj.RequestStatusTypeId).ToString(); try { using (WebDataEntities webDBEntities = new WebDataEntities()) { if (dataRequestLogObj.RequestStatusTypeId == (int)RequestStatus.Success) { Parameters parameters = JSONToParameters(dataRequestLogObj.RequestParameters); //check if data available WebDataDB.MortgageServicer mortgageServicerObj = webDBEntities.MortgageServicers.FirstOrDefault(i => i.BBL == parameters.BBL); if (mortgageServicerObj != null && DateTime.UtcNow.Subtract(mortgageServicerObj.LastUpdated).Days <= 30) { mServicerDetails.servicerName = mortgageServicerObj.Name; } else { mServicerDetails.status = RequestStatus.Error.ToString(); } } } return(mServicerDetails); } 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 deals with all the details associated with either returning the Mortgage Servicer details or creating the /// request for getting it scrapped from the web /// </summary> public static MortgageServicerDetails Get(string propertyBBL, string externalReferenceId, int priority, string jobId) { MortgageServicerDetails mServicerDetails = new MortgageServicerDetails(); mServicerDetails.BBL = propertyBBL; mServicerDetails.externalReferenceId = externalReferenceId; mServicerDetails.status = RequestStatus.Pending.ToString(); string parameters = ParametersToJSON(propertyBBL); using (WebDataEntities webDBEntities = new WebDataEntities()) { using (var webDBEntitiestransaction = webDBEntities.Database.BeginTransaction()) { try { string jsonBillParams = ParametersToJSON(propertyBBL); //check if data available WebDataDB.MortgageServicer mortgageServicerObj = webDBEntities.MortgageServicers.FirstOrDefault(i => i.BBL == propertyBBL); // record in database and data is not stale if (mortgageServicerObj != null && DateTime.UtcNow.Subtract(mortgageServicerObj.LastUpdated).Days <= 30) { mServicerDetails.servicerName = mortgageServicerObj.Name; mServicerDetails.status = RequestStatus.Success.ToString(); DAL.DataRequestLog.InsertForCacheAccess(webDBEntities, propertyBBL, RequestTypeId, externalReferenceId, jobId, jsonBillParams); } else { //check if pending request in queue DataRequestLog dataRequestLogObj = DAL.DataRequestLog.GetPendingRequest(webDBEntities, propertyBBL, RequestTypeId, jsonBillParams); if (dataRequestLogObj == null) //No Pending Request Create New Request { string requestStr = RequestData.ServicerWebsite(propertyBBL); Request requestObj = DAL.Request.Insert(webDBEntities, requestStr, RequestTypeId, priority, jobId); dataRequestLogObj = DAL.DataRequestLog.InsertForWebDataRequest(webDBEntities, propertyBBL, RequestTypeId, requestObj.RequestId, externalReferenceId, jobId, jsonBillParams); mServicerDetails.status = RequestStatus.Pending.ToString(); mServicerDetails.requestId = requestObj.RequestId; } else //Pending request in queue { mServicerDetails.status = RequestStatus.Pending.ToString(); //Send the RequestId for the pending request back mServicerDetails.requestId = dataRequestLogObj.RequestId; dataRequestLogObj = DAL.DataRequestLog.InsertForWebDataRequest(webDBEntities, propertyBBL, RequestTypeId, dataRequestLogObj.RequestId.GetValueOrDefault(), externalReferenceId, jobId, jsonBillParams); } } webDBEntitiestransaction.Commit(); } catch (Exception e) { webDBEntitiestransaction.Rollback(); mServicerDetails.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(mServicerDetails); }