/// <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; NoticeOfProperyValue noticeOfPropertyValueObj = 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.ParseNoticeOfPropertyValue(requestObj.ResponseData); Parameters parameters = JSONToParameters(dataRequestLogObj.RequestParameters); //check if old data in the DB noticeOfPropertyValueObj = webDBEntities.NoticeOfProperyValues.FirstOrDefault(i => i.BBL == parameters.BBL); if (noticeOfPropertyValueObj != null) { //Update data with new results noticeOfPropertyValueObj = CopyData(noticeOfPropertyValueObj, resultObj); noticeOfPropertyValueObj.BBL = parameters.BBL; noticeOfPropertyValueObj.LastUpdated = requestObj.DateTimeEnded.GetValueOrDefault(); webDBEntities.Entry(noticeOfPropertyValueObj).State = EntityState.Modified; } else { // add an entry into cache or DB noticeOfPropertyValueObj = CopyData(null, resultObj); noticeOfPropertyValueObj.BBL = parameters.BBL; noticeOfPropertyValueObj.LastUpdated = requestObj.DateTimeEnded.GetValueOrDefault(); webDBEntities.NoticeOfProperyValues.Add(noticeOfPropertyValueObj); } 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, noticeOfPropertyValueObj); } return(true); } 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); } } } }
/// <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); } }