Пример #1
0
        /// <summary>
        ///     This method gets the data or current status for a request
        /// </summary>
        /// <param name="dataRequestLogObj"></param>
        /// <returns></returns>
        public static FreddieMortgageDetails ReRun(DataRequestLog dataRequestLogObj)
        {
            FreddieMortgageDetails mDetails = new FreddieMortgageDetails();

            mDetails.BBL                 = dataRequestLogObj.BBL;
            mDetails.requestId           = dataRequestLogObj.RequestId;
            mDetails.externalReferenceId = dataRequestLogObj.ExternalReferenceId;
            mDetails.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.FreddieMortgage mortgageObj = webDBEntities.FreddieMortgages.FirstOrDefault(i => i.BBL == parameters.BBL);

                        if (mortgageObj != null && DateTime.UtcNow.Subtract(mortgageObj.LastUpdated).Days <= 30)
                        {
                            mDetails.isFreddieMortgage = mortgageObj.IsFreddie;
                        }
                        else
                        {
                            mDetails.status = RequestStatus.Error.ToString();
                        }
                    }
                }
                return(mDetails);
            }
            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;
                        bool?isFreddie             = 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 =  // need to modify
                            isFreddie = false;         // resultObj.ServicerName;

                            if (isFreddie == null)
                            {
                                logs = DAL.DataRequestLog.SetAsError(webDBEntities, requestObj.RequestId);
                            }
                            else
                            {
                                Parameters parameters = JSONToParameters(dataRequestLogObj.RequestParameters);
                                //check if old data in the DB
                                WebDataDB.FreddieMortgage mortgageObj = webDBEntities.FreddieMortgages.FirstOrDefault(i => i.BBL == parameters.BBL);
                                if (mortgageObj != null)
                                {           //Update data with new results
                                    mortgageObj.IsFreddie   = isFreddie.GetValueOrDefault();
                                    mortgageObj.LastUpdated = requestObj.DateTimeEnded.GetValueOrDefault();
                                    webDBEntities.Entry(mortgageObj).State = EntityState.Modified;
                                }
                                else
                                {           // add an entry into cache or DB
                                    mortgageObj             = new WebDataDB.FreddieMortgage();
                                    mortgageObj.BBL         = parameters.BBL;
                                    mortgageObj.IsFreddie   = isFreddie.GetValueOrDefault();
                                    mortgageObj.LastUpdated = requestObj.DateTimeEnded.GetValueOrDefault();

                                    webDBEntities.FreddieMortgages.Add(mortgageObj);
                                }

                                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, isFreddie);
                        }
                        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 FreddieMortgageDetails Get(Parameters inParameters, string externalReferenceId, int priority, string jobId)
        {
            FreddieMortgageDetails mDetails = new FreddieMortgageDetails();

            mDetails.BBL = inParameters.BBL;
            mDetails.externalReferenceId = externalReferenceId;
            mDetails.status = RequestStatus.Pending.ToString();

            string parameters = ParametersToJSON(inParameters);

            using (WebDataEntities webDBEntities = new WebDataEntities())
            {
                using (var webDBEntitiestransaction = webDBEntities.Database.BeginTransaction())
                {
                    try
                    {
                        //check if data available
                        WebDataDB.FreddieMortgage mortgageObj = webDBEntities.FreddieMortgages.FirstOrDefault(i => i.BBL == inParameters.BBL);

                        // record in database and data is not stale
                        if (mortgageObj != null && DateTime.UtcNow.Subtract(mortgageObj.LastUpdated).Days <= 30)
                        {
                            mDetails.isFreddieMortgage = mortgageObj.IsFreddie;
                            mDetails.status            = RequestStatus.Success.ToString();

                            DAL.DataRequestLog.InsertForCacheAccess(webDBEntities, inParameters.BBL, RequestTypeId, externalReferenceId, jobId, parameters);
                        }
                        else
                        {   //check if pending request in queue
                            DataRequestLog dataRequestLogObj = DAL.DataRequestLog.GetPendingRequest(webDBEntities, inParameters.BBL, RequestTypeId, parameters);

                            if (dataRequestLogObj == null) //No Pending Request Create New Request
                            {
                                string requestStr = "";    //RequestData.XXXX(inParameters);

                                Request requestObj = DAL.Request.Insert(webDBEntities, requestStr, RequestTypeId, priority, jobId);

                                dataRequestLogObj = DAL.DataRequestLog.InsertForWebDataRequest(webDBEntities, inParameters.BBL, RequestTypeId, requestObj.RequestId,
                                                                                               externalReferenceId, jobId, parameters);

                                mDetails.status    = RequestStatus.Pending.ToString();
                                mDetails.requestId = requestObj.RequestId;
                            }
                            else //Pending request in queue
                            {
                                mDetails.status = RequestStatus.Pending.ToString();
                                //Send the RequestId for the pending request back
                                mDetails.requestId = dataRequestLogObj.RequestId;
                                dataRequestLogObj  = DAL.DataRequestLog.InsertForWebDataRequest(webDBEntities, inParameters.BBL, RequestTypeId,
                                                                                                dataRequestLogObj.RequestId.GetValueOrDefault(), externalReferenceId, jobId, parameters);
                            }
                        }
                        webDBEntitiestransaction.Commit();
                    }
                    catch (Exception e)
                    {
                        webDBEntitiestransaction.Rollback();
                        mDetails.status = RequestStatus.Error.ToString();
                        DAL.DataRequestLog.InsertForFailure(inParameters.BBL, RequestTypeId, externalReferenceId, jobId, parameters);
                        Common.Logs.log().Error(string.Format("Exception encountered processing {0} with externalRefId {1}{2}",
                                                              inParameters.BBL, externalReferenceId, Common.Logs.FormatException(e)));
                    }
                }
            }
            return(mDetails);
        }