Example #1
0
        public ActionResult Arbitrary(ArbitraryPaymentModel paymentInfo, FormCollection collection)
        {
            int cardId;

            if (!int.TryParse(collection["item.CardAccount.CardAccountID"], out cardId))
            {
                ModelState.Clear();
                ModelState.AddModelError("CustomError", "Карта не найдена");
                return(View(paymentInfo));
            }
            else if (ModelState.IsValid)
            {
                Customer customer = rep.Customers.GetSingle(WebSecurity.CurrentUserId);
                if (customer.IsLocked)
                {
                    ModelState.Clear();
                    ModelState.AddModelError("CustomError", "Ваш аккаунт заблокирован");
                    return(View(paymentInfo));
                }
                paymentInfo.AccountCardId = cardId;
                CardAccount c = service.GetCardAccountById(cardId);
                if (c == null)
                {
                    ModelState.Clear();
                    ModelState.AddModelError("CustomError", "Карта не найдена");
                    return(View(paymentInfo));
                }
                paymentInfo.AccountCardNumber = CardAccountModule.ConvertCardNumberString(c.CardNumber);
                if (c.IsLocked)
                {
                    ModelState.Clear();
                    ModelState.AddModelError("CustomError", "Ваша платежная карта заблокирована");
                    return(View(paymentInfo));
                }
                if (c.ExpiredDate < Time.GetTime())
                {
                    c.Status = "Истек срок действия";
                    service.UpdateCardAccount(c);
                    ModelState.Clear();
                    ModelState.AddModelError("CustomError", "Истек срок действия карты");
                    return(View(paymentInfo));
                }
                var bankAccount = service.GetBankAccountById(c.BankAccountID);
                if (bankAccount == null)
                {
                    ModelState.Clear();
                    ModelState.AddModelError("CustomError", "Ошибка базы");
                    return(View(paymentInfo));
                }
                if (paymentInfo.Amount <= 0)
                {
                    ModelState.Clear();
                    ModelState.AddModelError("CustomError", "Сумма должна быть больше нуля");
                    return(View(paymentInfo));
                }
                if (!service.IsEnoughBalance(cardId, paymentInfo.Amount))
                {
                    ModelState.Clear();
                    ModelState.AddModelError("CustomError", "Недостаточно средств на счете");
                    return(View(paymentInfo));
                }

                return(RedirectToAction("ConfirmArbitrary", paymentInfo));
            }
            else
            {
                return(View(paymentInfo));
            }
        }
Example #2
0
        public ActionResult Create(MobileAutoPayModel model, FormCollection collection)
        {
            var custome = repo.Customers.GetSingle(WebSecurity.CurrentUserId);

            ViewBag.FirstName  = custome.FirstName;
            ViewBag.MiddleName = custome.MiddleName;
            ViewBag.LastName   = custome.LastName;

            string language = "ru";
            string culture  = "RU";

            Thread.CurrentThread.CurrentCulture   = CultureInfo.GetCultureInfo(string.Format("{0}-{1}", language, culture));
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(string.Format("{0}-{1}", language, culture));

            DateTime date =
                DateTime.ParseExact(collection["StartDate"], "dd.MM.yyyy", CultureInfo.CurrentCulture);

            model.StartDate = date;
            ModelState.Clear();

            int cardId;

            if (!int.TryParse(collection["item.CardAccount.CardAccountID"], out cardId))
            {
                ModelState.Clear();
                ModelState.AddModelError("CustomError", "Карта не найдена");
                return(View(model));
            }
            else if (ModelState.IsValid)
            {
                if ((model.IntervalDays <= 0) && (model.IntervalHours <= 0) && (model.IntervalMinutes <= 0))
                {
                    ModelState.Clear();
                    ModelState.AddModelError("CustomError", "Интервал должен быть положительным");
                    return(View(model));
                }
                Customer customer = repo.Customers.GetSingle(WebSecurity.CurrentUserId);
                if (customer.IsLocked)
                {
                    ModelState.Clear();
                    ModelState.AddModelError("CustomError", "Ваш аккаунт заблокирован");
                    return(View(model));
                }
                model.CardAccountID = cardId;
                CardAccount c = service.GetCardAccountById(cardId);
                if (c == null)
                {
                    ModelState.Clear();
                    ModelState.AddModelError("CustomError", "Карта не найдена");
                    return(View(model));
                }
                model.CardNumber = CardAccountModule.ConvertCardNumberString(c.CardNumber);
                if (c.IsLocked)
                {
                    ModelState.Clear();
                    ModelState.AddModelError("CustomError", "Ваша платежная карта заблокирована");
                    return(View(model));
                }
                if (c.ExpiredDate < Time.GetTime())
                {
                    c.Status = "Истек срок действия";
                    service.UpdateCardAccount(c);
                    ModelState.Clear();
                    ModelState.AddModelError("CustomError", "Истек срок действия карты");
                    return(View(model));
                }

                var bankAccount = service.GetBankAccountById(c.BankAccountID);
                if (bankAccount == null)
                {
                    ModelState.Clear();
                    ModelState.AddModelError("CustomError", "Ошибка базы");
                    return(View(model));
                }
                if (bankAccount.CurrencyID != 1)
                {
                    ModelState.Clear();
                    ModelState.AddModelError("CustomError", "Оплату мобильной связи можно проводить только беларусскими рублями");
                    return(View(model));
                }
                if (model.Amount <= 0)
                {
                    ModelState.Clear();
                    ModelState.AddModelError("CustomError", "Сумма должна быть больше нуля");
                    return(View(model));
                }
                if (!service.IsEnoughBalance(cardId, model.Amount))
                {
                    ModelState.Clear();
                    ModelState.AddModelError("CustomError", "Недостаточно средств на счете");
                    return(View(model));
                }
                model.StartDate = model.StartDate.AddMinutes(model.StartMinutes);
                model.StartDate = model.StartDate.AddHours(model.StartHours);
                return(RedirectToAction("ConfirmAutoPay", model));
            }
            else
            {
                return(View(model));
            }
        }