Example #1
0
    protected virtual void InternalIncreaseInventory(InventoryStateModel stateModel, int quantity, bool decreaseSold)
    {
        if (quantity < 0)
        {
            throw new DaprException("Quantity should not be less than 0.");
        }

        if (decreaseSold && stateModel.Sold - quantity < 0)
        {
            throw new DaprException("Target Sold cannot be less than 0.");
        }

        stateModel.Inventory = checked (stateModel.Inventory + quantity);

        if (decreaseSold)
        {
            stateModel.Sold -= quantity;
        }
    }
Example #2
0
    protected virtual void InternalReduceInventory(InventoryStateModel stateModel, int quantity, bool increaseSold)
    {
        if (quantity < 0)
        {
            throw new DaprException("Quantity should not be less than 0.");
        }

        if (quantity > stateModel.Inventory)
        {
            throw new DaprException("Insufficient inventory.");
        }

        if (increaseSold)
        {
            stateModel.Sold = checked (stateModel.Sold + quantity);
        }

        stateModel.Inventory -= quantity;
    }
Example #3
0
 public InventoryState(GameStateModel model, GameStateView view) : base(model, view)
 {
     _webService = GameController.Instance.WebService;
     _view       = View as InventoryStateView;
     _model      = Model as InventoryStateModel;
 }
Example #4
0
 protected virtual async Task SetInventoryStateAsync(InventoryStateModel state)
 {
     await StateManager.SetStateAsync(InventoryStateName, state);
 }