Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("SponsorTransactionsID,SponsorID,BankName,TransactionDate,TrackingNumber,LateFourNumbersOfBankCard,Amount")] SponsorTransaction sponsorTransaction)
        {
            if (id != sponsorTransaction.SponsorTransactionsID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    await sponsors.UpdateTransactionAsync(sponsorTransaction);

                    await sponsors.saveAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SponsorTransactionExists(sponsorTransaction.SponsorTransactionsID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["SponsorID"] = new SelectList(await sponsors.GetAllAsync(), "SponsorID", "Name", sponsorTransaction.SponsorID);
            return(View(sponsorTransaction));
        }
Пример #2
0
 public async Task <bool> IsExistTransactionAsync(SponsorTransaction sponsorTransaction)
 {
     try
     {
         SponsorTransaction b = await GetTransactionAsync(sponsorTransaction);
     }
     catch (NotFoundException)
     {
         return(false);
     }
     return(true);
 }
Пример #3
0
        public async Task <bool> UpdateTransactionAsync(SponsorTransaction sponsorTransaction)
        {
            if (!(await IsExistTransactionAsync(sponsorTransaction)))
            {
                throw new NotFoundException();
            }

            try
            {
                db.SponsorTransactions.Update(sponsorTransaction);
                return(true);
            }
            catch (System.Exception)
            {
                throw;
            }
        }
        public async Task <bool> InsertErrorAsync(SponsorTransaction st, ErrorMessage Message)
        {
            var err = new SponsorTransactionError();

            err.SponsorName    = st.MySponsor?.Name.ToString() ?? "";
            err.Phone          = st.MySponsor?.PhoneNumber.ToString() ?? "";
            err.Date           = st.MyTransaction?.TransactionDate.Date.ToString() ?? st.MyReceipt?.TransactionDate.Date.ToString() ?? "";
            err.Time           = st.MyTransaction?.TransactionDate.TimeOfDay.ToString() ?? st.MyReceipt?.TransactionDate.TimeOfDay.ToString() ?? "";
            err.ReceiptNumber  = st.MyReceipt?.ReceiptNumber.ToString() ?? "";
            err.CardNumber     = st.MyTransaction?.LastFourNumbersOfBankCard.ToString() ?? "";
            err.TrackingNumber = st.MyTransaction?.TrackingNumber.ToString() ?? "";
            err.Amount         = st.MyTransaction?.Amount.ToString() ?? st.MyReceipt?.Amount.ToString() ?? "";
            err.ErrorMessage   = Message.ToString().Replace('_', ' ');
            err.ColleagueID    = st.ColleagueID;

            await InsertErrorAsync(err);

            return(true);
        }
        public async Task <bool> IsExistTransactionAsync(SponsorTransaction st)
        {
            if (st.MyTransaction == null)
            {
                return(true);
            }

            try
            {
                db.BankTransactions
                .Include(x => x.Transaction)
                .Where(x => x.Transaction.Amount == st.MyTransaction.Amount &&
                       x.Transaction.LastFourNumbersOfBankCard.ToString().Contains(st.MyTransaction.LastFourNumbersOfBankCard.ToString()) &&
                       x.Transaction.TrackingNumber.ToString().Contains(st.MyTransaction.TrackingNumber.ToString()) &&
                       x.Transaction.TransactionDate == st.MyTransaction.TransactionDate);
            }
            catch (NotFoundException)
            {
                return(false);
            }
            return(true);
        }
Пример #6
0
        public async Task <SponsorTransaction> GetTransactionAsync(SponsorTransaction sponsorTransaction)
        {
            try
            {
                var x = (await GetAllTransactionBySponsorIdAsync(sponsorTransaction.SponsorID)).ToList();

                if (sponsorTransaction.MyTransaction != null)
                {
                    x = x.Where(m => m.MyTransaction != null).ToList();
                    x = x.Where(m => m.MyTransaction.TransactionDate == sponsorTransaction.MyTransaction.TransactionDate
                                &&
                                m.MyTransaction.Amount == sponsorTransaction.MyTransaction.Amount
                                &&
                                m.MyTransaction.LastFourNumbersOfBankCard == sponsorTransaction.MyTransaction.LastFourNumbersOfBankCard
                                &&
                                m.MyTransaction.TrackingNumber == sponsorTransaction.MyTransaction.TrackingNumber).ToList();
                }
                else if (sponsorTransaction.MyReceipt != null)
                {
                    x = x.Where(m => m.MyReceipt != null).ToList();
                    x = x.Where(m => m.MyReceipt.Amount == sponsorTransaction.MyReceipt.Amount
                                &&
                                m.MyReceipt.ReceiptNumber == sponsorTransaction.MyReceipt.ReceiptNumber
                                &&
                                m.MyReceipt.TransactionDate == sponsorTransaction.MyReceipt.TransactionDate).ToList();
                }
                else
                {
                    throw new NotFoundException();
                }

                return(x.First());
            }
            catch (System.Exception)
            {
                throw new NotFoundException();
            }
        }
Пример #7
0
        private async Task <bool> InsertTransactionValidateAsync(SponsorTransaction sponsorTransaction)
        {
            if (await IsExistTransactionAsync(sponsorTransaction))
            {
                throw new DuplicateTransactionException();
            }

            if (await new BankRepository(db).IsExistTransactionAsync(sponsorTransaction))
            {
                throw new DoNotExistBankTransactionException();
            }

            try
            {
                await db.SponsorTransactions.AddAsync(sponsorTransaction);

                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #8
0
        public async Task <IActionResult> Create(string id, [Bind("SponsorTransactionsID,SponsorID,ColleagueID,CauseOfSupport,OtherSupport,MyTransaction,MyReceipt")] SponsorTransaction sponsorTransaction,
                                                 string TransactionDate, bool TransactionType)
        {
            RedirectToActionResult view;

            if (id == "Colleague")
            {
                view = RedirectToAction("Details", "Colleague", new { id = sponsorTransaction.ColleagueID });
            }
            else if (id == "Sponsor")
            {
                view = RedirectToAction("Details", "Sponsor", new { id = sponsorTransaction.SponsorID });
            }
            else
            {
                ViewBag.err = new NotFoundException();
                return(View("Error"));
            }

            if (TransactionType)
            {
                ModelState["MyTransaction.TrackingNumber"].ValidationState            = ModelValidationState.Skipped;
                ModelState["MyTransaction.Amount"].ValidationState                    = ModelValidationState.Skipped;
                ModelState["MyTransaction.LastFourNumbersOfBankCard"].ValidationState = ModelValidationState.Skipped;
                sponsorTransaction.MyTransaction = null;
            }
            else
            {
                ModelState["MyReceipt.ReceiptNumber"].ValidationState = ModelValidationState.Skipped;
                ModelState["MyReceipt.Amount"].ValidationState        = ModelValidationState.Skipped;
                sponsorTransaction.MyReceipt = null;
            }

            if (ModelState.IsValid)
            {
                try
                {
                    DateTime date = Convert.ToDateTime(TransactionDate.ToAD());
                    if (TransactionType)
                    {
                        sponsorTransaction.MyReceipt.TransactionDate = date;
                    }
                    else
                    {
                        sponsorTransaction.MyTransaction.TransactionDate = date;
                    }
                }
                catch (Exception)
                {
                    this.SetViewMessage("Please Complete fields ...", WebMessageType.Warning);
                    return(view);
                }

                try
                {
                    this.SetViewMessage("A new transaction was registered successfully.", WebMessageType.Success);

                    if (!(await sponsors.InsertTransactionAsync(sponsorTransaction)))
                    {
                        this.SetViewMessage("A new transaction was registered as Error.", WebMessageType.Warning);
                    }

                    await sponsors.saveAsync();
                }
                catch (Exception ex)
                {
                    this.SetViewMessage(ex.Message, WebMessageType.Danger);
                }
            }
            else
            {
                this.SetViewMessage("Please Complete fields ...", WebMessageType.Warning);
            }
            return(view);
        }
Пример #9
0
        public async Task <bool> InsertTransactionAsync(SponsorTransaction st)
        {
            Sponsor mySponsor;

            try
            {
                mySponsor = await GetByIdAsync(st.SponsorID);

                st.MySponsor = mySponsor;

                if (mySponsor.ColleagueID != st.ColleagueID)
                {
                    await new ColleagueRepository(db)
                    .InsertErrorAsync(st, ErrorMessage.This_sponsor_is_related_to_another_colleague);

                    return(false);
                }
            }
            catch (NotFoundException ex)
            {
                await new ColleagueRepository(db)
                .InsertErrorAsync(st, ErrorMessage.Phone_number_not_entered);

                return(false);
            }

            if (st.MyTransaction != null)
            {
                bool valid = true;
                valid = valid && st.MyTransaction.Amount > 0;
                valid = valid && st.MyTransaction.LastFourNumbersOfBankCard.ToString().Length >= 4;
                valid = valid && st.MyTransaction.TrackingNumber.Length > 4;

                if (!valid)
                {
                    await new ColleagueRepository(db)
                    .InsertErrorAsync(st, ErrorMessage.Correct_the_type_of_input_information);

                    return(false);
                }
            }
            else if (st.MyReceipt != null)
            {
                bool valid = true;
                valid = valid && st.MyReceipt.Amount > 0;
                valid = valid && st.MyReceipt.ReceiptNumber.ToString().Length > 2;

                if (!valid)
                {
                    await new ColleagueRepository(db)
                    .InsertErrorAsync(st, ErrorMessage.Correct_the_type_of_input_information);

                    return(false);
                }
            }
            else
            {
                await new ColleagueRepository(db)
                .InsertErrorAsync(st, ErrorMessage.No_transaction_information_entered);

                return(false);
            }

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

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

                return(false);
            }

            return(true);
        }
Пример #10
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);
        }