예제 #1
0
        /// <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);
            }
        }
예제 #2
0
        /// <summary>
        ///     This method updates the Mortgage Servicer table based on the information received from the Request Object
        /// </summary>
        /// <param name="appContext"></param>
        /// <param name="requestObj"></param>
        /// <returns>True if successful else false</returns>
        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;
                        string servicerName        = (string)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)
                            {
                                throw (new Exception("Cannot locate Request Log Record(s)"));
                            }

                            var resultObj = (ResponseData.ParseServicer(requestObj.ResponseData))[0];
                            servicerName = resultObj.ServicerName;
                            if (servicerName == null)
                            {
                                logs = DAL.DataRequestLog.SetAsError(webDBEntities, requestObj.RequestId);
                            }
                            else
                            {
                                Parameters parameters = JSONToParameters(dataRequestLogObj.RequestParameters);
                                //check if old data in the DB
                                WebDataDB.MortgageServicer mortgageServicerObj = webDBEntities.MortgageServicers.FirstOrDefault(i => i.BBL == parameters.BBL);
                                if (mortgageServicerObj != null)
                                {           //Update data with new results
                                    mortgageServicerObj.Name        = resultObj.ServicerName;
                                    mortgageServicerObj.LastUpdated = requestObj.DateTimeEnded.GetValueOrDefault();
                                    webDBEntities.Entry(mortgageServicerObj).State = EntityState.Modified;
                                }
                                else
                                {           // add an entry into cache or DB
                                    mortgageServicerObj             = new WebDataDB.MortgageServicer();
                                    mortgageServicerObj.BBL         = parameters.BBL;
                                    mortgageServicerObj.Name        = resultObj.ServicerName;
                                    mortgageServicerObj.LastUpdated = requestObj.DateTimeEnded.GetValueOrDefault();

                                    webDBEntities.MortgageServicers.Add(mortgageServicerObj);
                                }

                                webDBEntities.SaveChanges();

                                logs = DAL.DataRequestLog.SetAsSuccess(webDBEntities, requestObj.RequestId);
                            }
                            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, servicerName);
                        }
                        return(true);
                    }
                    catch (DbEntityValidationException dbEx)
                    {
                        foreach (var validationErrors in dbEx.EntityValidationErrors)
                        {
                            foreach (var validationError in validationErrors.ValidationErrors)
                            {
                                Common.Logs.log().Error(string.Format("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage));
                            }
                        }
                        return(false);
                    }
                    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);
                    }
                }
            }
        }
예제 #3
0
        /// <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);
        }