/// <summary> /// есть ли на карточке card value число денег в валюте currency /// </summary> /// <param name="card"></param> /// <param name="currency"></param> /// <param name="value"></param> /// <returns></returns> public static bool IsMoneyAvailable(Card card, Currency currency, decimal value) { if (value <= 0) { return false; } if (card == null) { throw new Exception("Current card does not exist!"); } try { if (currency.Id != card.Currency.Id) { decimal converted = PaymentDAL.Instance.GetValueForCard(card, currency, value); return card.Balance - converted >= 0; } return card.Balance - value >= 0; } catch (Exception) { return false; } }
public Card CreateCard(Card item) { return this.Core.CreateCard( item.Name, item.IdUser, item.Budget, item.Expenses); }
public void Card_ValidObjectIsConstructed() { Card card = new Card(CardValue.Ace, CardSuit.Clubs); Assert.AreEqual(CardValue.Ace, card.Value); Assert.AreEqual(CardSuit.Clubs, card.Suit); card = new Card(CardValue.Five, CardSuit.Hearts); Assert.AreEqual(CardValue.Five, card.Value); Assert.AreEqual(CardSuit.Hearts, card.Suit); }
public void Card_ColorIsCorrectlyDetermined() { Card diamond = new Card(CardValue.Ace, CardSuit.Diamonds); Assert.AreEqual(CardColor.Red, diamond.Color); Card heart = new Card(CardValue.Ace, CardSuit.Hearts); Assert.AreEqual(CardColor.Red, heart.Color); Card club = new Card(CardValue.Ace, CardSuit.Clubs); Assert.AreEqual(CardColor.Black, club.Color); Card spade = new Card(CardValue.Ace, CardSuit.Spades); Assert.AreEqual(CardColor.Black, spade.Color); }
public static void ProcessPayment(Card fromAccount, Payment payment, decimal valueToPay) { if (fromAccount == null || valueToPay < 0) { throw new Exception("Error while processing payment"); } payment.FromAccount = fromAccount; payment.TotalAmount = valueToPay; payment.PaymentDate = DateTime.Now; //Doing transaction. PaymentDAL.Instance.PerformTransaction(payment); }
public static void ProcessPayment(Card fromAccount, Card toAccount, decimal valueToPay, string personalNumber) { if (fromAccount == null || toAccount == null || valueToPay < 0) { throw new Exception("Error while processing payment"); } Payment payment = new Payment(); payment.Currency = fromAccount.Currency; payment.FromAccount = fromAccount; payment.PaymentDate = DateTime.Now; payment.ToAccount = toAccount; payment.TotalAmount = Math.Round(valueToPay, 5); payment.PersonalInformation = personalNumber; //Doing transaction. PaymentDAL.Instance.PerformTransaction(payment); }
public ActionResult AddCard(int clientId, Card card) { if (clientId < 0 && card == null) { RedirectToInternalError(); } if (!ModelState.IsValid) return AddCard(clientId); try { if (!CardDAL.Instance.AddCard(clientId, card)) return RedirectToInternalError(); } catch (Exception) { return RedirectToInternalError(); } finally { ViewData.Remove("clientId"); ViewData.Remove("cardsId"); } return RedirectToAction("Index", "User"); }
public Card Put(Card item) { return this._helper.UpdateCard(item); }
public Card Post(Card item) { return this._helper.CreateCard(item); }
public ActionResult EditCard(Card card) { if (card == null) { RedirectToInternalError(); } ModelState.Remove("CardNumber"); ModelState.Remove("Currency.Rate"); if (string.IsNullOrEmpty(card.CardNumber) || !Regex.IsMatch(card.CardNumber, "^[0-9]{16}$")) { ModelState.AddModelError("CardNumber", "Incorrect card number format. Should be 16 numbers."); } if (!ModelState.IsValid) return EditCard(card.Id); CardDAL.Instance.UpdateCard(card); return RedirectToAction("CardsManagment"); }
public Card UpdateCard(Card item) { return this.Core.UpdateCard( item.Id, item.Name, item.Budget, item.Expenses); }