Ejemplo n.º 1
0
        public async Task <bool> InsertTransactionAsync(DataRow row, int ColleagueID)
        {
            var st = new SponsorTransaction();

            if (row["Phone"].ToString() == string.Empty || row["Phone"].ToString().Length != 10)
            {
                await new ColleagueRepository(db)
                .InsertErrorAsync(row, ErrorMessage.Phone_number_not_entered, ColleagueID);
            }

            long phoneNumber = long.Parse(row["Phone"].ToString());

            Sponsor mySponsor;

            try
            {
                mySponsor = await GetByPhoneNumberAsync(phoneNumber);

                if (mySponsor.ColleagueID != ColleagueID)
                {
                    await new ColleagueRepository(db)
                    .InsertErrorAsync(row, ErrorMessage.This_sponsor_is_related_to_another_colleague, ColleagueID);
                }
            }
            catch (NotFoundException)
            {
                mySponsor             = new Sponsor();
                mySponsor.ColleagueID = ColleagueID;
                mySponsor.PhoneNumber = phoneNumber;
                mySponsor.Name        = row["SponsorName"].ToString();
                if (mySponsor.Name == string.Empty)
                {
                    mySponsor.Name = "Undefine";
                }

                await InsertAsync(mySponsor);
                await saveAsync();

                mySponsor = await GetByPhoneNumberAsync(phoneNumber);

                if (mySponsor == null)
                {
                    await new ColleagueRepository(db)
                    .InsertErrorAsync(row, ErrorMessage.There_is_a_problem_when_adding_a_new_sponsor, ColleagueID);
                }
            }

            try
            {
                st.SponsorID   = mySponsor.SponsorID;
                st.ColleagueID = ColleagueID;

                //DateTime date = Convert.ToDateTime(row["Date"].ToString().ToAD()).Date;
                DateTime date = Convert.ToDateTime(row["Date"].ToString()).Date;
                TimeSpan time;
                try
                {
                    time = TimeSpan.Parse(row["Time"].ToString());
                }
                catch (Exception)
                {
                    time = Convert.ToDateTime(row["Time"].ToString()).TimeOfDay;
                }

                if (row["CardNumber"].ToString() != "" && row["TrackingNumber"].ToString() != "")
                {
                    st.MyTransaction        = new BankData();
                    st.MyTransaction.Amount = Convert.ToDouble(row["Amount"]);
                    st.MyTransaction.LastFourNumbersOfBankCard = Convert.ToInt16(row["CardNumber"]);
                    st.MyTransaction.TrackingNumber            = row["TrackingNumber"].ToString();
                    st.MyTransaction.TransactionDate           = date + time;
                }
                else if (row["ReceiptNumber"].ToString() != "")
                {
                    st.MyReceipt                 = new ReceiptData();
                    st.MyReceipt.Amount          = Convert.ToDouble(row["Amount"]);
                    st.MyReceipt.TransactionDate = date + time;
                }
                else
                {
                    await new ColleagueRepository(db)
                    .InsertErrorAsync(row, ErrorMessage.No_transaction_information_entered, ColleagueID);
                }
            }
            catch (Exception)
            {
                await new ColleagueRepository(db)
                .InsertErrorAsync(row, ErrorMessage.Correct_the_type_of_input_information, ColleagueID);
            }

            try
            {
                await InsertTransactionValidateAsync(st);
            }
            catch (DuplicateTransactionException)
            {
                await new ColleagueRepository(db)
                .InsertErrorAsync(row, ErrorMessage.Duplicate, ColleagueID);

                return(false);
            }
            catch (DoNotExistBankTransactionException)
            {
                await new ColleagueRepository(db)
                .InsertErrorAsync(row, ErrorMessage.This_transaction_is_not_available_in_bank_transactions, ColleagueID);

                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
 public async Task <bool> IsExistAsync(Sponsor sponsor)
 {
     return(await IsExistAsync(sponsor.PhoneNumber) || await IsExistAsync(sponsor.ColleagueID));
 }