Пример #1
0
        public OperationsStatus InsertErrorLog(ErrorLog ErrorObj)
        {
            OperationsStatus operationsStatusObj = null;

            try
            {
                operationsStatusObj = _errorLogRepository.InsertErrorLog(ErrorObj);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(operationsStatusObj);
        }
Пример #2
0
        public ActionResult <QBSyncResponse> Client(int id)
        {
            //If the id is 0, return all subscribers otherwise return the requested subscriber
            string bRtn;
            bool   updateAccessTableResult;

            subscriberId = id;
            IEnumerable <Subscriber> subscriber;

            currentMethodName = this.ControllerContext.RouteData.Values["action"].ToString();

            if (subscriberId == 0)
            {
                subscriber = _subscriberRepo.GetAllSubscribers();
            }
            else
            {
                subscriber = _subscriberRepo.GetById(subscriberId);
                if (subscriber == null)
                {
                    _logger.LogError("subscriber not found");
                    return(new QBSyncResponse()
                    {
                        ResponseStatus = false,
                        ResponseMessage = "Subscriber not found."
                    });
                }
            }

            foreach (Subscriber subs in subscriber)
            {
                subscriberId = subs.Id;
                _logger.LogInfo("Begin Subscriber " + subscriberId + " Authorization");
                QBOAccess qboAccess = _qboaccessRepo.GetById(subscriberId);
                if (qboAccess == null)
                {
                    _logger.LogError("You must authorize with QuickBooks before syncing your data.");
                    return(new QBSyncResponse()
                    {
                        ResponseStatus = false,
                        ResponseMessage = "You must authorize with QuickBooks before syncing your data."
                    });
                }
                // save Access Id
                int qboAccessId = qboAccess.Id;

                // Refresh QBO connection
                bRtn = RefreshQBO(qboAccess);
                if (bRtn != SuccessMessage)
                {
                    _qboaccessRepo.DeleteQBOAccess(subscriberId);
                    return(new QBSyncResponse()
                    {
                        ResponseStatus = false,
                        ResponseMessage = bRtn
                    });
                }
                // Update Access table with new refresh token
                try
                {
                    AESCryptography cryptography = new AESCryptography(_configuration);
                    appOauthRefreshToken = cryptography.Encrypt(appOauthRefreshToken);
                    if (IsAllDigits(qboAccess.Company))
                    {
                        companyId = cryptography.Encrypt(qboAccess.Company);
                    }
                    else
                    {
                        companyId = qboAccess.Company;
                    }
                    updateAccessTableResult = _qboaccessRepo.UpdateQBOAccess(qboAccessId, companyId, appOauthAccessToken, appOauthRefreshToken, qboAccess);
                    if (updateAccessTableResult == false)
                    {
                        _logger.LogError("You will need to re-authorize your QuickBooks account and try to sync again.");
                        return(new QBSyncResponse()
                        {
                            ResponseStatus = false,
                            ResponseMessage = "You will need to re-authorize your QuickBooks account and try to sync again."
                        });
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogError("error occurred" + ex.Message);
                    _errorLogRepo.InsertErrorLog(new ErrorLog
                    {
                        SubscriberId  = subscriberId,
                        ErrorMessage  = ex.Message,
                        ServiceName   = serviceName,
                        MethodName    = currentMethodName,
                        ErrorDateTime = DateTime.Now
                    });
                    return(new QBSyncResponse()
                    {
                        ResponseStatus = false,
                        ResponseMessage = "Error occurred " + ex.Message
                    });
                }
                _logger.LogInfo("End Subscriber " + subscriberId + " Authorization");

                //Time to get some data from QBO
                _logger.LogInfo("Begin QBO Data Access for Subscriber " + subscriberId);
                // Get and Update Customers & Invoices
                bRtn = GetQBOCustomers(qboAccess);
                if (bRtn != SuccessMessage)
                {
                    _logger.LogError(bRtn);
                    return(new QBSyncResponse()
                    {
                        ResponseStatus = false,
                        ResponseMessage = bRtn
                    });
                }
                _logger.LogInfo("End QBO Data Access for Subscriber " + subscriberId);
                //Update the last sync date in the subscriber table
                var updateSyncDateResult = _subscriberRepo.UpdateSubscriber(subscriberId, DateTime.Now, subs);
                if (updateSyncDateResult == false)
                {
                    _logger.LogError("Not able to update last sync date for subscriber");
                    return(new QBSyncResponse()
                    {
                        ResponseStatus = false,
                        ResponseMessage = "Not able to update last sync date for subscriber"
                    });
                }
            }
            return(new QBSyncResponse()
            {
                ResponseStatus = true,
                ResponseMessage = SuccessMessage
            });
        }
Пример #3
0
        public ActionResult <bool> BeginAuthorize(int id)
        {
            _logger.LogInfo("Start BeginAuthorize for Subscriber " + id);
            HttpContext.Session.SetInt32("subscriberId", id); // set the session subscriber id
            var connString = new QuickBooksOnlineConnectionStringBuilder();

            connString.Offline           = false;
            connString.OAuthClientId     = appClientId;
            connString.OAuthClientSecret = appClientSecret;
            connString.UseSandbox        = useSandBox;
            connString.Logfile           = "c:\\users\\public\\documents\\QBOLog.txt";
            connString.Verbosity         = "5";
            String callbackURL = _configuration["CFXServiceConfiguration:AuthanticateServiceEndPoint"] + "api/master/finalauthorize";

            currentMethodName = this.ControllerContext.RouteData.Values["action"].ToString();


            try
            {
                using (QuickBooksOnlineConnection connQBO = new QuickBooksOnlineConnection(connString.ToString()))
                {
                    connQBO.RuntimeLicense = runTimeLicense;
                    using (QuickBooksOnlineCommand cmdQBO = new QuickBooksOnlineCommand("GetOAuthAuthorizationURL", connQBO))
                    {
                        cmdQBO.Parameters.Add(new QuickBooksOnlineParameter("CallbackURL", callbackURL));
                        cmdQBO.CommandType = CommandType.StoredProcedure;

                        using (QuickBooksOnlineDataReader reader = cmdQBO.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                Response.Redirect(reader["URL"] as string, false);
                            }
                            else
                            {
                                _errorLogRepo.InsertErrorLog(new ErrorLog
                                {
                                    SubscriberId  = id,
                                    ErrorMessage  = "No Authorization URL available",
                                    ServiceName   = serviceName,
                                    MethodName    = currentMethodName,
                                    ErrorDateTime = DateTime.Now
                                });
                                return(false);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _errorLogRepo.InsertErrorLog(new ErrorLog
                {
                    SubscriberId  = id,
                    ErrorMessage  = ex.Message,
                    ServiceName   = serviceName,
                    MethodName    = currentMethodName,
                    ErrorDateTime = DateTime.Now
                });
                return(false);
            }
            _logger.LogInfo("End BeginAuthorize for Subscriber " + id);
            return(true);
        }
Пример #4
0
 public ErrorLog InsertErrorLog(ErrorLog entity)
 {
     return(_iErrorLogRepository.InsertErrorLog(entity));
 }