/// <summary> /// Validates that tender line fulfills limits configured for card type. /// </summary> /// <param name="context">The request context.</param> /// <param name="tenderLine">Payment information.</param> /// <returns>Collection of <see cref="DataValidationFailure"/>.</returns> private static IEnumerable <DataValidationFailure> ValidateCardTypeLimits(RequestContext context, TenderLine tenderLine) { List <DataValidationFailure> failures = new List <DataValidationFailure>(); CardTypeInfo cardTypeInfo = CardTypeHelper.GetCardTypeConfiguration(tenderLine.CardTypeId, context); if (cardTypeInfo == null) { failures.Add(new DataValidationFailure(DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_ObjectNotFound, "Card type with id '{0}' not found", tenderLine.CardTypeId)); } if (tenderLine.CashBackAmount < 0) { failures.Add(new DataValidationFailure(DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_InvalidCashBackAmount, "Cash back amount cannot be negative.")); } if (tenderLine.CashBackAmount != 0 && tenderLine.Amount < 0) { failures.Add(new DataValidationFailure(DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_AmountDueMustBePaidBeforeCheckout, "Cash back not allowed for refunds.")); } if (cardTypeInfo != null && tenderLine.CashBackAmount > cardTypeInfo.CashBackLimit) { string message = string.Format("Cash back amount for card type '{0}' exceed maximum allowed value {1}.", cardTypeInfo.TypeId, cardTypeInfo.CashBackLimit); failures.Add(new DataValidationFailure(DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_InvalidCashBackAmount, message)); } return(failures); }
public void AddElement(ICard element) { CheckIfDestroyed(); if (Zone != Zone.Board) { throw new InvalidOperationException($"Can only add elements to cards on the board"); } if (CardTypeHelper.IsElement(element.Type) == false) { throw new ArgumentException($"{element} is not an element"); } if (CardTypeHelper.IsElement(Type)) { throw new InvalidOperationException($"Cannot add an element to a {Type} card"); } if (CardTypeHelper.DoesElementDestroy(element.Type, Type)) { IsDestroyed = true; } else if (CardTypeHelper.DoesElementUpgrade(element.Type, Type)) { Type += (int)element.Type; _element = element.Type; } }
public void GetAttackedBy(ICard other) { if (Zone != Zone.Board || other.Zone != Zone.Board || CardTypeHelper.IsElement(other.Type) || CardTypeHelper.IsElement(Type)) { throw new InvalidOperationException($"Only cards on the board can fight"); } else if (CardTypeHelper.DoesUnitDestroy(other.Type, Type)) { IsDestroyed = true; } }
public Card(CardType type) { if (CardTypeHelper.IsBaseUnit(type)) { _baseType = type; _element = CardType.None; } else if (CardTypeHelper.IsElement(type)) { _element = type; _baseType = CardType.None; } else { throw new ArgumentException($"Cannot create a unit of type {type}"); } Type = type; IsDestroyed = false; }