Beispiel #1
0
        public IActionResult AddPayment(string payment)
        {
            string pattern1   = @"delete";
            string pattern2   = @"add";
            string validate   = payment;
            Match  match      = Regex.Match(validate, pattern1);
            var    paymentId  = Regex.Match(payment, @"\d+").Value;
            string helperType = Regex.Match(payment, pattern2).Value;

            HttpContext.Session.SetString("HelperType", helperType);
            HttpContext.Session.SetString("PaymentId", paymentId);

            if (match.Success)
            {
                var        result      = Int32.Parse(paymentId);
                dm.Payment paymentInfo = new dm.Payment
                {
                    PaymentId = result
                };
                PaymentHelper.DeletePaymentByPaymentId(paymentInfo);

                return(RedirectToAction("ChangePayment", "Home"));
            }
            return(RedirectToAction("AddPaymentView", "Home"));
        }
        // In the user homepage when payment is selected, userId is passed in PaymentViewModel format
        public List <PaymentViewModel> GetAllPayments(PaymentViewModel paymentView)
        {
            dm.Payment        paymentDomainModel = createModel.MappingPayment(paymentView);
            List <dm.Payment> domainPaymentList  = PaymentHelper.GetPaymentById(paymentDomainModel);

            return(createModel.MappingView(domainPaymentList));
        }
        // add requires all properties, delete only needs
        public bool AddOrDeletePayments(PaymentViewModel paymentView)
        {
            dm.Payment paymentDomainModel = createModel.MappingPayment(paymentView);
            dm.User    getUser            = UserHelper.GetUserInfoByIdForPayment(paymentDomainModel);
            var        valCheckAdd        = validator.ValidateNewPayment(paymentDomainModel);

            if (paymentView.HelperType == "add")
            {
                if (valCheckAdd)
                {
                    var addedPayment = new dm.Payment
                    {
                        PaymentId  = paymentDomainModel.PaymentId,
                        CCNumber   = paymentDomainModel.CCNumber,
                        CCUserName = paymentDomainModel.CCUserName,
                        Month      = paymentDomainModel.Month,
                        Year       = paymentDomainModel.Year,
                        CVV        = paymentDomainModel.CVV,

                        User = new User
                        {
                            UserId    = getUser.UserId,
                            Username  = getUser.Username,
                            Password  = getUser.Password,
                            Firstname = getUser.Firstname,
                            Lastname  = getUser.Lastname,
                            Email     = getUser.Email
                        }
                    };
                    PaymentHelper.AddPaymentById(addedPayment);
                    return(true);
                }
                return(false);
            }
            PaymentHelper.DeletePaymentByPaymentId(paymentDomainModel);
            return(true);
        }