public void BankAccount_Should_GetAccount_By_Id()
        {
            //Arrange
            var effortContext = new BankSystemContext(Effort.DbConnectionFactory.CreateTransient());
            var mapperMock    = new Mock <IMapper>();

            var user = new ApplicationUser()
            {
                PasswordHash = "1234",
                PhoneNumber  = "12455",
                FirstName    = "asdfgh",
                LastName     = "lastName",
                UserName     = "******",
                Email        = "*****@*****.**"
            };

            effortContext.Users.Add(user);

            var bank = new BankAccountAddAspModel()
            {
                BankAccountType = (BankAccountType)1,
                Amount          = 12345,
                Currency        = (Currency)973,
                OwnerId         = user.Id,
                IsDeleted       = false
            };

            var bankMock = new BankAccount()
            {
                BankAccountType = (BankAccountType)1,
                Amount          = 12345,
                Currency        = (Currency)973,
                OwnerId         = user.Id,
                IsDeleted       = false
            };

            var bankReadModel = new BankAccountReadModel()
            {
                BankAccountType = (BankAccountType)1,
                Amount          = 12345,
                Currency        = (Currency)973,
                OwnerId         = user.Id,
                IsDeleted       = false
            };

            mapperMock.Setup(x => x.Map <BankAccount>(It.IsAny <BankAccountAddAspModel>()))
            .Returns(bankMock);

            mapperMock.Setup(x => x.Map <BankAccountReadModel>(It.IsAny <BankAccount>()))
            .Returns(bankReadModel);

            var sut = new BankAccountServices(effortContext, mapperMock.Object);

            sut.AddBankAccount(bank);
            //Act
            var result = sut.GetBankAccountByID(bankMock.Id.ToString());

            Assert.IsInstanceOfType(result, typeof(BankAccountReadModel));
            Assert.IsTrue(result.OwnerId == bankMock.OwnerId);
        }
        public void BankAccountAddService_should_Add_ToDataBase_When_ToldTo()
        {// Tva ne e na Sashko , ne e i na Sashka
            //Arrange
            var effortContext = new BankSystemContext(Effort.DbConnectionFactory.CreateTransient());
            var mapperMock    = new Mock <IMapper>();
            var user          = new ApplicationUser()
            {
                PasswordHash = "1234",
                PhoneNumber  = "12455",
                FirstName    = "asdfgh",
                LastName     = "lastName",
                UserName     = "******",
                Email        = "*****@*****.**"
            };

            effortContext.Users.Add(user);

            var bank = new BankAccountAddAspModel()
            {
                // Id=1,
                BankAccountType = (BankAccountType)1,
                Amount          = 12345,
                Currency        = (Currency)973,
                OwnerId         = user.Id,
                IsDeleted       = false
            };

            var bankMock = new BankAccount()
            {
                // Id = 1,
                BankAccountType = (BankAccountType)1,
                Amount          = 12345,
                Currency        = (Currency)973,
                OwnerId         = user.Id,
                IsDeleted       = false
            };

            mapperMock.Setup(x => x.Map <BankAccount>(It.IsAny <BankAccountAddAspModel>()))
            .Returns(bankMock);

            //Act
            var sut = new BankAccountServices(effortContext, mapperMock.Object);

            sut.AddBankAccount(bank);



            // Assert

            Assert.AreEqual(1, effortContext.BankAccounts.Count());
        }
 public ActionResult UploadPaymentInfo(HttpPostedFileBase image)
 {
     if (image != null)
     {
         using (var db = new ApplicationDbContext())
         {
             var         userId            = User.Identity.GetUserId();
             var         AppUser           = db.Users.Find(userId);
             BankAccount UserBankAccount   = BankAccountServices.GetUserBankAccount(AppUser);
             var         outgoingdonations = (from d in db.Donations where d.DonorId == UserBankAccount.Id && d.IsOpen == false select d);
             Donation    donation          = null;
             if (outgoingdonations.Count() == 1)
             {
                 donation = outgoingdonations.First();
             }
             Payment NewPay = new Payment
             {
                 DonationPack = donation,
                 CreationDate = DateTime.Now,
                 Confirmed    = false,
             };
             db.Payments.Add(NewPay);
             POPImage PopImg = new POPImage();
             PopImg.Payment = NewPay;
             PopImg.Image   = new byte[image.ContentLength];
             image.InputStream.Read(PopImg.Image, 0, image.ContentLength);
             db.POPImages.Add(PopImg);
             db.SaveChanges();
         }
         return(RedirectToAction("Welcome", "Home"));
     }
     else
     {
         return(HttpNotFound("Something went wrong"));
     }
 }
Esempio n. 4
0
        internal ActionResult Homepage()
        {
            ApplicationUser AppUser;
            // Get data
            var UserId = User.Identity.GetUserId();

            AppUser = DbAccessHandler.DbContext.Users.Find(UserId);
            var            UserBankAccount   = BankAccountServices.GetUserBankAccount(AppUser);
            var            IncomingDonations = DonationServices.GetIncomingAccountDonations(UserBankAccount);
            List <Payment> IncomingPayments  = new List <Payment>();

            foreach (Donation d in IncomingDonations)
            {
                Payment p = PaymentServices.GetPaymentForDonation(d);
                if (PaymentServices.IsNotNull(p))
                {
                    IncomingPayments.Add(p);
                }
            }

            var            OutgoingDonations = DonationServices.GetOutgoingAccountDonations(UserBankAccount);
            List <Payment> OutgoingPayments  = new List <Payment>();

            foreach (Donation d in OutgoingDonations)
            {
                Payment p1 = PaymentServices.GetPaymentForDonation(d);
                if (PaymentServices.IsNotNull(p1))
                {
                    OutgoingPayments.Add(p1);
                }
            }


            List <Donation> _pendingIncomingDonations = new List <Donation>(2);
            List <Payment>  _pendingIncomingpayments  = new List <Payment>(2);

            Donation PendingOutgoingDonation = null;
            Payment  PendingOutgoingPayment  = null;

            if (UserBankAccount.IsReceiver == false)
            {
                if (OutgoingDonations.Where(m => m.IsOpen == false).Count() > 0)
                {
                    PendingOutgoingDonation = OutgoingDonations.Where(m => m.IsOpen == false).First();
                }

                if (OutgoingPayments.Where(m => m.Confirmed == false).Count() > 0)
                {
                    PendingOutgoingPayment = OutgoingPayments.Where(m => m.Confirmed == false).First();
                }
            }
            else
            {
                var IDnts = IncomingDonations.Where(m => m.IsOpen == false).ToList();
                if (IDnts != null)
                {
                    _pendingIncomingDonations = IDnts;
                }
                var IPymts = IncomingPayments.Where(m => m.Confirmed == false).ToList();
                if (IPymts != null)
                {
                    _pendingIncomingpayments = IPymts;
                }
            }

            //Get Users personal Information
            var FirstName   = AppUser.FirstName;
            var LastName    = AppUser.LastName;
            var PhoneNumber = AppUser.PhoneNumber;

            if (AppUser.PhoneNumberConfirmed == false)
            {
                PhoneNumber = PhoneNumber + " (Unconfirmed)";
            }
            var Emailaddress = AppUser.Email;

            //Add objects to the data dictionary

            //Personal Information
            UserDetails Ud = new UserDetails
            {
                FirstName   = FirstName,
                LastName    = LastName,
                PhoneNumber = PhoneNumber,
                UserName    = Emailaddress
            };

            ViewBag.UserDetails = Ud;

            //Account Information
            BankAccountDetails Bd = new BankAccountDetails
            {
                AccountTitle  = UserBankAccount.AccountTitle,
                AccountNumber = UserBankAccount.AccountNumber,
                BankName      = UserBankAccount.Bank,
                IsReceiver    = UserBankAccount.IsReceiver
            };

            ViewBag.BankAccountDetails = Bd;

            //Outgoing Payments Information
            ViewBag.OutgoingPayments = OutgoingPayments.Where(m => m.Confirmed == true).Select(m => m.CreationDate).ToList();

            //Incoming Payments Information
            ViewBag.IncomingPayments = IncomingPayments.Where(m => m.Confirmed == true).Select(m => m.CreationDate).ToList();

            //Pending Donors Information
            var PendingIncomingDonations = new List <Dictionary <string, object> >();

            if (_pendingIncomingDonations.Count > 0)
            {
                foreach (Donation d in _pendingIncomingDonations)
                {
                    var DonationId    = d.Id;
                    var Name          = d.Donor.AccountTitle;
                    var AccountNumber = d.Donor.AccountNumber;
                    var BankName      = d.Donor.Bank;
                    var Payment       = _pendingIncomingpayments.Where(p => p.DonationPack.Id == d.Id).FirstOrDefault();

                    Dictionary <string, object> set = new Dictionary <string, object>();
                    set.Add("DonationId", DonationId);
                    set.Add("Name", Name);
                    set.Add("AccountNumber", AccountNumber);
                    set.Add("BankName", BankName);
                    if (Payment != null)
                    {
                        set.Add("PaymentId", Payment.Id);
                        set.Add("Confirmed", Payment.Confirmed);
                    }
                    else
                    {
                        set.Add("PaymentId", null);
                        set.Add("Confirmed", null);
                    }
                    PendingIncomingDonations.Add(set);
                }
            }
            ViewBag.PendingIncomingDonations = PendingIncomingDonations;

            //Pending Outgoing Donation View
            DonationDetails DonationDetails = null;

            if (PendingOutgoingDonation != null)
            {
                DonationDetails                        = new DonationDetails();
                DonationDetails.DonationId             = PendingOutgoingDonation.Id;
                DonationDetails.RecipientFullName      = PendingOutgoingDonation.Ticket.TicketHolder.AccountTitle;
                DonationDetails.RecipientAccountNumber = PendingOutgoingDonation.Ticket.TicketHolder.AccountNumber;
                DonationDetails.RecipientBankName      = PendingOutgoingDonation.Ticket.TicketHolder.Bank;
                DonationDetails.DonationSetupDate      = PendingOutgoingDonation.CreationDate;
            }
            ViewBag.PendingOutgoingDonation = DonationDetails;
            PaymentDetails PayDetails = null;

            if (PendingOutgoingPayment != null)
            {
                PayDetails           = new PaymentDetails();
                PayDetails.PaymentId = PendingOutgoingPayment.Id;
                PayDetails.Status    = PendingOutgoingPayment.Confirmed;
                PayDetails.Date      = PendingOutgoingPayment.CreationDate.ToShortDateString();
            }
            ViewBag.PendingPayDetails = PayDetails;

            //Pending Outgoing Payment Information
            ViewBag.PendingOutgoingPayment = PendingOutgoingPayment;

            return(View("HomePage"));
        }