public IInventoryCollection Dispense(string id, IAmount amount, int count)
 {
     if (inventory.ContainsKey(id))
     {
         if (count >= inventory[id].GetCount())
         {
             if (inventory[id].GetItemPrice() * count >= amount.GetValue())
             {
                 inventory[id] = inventory[id].UpdateCount(count);
                 if (!soldItems.ContainsKey(id))
                 {
                     soldItems.Add(id, new SoldItemInventory(inventory[id].GetItem(), count));
                 }
                 else
                 {
                     soldItems[id].UpdateCount(count);
                 }
                 soldItemPrice.Add(id, count * inventory[id].GetItemPrice());
             }
             else
             {
                 logger.Error($"Not enough money to dispense {count} items of price {count* inventory[id].GetItemPrice()}");
             }
         }
         else
         {
             logger.Error("not enough item(s) to dispense");
         }
     }
     else
     {
         logger.Error("Item not present in machine");
     }
     return(this);
 }
 public Statement(DateTime date, AccountAction accountAction, IAmount amount, IAmount balance)
 {
     Date          = date;
     AccountAction = accountAction;
     Amount        = amount ?? throw new ArgumentNullException(nameof(amount));
     Balance       = balance ?? throw new ArgumentNullException(nameof(balance));
 }
Beispiel #3
0
 private Foodstuff(Guid id, string name, Uri imageUrl, IAmount baseAmount, IAmount amountStep) : base(id)
 {
     Name       = name;
     ImageUrl   = imageUrl;
     BaseAmount = baseAmount;
     AmountStep = amountStep;
 }
Beispiel #4
0
 public Transaction(IParticipant Payee, IParticipant Payer, IAmount Amount, DateTime Date)
 {
     this.Payee  = Payee;
     this.Payer  = Payer;
     this.Amount = Amount;
     this.Date   = Date;
 }
 public override void Initialization()
 {
     price       = FactoryManager.Build <Price>(node.GetNode("price"), GetContext());
     reward      = FactoryManager.Build <Reward>(node.GetNode("reward"), GetContext());
     requirement = FactoryManager.Build <Requirement>(node.GetNode("requirement"), GetContext());
     amount      = FactoryManager.Build <Amount>(node.GetNode("amount"), GetContext());
 }
Beispiel #6
0
        public void ShouldReturnFormattedStringWithWithdrawal(DateTime date, IAmount balance, IAmount amount)
        {
            var sut = new Statement(date, AccountAction.Withdrawal, amount, balance);

            var assert = $"| {date.ToShortDateString()} |  | {amount.ToString()} | {balance.ToString()} |";

            sut.ToString().Should().Be(assert);
        }
Beispiel #7
0
 static void Main(string[] args)
 {
     client = new XRPCClient("localhost", 9090);
     client.Options.ParameterFormater = new JsonPacket();//default messagepack
     henry = client.Create <IAmount>("henry");
     ken   = client.Create <IAmount>("ken");
     Test();
     Console.Read();
 }
        internal static void CommitAndRound(IAmount operation, IAmount destination, OperationType type, bool rollback)
        {
            var accountAmount   = Math.Round(destination.Amount, 2);
            var operationAmount = Math.Round(operation.Amount, 2);
            var sign1           = type == OperationType.Income ? 1.0 : -1.0;
            var sign2           = rollback ? -1.0 : 1.0;

            operation.Amount   = operationAmount;
            destination.Amount = Math.Round(accountAmount + sign1 * sign2 * operationAmount, 2);
        }
Beispiel #9
0
        public Form(ISettings settings, IRecordsStorage aggregator, IAdder adder, IAmountFactory factory)
        {
            this.settings   = settings;
            this.aggregator = aggregator;
            this.adder      = adder;
            this.factory    = factory;

            amount = factory.Create(selectedType);
            Types  = Enum.GetValues(typeof(Types)).Cast <Types>();
            UpdateCategories(selectedType);

            DateTime     = DateTime.Now;
            Descriptions = settings.Descriptions;
        }
Beispiel #10
0
 public void Add(IAmount amount) => _money       += amount.Value;
Beispiel #11
0
 public CallFailed(IAmount amount)
 {
     PayPenalty = amount;
 }
Beispiel #12
0
 public Transaction(IParticipant Payee, IParticipant Payer, IAmount Amount) : this(Payee, Payer, Amount, DateTime.Now)
 {
 }
Beispiel #13
0
 public RenewableResourceReward(RawNode node, IContext context)
     : base(node, context)
 {
     _amount = FactoryManager.Build <Amount>(node.GetNode("amount"), context);
 }
Beispiel #14
0
 public void Remove(IAmount amount)
 {
     _amount -= amount.Amount();
 }
Beispiel #15
0
 public void PaySalary(IAmount amount)
 {
     _amount += amount.Amount();
 }
 public IVendingMachineActions Dispense(string id, IAmount amount, int count)
 {
     inventory = inventory.Dispense(id, amount, count);
     return(this);
 }
Beispiel #17
0
 public SalaryPaymentOccured(IAmount amount)
 {
     this.Amount = amount;
 }
Beispiel #18
0
 public Account(IAmount amount, IStatementCollection statementCollection)
 {
     Balance             = amount ?? throw new ArgumentNullException(nameof(amount));
     StatementCollection = statementCollection ?? throw new ArgumentNullException(nameof(statementCollection));
 }
Beispiel #19
0
 public SimpleResourceReward(RawNode node, IContext context = null) : base(node, context)
 {
     amount = FactoryManager.Build <Amount>(node.GetNode("amount"), context);
 }
Beispiel #20
0
 public Transaction(DateTime getTime, IAmount credit, IAmount debit)
 {
     _getTime = getTime;
     _credit  = credit;
     _debit   = debit;
 }
Beispiel #21
0
 public CallPayment(IAmount callRate, CallRating rating)
 {
     _callRate = callRate;
     _rating   = rating;
 }
Beispiel #22
0
 public void Add(IAmount amount)
 {
     _amount += amount.Amount();
 }
Beispiel #23
0
 public void Increase(IAmount amount)
 {
     _amount += amount.Amount();
     World.Publish(new RentIncreased());
 }
 public static bool IsLessThan(IAmount a1, IAmount a2)
 {
     return(a1.Unit == a2.Unit && a1.Count < a2.Count);
 }
Beispiel #25
0
 public void Substract(IAmount amount) => _money -= amount.Value;
 public static IOption <IAmount> Substract(IAmount a1, IAmount a2)
 {
     return(CountOperation((c1, c2) => c1 - c2, a1, a2));
 }
 public static IOption <IAmount> Add(IAmount a1, IAmount a2)
 {
     return(CountOperation((c1, c2) => c1 + c2, a1, a2));
 }
Beispiel #28
0
 public void PaySalary(IAmount amount)
 {
     _amount += amount.Amount();
     World.Publish(new SalaryPaymentOccured(amount));
     World.Publish(new MoneyDeposited());
 }
        private static IOption <IAmount> CountOperation(Func <float, float, float> op, IAmount first, IAmount second)
        {
            var validOperation = first.Unit == second.Unit;
            var amount         = validOperation
                ? new Amount(op(first.Count, second.Count), first.Unit).ToOption()
                : Option.Empty <Amount>();

            return(amount.Map(a => a as IAmount));
        }
Beispiel #30
0
 public void Add(IAmount amount)
 {
     _amount += amount.Amount();
     World.Publish(new MoneyDeposited());
 }