/// <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);
            }
        }
Exemple #2
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, NoticeOfProperyValue noticeOfPropertyValueObj)
        {
            if (!CallingSystem.isAnyCallBack(appContext))
            {
                return;
            }

            var resultObj = new BAL.Results();

            resultObj.noticeOfPropertyValueResult = new NoticeOfPropertyValueResult();
            resultObj.noticeOfPropertyValueResult.noticeOfPropertyValue = noticeOfPropertyValueObj;

            foreach (var rec in logs)
            {
                resultObj.noticeOfPropertyValueResult.BBL                 = rec.BBL;
                resultObj.noticeOfPropertyValueResult.requestId           = rec.RequestId;
                resultObj.noticeOfPropertyValueResult.status              = ((RequestStatus)rec.RequestStatusTypeId).ToString();
                resultObj.noticeOfPropertyValueResult.externalReferenceId = rec.ExternalReferenceId;
                CallingSystem.PostCallBack(appContext, resultObj);
            }
        }
        /// <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);
                    }
                }
            }
        }