Exemplo n.º 1
0
        private static WebDataDB.Mortgage CopyData(WebDataDB.Mortgage resultObj, RequestResponseBuilder.ResponseObjects.Mortgage valObj)
        {
            if (resultObj == null)
            {
                resultObj = new WebDataDB.Mortgage();
            }

            resultObj.FHACaseNumber   = Conversions.GetSingleValue(valObj.FHACaseNo);
            resultObj.MortgageAmounts = Conversions.Concat(valObj.MortgageAmount);

            return(resultObj);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     This method gets the data or current status for a request
        /// </summary>
        /// <param name="dataRequestLogObj"></param>
        /// <returns></returns>
        public static MortgageDocumentResult ReRun(DataRequestLog dataRequestLogObj)
        {
            MortgageDocumentResult resultObj = new MortgageDocumentResult();

            resultObj.BBL                 = dataRequestLogObj.BBL;
            resultObj.requestId           = dataRequestLogObj.RequestId;
            resultObj.externalReferenceId = dataRequestLogObj.ExternalReferenceId;
            resultObj.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.Mortgage mortgageDocumentObj = webDBEntities.Mortgages.FirstOrDefault(i => i.BBL == parameters.BBL && i.MortgageDocumentURI == parameters.URI);

                        if (mortgageDocumentObj != null && DateTime.UtcNow.Subtract(mortgageDocumentObj.LastUpdated).Days <= 30)
                        {
                            resultObj.mortgageDetails = mortgageDocumentObj;
                        }
                        else
                        {
                            resultObj.status = RequestStatus.Error.ToString();
                        }
                    }
                }
                return(resultObj);
            }
            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);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        ///     This method calls back portal for every log record in the list
        /// </summary>
        private static void MakeCallBacks(Common.Context appContext, List <DataRequestLog> logs, WebDataDB.Mortgage mortgageDocumentResultObj)
        {
            if (!CallingSystem.isAnyCallBack(appContext))
            {
                return;
            }

            var resultObj = new BAL.Results();

            resultObj.mortgageDocumentResult = new MortgageDocumentResult();
            resultObj.mortgageDocumentResult.mortgageDetails = mortgageDocumentResultObj;

            foreach (var rec in logs)
            {
                resultObj.mortgageDocumentResult.BBL                 = rec.BBL;
                resultObj.mortgageDocumentResult.requestId           = rec.RequestId;
                resultObj.mortgageDocumentResult.status              = ((RequestStatus)rec.RequestStatusTypeId).ToString();
                resultObj.mortgageDocumentResult.externalReferenceId = rec.ExternalReferenceId;
                CallingSystem.PostCallBack(appContext, resultObj);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        ///     This method updates the Mortgage Servicer table based on the information received from the Request Object
        /// </summary>
        /// <param name="requestObj"></param>
        /// <param name="appContext"></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;
                        WebDataDB.Mortgage    mortgageDocumentObj = 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)
                            {
                                var resultObj = ResponseData.ParseMortgage(requestObj.ResponseData);

                                Parameters parameters = JSONToParameters(dataRequestLogObj.RequestParameters);
                                //check if old data in the DB
                                mortgageDocumentObj = webDBEntities.Mortgages.FirstOrDefault(i => i.BBL == parameters.BBL && i.MortgageDocumentURI == parameters.URI);

                                if (mortgageDocumentObj != null)
                                {           //Update data with new results
                                    mortgageDocumentObj     = CopyData(mortgageDocumentObj, resultObj);
                                    mortgageDocumentObj.BBL = parameters.BBL;
                                    mortgageDocumentObj.MortgageDocumentURI        = parameters.URI;
                                    mortgageDocumentObj.LastUpdated                = requestObj.DateTimeEnded.GetValueOrDefault();
                                    webDBEntities.Entry(mortgageDocumentObj).State = EntityState.Modified;
                                }
                                else
                                {           // add an entry into cache or DB
                                    mortgageDocumentObj     = CopyData(null, resultObj);
                                    mortgageDocumentObj.BBL = parameters.BBL;
                                    mortgageDocumentObj.MortgageDocumentURI = parameters.URI;
                                    mortgageDocumentObj.LastUpdated         = requestObj.DateTimeEnded.GetValueOrDefault();
                                    webDBEntities.Mortgages.Add(mortgageDocumentObj);
                                }

                                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, mortgageDocumentObj);
                        }
                        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);
                    }
                }
            }
        }