public IActionResult PayWarehouse(PaymentHistoryVM paymentHistoryVM)
        {
            //when ModelState.IsValid equal to FALSE
            var errors = ModelState
                         .Where(x => x.Value.Errors.Count > 0)
                         .Select(x => new { x.Key, x.Value.Errors })
                         .ToArray();

            ViewBag.showMsg = true;
            string uNameIdWarehouse = _unitOfWork.PaymentBalance.GetAll().Where(a => a.IsWarehouseBalance).Select(a => a.UserNameId).FirstOrDefault();

            paymentHistoryVM.PaymentAddress = _unitOfWork.PaymentSentAddress.GetAll().Where(a => a.UserNameId == uNameIdWarehouse).Select(i => new SelectListItem
            {
                Text  = i.PaymentTypeAddress,
                Value = i.Id.ToString()
            });
            if (ModelState.IsValid)
            {
                _unitOfWork.PaymentHistory.Add(paymentHistoryVM.PaymentHistory);
                AddBalanceToWarehouse(paymentHistoryVM.PaymentHistory.Amount);
                _unitOfWork.Save();
                ViewBag.Success = true;
                return(View(paymentHistoryVM));
            }
            ViewBag.Success = false;
            return(View(paymentHistoryVM));
        }
        public IActionResult AddPayment()
        {
            string uNameId = (_unitOfWork.ApplicationUser.GetAll().Where(q => q.UserName == User.Identity.Name).Select(q => q.Id)).FirstOrDefault();

            ViewBag.uNameId = uNameId;
            PaymentHistoryVM paymentHistoryVM = new PaymentHistoryVM()
            {
                PaymentHistory = new PaymentHistory(),
                PaymentAddress = _unitOfWork.PaymentSentAddress.GetAll().Where(a => a.UserNameId == uNameId).Select(i => new SelectListItem
                {
                    Text  = i.PaymentTypeAddress + " - " + i.PaymentType,
                    Value = i.Id.ToString()
                })
            };

            ViewBag.ShowMsg     = 0;
            ViewBag.payoneermsg = false;
            return(View(paymentHistoryVM));
        }
        public IActionResult PayWarehouse()
        {
            //pay warehouse
            // get the user we pay to from payment balance
            string uNameIdWarehouse = _unitOfWork.PaymentBalance.GetAll().Where(a => a.IsWarehouseBalance).Select(a => a.UserNameId).FirstOrDefault();

            ViewBag.uNameIdWarehouse = uNameIdWarehouse;
            PaymentHistoryVM paymentHistoryVM = new PaymentHistoryVM()
            {
                PaymentHistory = new PaymentHistory(),
                //need to retrieve all addresses belong to an admin user
                PaymentAddress = _unitOfWork.PaymentSentAddress.GetAll().Where(a => a.IsAdmin).Select(i => new SelectListItem
                {
                    Text  = i.PaymentTypeAddress,//type and type address
                    Value = i.Id.ToString()
                })
            };

            ViewBag.showMsg = false;
            return(View(paymentHistoryVM));
        }
        public IActionResult AddPayment(PaymentHistoryVM paymentHistoryVM)
        {
            string uNameId = (_unitOfWork.ApplicationUser.GetAll().Where(q => q.UserName == User.Identity.Name).Select(q => q.Id)).FirstOrDefault();

            paymentHistoryVM.PaymentAddress = _unitOfWork.PaymentSentAddress.GetAll().Where(a => a.UserNameId == uNameId).Select(i => new SelectListItem
            {
                Text  = i.PaymentTypeAddress + " - " + i.PaymentType,
                Value = i.Id.ToString()
            });
            if (ModelState.IsValid)
            {
                PaymentSentAddress paymentSentAddress =
                    _unitOfWork.PaymentSentAddress.GetAll().Where(a => a.Id == paymentHistoryVM.PaymentHistory.SentFromAddressId).FirstOrDefault();
                if (paymentSentAddress.PaymentType == SD.PaymentPaypal)//then fees will apply
                {
                    paymentHistoryVM.PaymentHistory.Amount = paymentHistoryVM.PaymentHistory.Amount - SD.paypalOneTimeFee -
                                                             (paymentHistoryVM.PaymentHistory.Amount * SD.paypalPercentFees / 100);
                }
                _unitOfWork.PaymentHistory.Add(paymentHistoryVM.PaymentHistory);
                _unitOfWork.Save();
                ViewBag.ShowMsg = 1;
            }
            return(View(paymentHistoryVM));
        }