Esempio n. 1
0
        /// <summary>
        ///     This method deals with all the details associated with either returning the tax bill details or creating the
        ///     request for getting it scrapped from the web
        /// </summary>
        public static TaxBillDetails Get(string propertyBBL, string externalReferenceId, int priority, string jobId)
        {
            TaxBillDetails taxBill = new TaxBillDetails();

            taxBill.BBL = propertyBBL;
            taxBill.externalReferenceId = externalReferenceId;
            taxBill.status     = RequestStatus.Pending.ToString();
            taxBill.billAmount = null;

            string parameters = ParametersToJSON(propertyBBL);

            using (WebDataEntities webDBEntities = new WebDataEntities())
            {
                using (var webDBEntitiestransaction = webDBEntities.Database.BeginTransaction())
                {
                    try
                    {
                        //check if data available
                        WebDataDB.TaxBill taxBillObj = webDBEntities.TaxBills.FirstOrDefault(i => i.BBL == propertyBBL);

                        // record in database and data is not stale
                        if (taxBillObj != null && DateTime.UtcNow.Subtract(taxBillObj.LastUpdated).Days <= 30)
                        {
                            taxBill.billAmount = taxBillObj.BillAmount;
                            taxBill.status     = RequestStatus.Success.ToString();

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

                            if (dataRequestLogObj == null) //No Pending Request Create New Request
                            {
                                string requestStr = RequestData.PropertyTaxesNYC(propertyBBL);

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

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

                                taxBill.status    = RequestStatus.Pending.ToString();
                                taxBill.requestId = requestObj.RequestId;
                            }
                            else //Pending request in queue
                            {
                                taxBill.status = RequestStatus.Pending.ToString();
                                //Send the RequestId for the pending request back
                                taxBill.requestId = dataRequestLogObj.RequestId;
                                dataRequestLogObj = DAL.DataRequestLog.InsertForWebDataRequest(webDBEntities, propertyBBL, RequestTypeId,
                                                                                               dataRequestLogObj.RequestId.GetValueOrDefault(), externalReferenceId, jobId, parameters);
                            }
                        }
                        webDBEntitiestransaction.Commit();
                    }
                    catch (Exception e)
                    {
                        webDBEntitiestransaction.Rollback();
                        taxBill.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(taxBill);
        }