Ejemplo n.º 1
0
        public string PayPalTransactionProcessLongRunningAction(string id, int PaypalApi, string RangeDate)
        {
            using (ImsDbContext dbContext = new ImsDbContext())
            {
                dbContext.Configuration.AutoDetectChangesEnabled = false;
                PaypalApi paypalApi = dbContext.PaypalApis.Find(PaypalApi);
                dbContext.Configuration.AutoDetectChangesEnabled = true;
                this.ImsService.PayPalHelper(paypalApi);
                string   dataRange = RangeDate;
                string[] date      = dataRange.Split(new char[] { '-' });

                DateTime startDate = DateTime.Parse(date[0].Trim());
                DateTime endDate   = DateTime.Parse(date[1].Trim());

                IEnumerable <PaymentTransactionSearchResultType> PaypalTransactionSearch = this.ImsService.ApiTransactionSearch(startDate, endDate);
                int total = PaypalTransactionSearch.Count <PaymentTransactionSearchResultType>();


                if (PaypalTransactionSearch.Count() > 0)
                {
                    var lastsearch = PaypalTransactionSearch.Last();
                    var lastdetail = this.ImsService.ApiTransactionDetail(lastsearch);
                    ProcessLastDate = lastdetail.PaymentTransactionDetails.PaymentInfo.PaymentDate;
                }
                else
                {
                    ProcessLastDate = startDate.ToCnDataString();
                }
                int i = 0;
                // List<PayPalTransaction> pptlist = new List<PayPalTransaction>();
                PaypalTransactionSearch.ToList().ForEach(a =>
                {
                    GetTransactionDetailsResponseType PaypalTransactionDetails = this.ImsService.ApiTransactionDetail(a);
                    if (PaypalTransactionDetails.Ack.Equals(AckCodeType.SUCCESS))
                    {
                        i++;
                        int d = Precentage(i, total);

                        lock (syncRoot)
                        {
                            ProcessStatus[id] = d;
                            ProcessTotal      = total;
                            ProcessNumber     = i + 1;
                        }
                        dbContext.Configuration.AutoDetectChangesEnabled = false;
                        bool flag = dbContext.PayPalTransactions.AsNoTracking().Count(j => j.TransactionId == a.TransactionID) == 0;
                        dbContext.Configuration.AutoDetectChangesEnabled = true;
                        if (flag)
                        {
                            var detail = this.ImsService.PayPayTransaction(PaypalTransactionDetails);
                            // pptlist.Add(detail);
                            dbContext.Insert <PayPalTransaction>(detail);
                        }
                    }
                });
                // dbContext.PayPalTransactions.AddRange(pptlist);
                // dbContext.SaveChanges();
            }
            return(id);
        }
Ejemplo n.º 2
0
        public string PaymentTransactionProcessLongRunningAction(string id, int PaypalApi, string RangeDate)
        {
            PaypalApi paypalApi = this.ImsService.GetPaypalApi(PaypalApi);

            this.ImsService.PayPalHelper(paypalApi);

            string dataRange = RangeDate;

            string[] date = dataRange.Split(new char[] { '-' });

            DateTime startDate = DateTime.Parse(date[0].Trim());
            DateTime endDate   = DateTime.Parse(date[1].Trim());

            IEnumerable <PaymentTransactionSearchResultType> PaypalTransactionSearch = this.ImsService.ApiTransactionSearch(startDate, endDate);
            var total = PaypalTransactionSearch.Count <PaymentTransactionSearchResultType>();


            int i = 0;

            foreach (var item in PaypalTransactionSearch)
            {
                GetTransactionDetailsResponseType PaypalTransactionDetails = this.ImsService.ApiTransactionDetail(item);
                if (PaypalTransactionDetails.Ack.Equals(AckCodeType.SUCCESS))
                {
                    i++;
                    int d = Precentage(i, total);

                    lock (syncRoot)
                    {
                        ProcessStatus[id] = d;
                    }


                    /*TransactionDetailRequest request = new TransactionDetailRequest
                     * {
                     *  TransactionID = item.TransactionID
                     * };*/

                    PaymentTransactionRequest request = new PaymentTransactionRequest
                    {
                        TransactionID = item.TransactionID
                    };
                    if (this.ImsService.GetPaymentTransactionList(request).Count() == 0)
                    {
                        var detail = this.ImsService.PaymentTransaction(PaypalTransactionDetails);

                        using (var dbContext = new ImsDbContext())
                        {
                            dbContext.Insert <Evisou.Ims.Contract.Model.PayPal.PaymentTransactionType>(detail);
                        }
                    }
                }
            }

            return(id);
        }