Exemplo n.º 1
0
        public Task SyncAsync()
        {
            Task tsk = Task.Run(
                () =>
            {
                string paysYear = _paymentYear.Substring(2, 2);
                RepositoryBase <Payment> paymentRepository = _unitOfWork.Payments;
                var sgePayments = paymentRepository.GetAll();
                var irsPayments = new PaymentTableAdapter(Properties.Settings.Default.IrsDbPath,
                                                          paysYear).GetData();
                double count   = irsPayments.Count;
                double current = 0.0;

                foreach (Payment irsPayment in irsPayments)
                {
                    bool exist = sgePayments.Any(p => p.PaymentNo == irsPayment.PaymentNo);
                    if (!exist)         //If new Add it
                    {
                        Payment newSgePayment = new Payment()
                        {
                            PaymentNo    = irsPayment.PaymentNo,
                            AccountNo    = irsPayment.AccountNo,
                            ContractNo   = irsPayment.ContractNo,
                            Renewal      = irsPayment.Renewal,
                            Name         = irsPayment.Name,
                            PayDate      = irsPayment.PayDate,
                            PaymentType  = irsPayment.PaymentType,
                            PaymentFor1  = irsPayment.PaymentFor1,
                            PaymentFor2  = irsPayment.PaymentFor2,
                            TotalPayment = irsPayment.TotalPayment,
                            Rent         = irsPayment.Rent,
                            Deposit      = irsPayment.Deposit,
                            Maintenance  = irsPayment.Maintenance,
                            Others       = irsPayment.Others,
                            Posted       = irsPayment.Posted,
                            DebitAccount = irsPayment.DebitAccount,
                            PayCode      = irsPayment.PayCode,
                        };
                        paymentRepository.Add(newSgePayment);
                    }
                    else         //Otherwise udpate it.
                    {
                        var existingPayment = sgePayments.Single(p => p.PaymentNo == irsPayment.PaymentNo);

                        existingPayment.AccountNo    = irsPayment.AccountNo;
                        existingPayment.ContractNo   = irsPayment.ContractNo;
                        existingPayment.Renewal      = irsPayment.Renewal;
                        existingPayment.Name         = irsPayment.Name;
                        existingPayment.PayDate      = irsPayment.PayDate;
                        existingPayment.PaymentType  = irsPayment.PaymentType;
                        existingPayment.PaymentFor1  = irsPayment.PaymentFor1;
                        existingPayment.PaymentFor2  = irsPayment.PaymentFor2;
                        existingPayment.TotalPayment = irsPayment.TotalPayment;
                        existingPayment.Rent         = irsPayment.Rent;
                        existingPayment.Deposit      = irsPayment.Deposit;
                        existingPayment.Maintenance  = irsPayment.Maintenance;
                        existingPayment.Others       = irsPayment.Others;
                        existingPayment.Posted       = irsPayment.Posted;
                        existingPayment.DebitAccount = irsPayment.DebitAccount;
                        existingPayment.PayCode      = irsPayment.PayCode;
                    }
                    current++;
                    double progress = (current / count) * 100;
                    RaiseProgress(progress);
                }
            }
                );

            return(tsk);
        }