public ActionResult Transfer(TransferModel 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.CardId = cardId; CardAccount c = service.GetCardAccountById(cardId); if (c == null) { ModelState.Clear(); ModelState.AddModelError("CustomError", "Карта не найдена"); return(View(paymentInfo)); } paymentInfo.CardNumber = 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 targetCard = service.GetCardAccountByNumber(paymentInfo.TargetCardAccountNumber); if (targetCard == null) { ModelState.Clear(); ModelState.AddModelError("CustomError", "Не найдена карта с таким номером"); return(View(paymentInfo)); } var bankAccount = service.GetBankAccountById(c.BankAccountID); var targetBankAccount = service.GetBankAccountById(targetCard.BankAccountID); if (targetBankAccount == null || bankAccount == null) { ModelState.Clear(); ModelState.AddModelError("CustomError", "Ошибка базы"); return(View(paymentInfo)); } paymentInfo.TargetCardAccountId = targetCard.CardAccountID; if (targetBankAccount.BankAccountID == bankAccount.BankAccountID) { ModelState.Clear(); ModelState.AddModelError("CustomError", "Нельзя переводить на этот же счет"); return(View(paymentInfo)); } var currency = service.GetCurrencyById(bankAccount.CurrencyID); var targetCurrency = service.GetCurrencyById(targetBankAccount.CurrencyID); if (currency.CurrencyID != targetCurrency.CurrencyID) { 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("ConfirmTransfer", paymentInfo)); } else { return(View(paymentInfo)); } }