Beispiel #1
0
        public void ExportFertilizer(Fertilizer fertilizer, string name)
        {
            if (this.CurrentLoad - fertilizer.Amount < 0)
            {
                throw new ArgumentException($"You can export up to {this.CurrentLoad}");
            }

            if (!fertilizer.Name.ToLower().Equals(this.CurrentFertilizer))
            {
                throw new ArgumentException($"You can export {this.CurrentFertilizer}");
            }

            if (fertilizer.Amount <= 0)
            {
                throw new ArgumentException("Please enter positive number");
            }

            if (this.CurrentFertilizer == null)
            {
                throw new ArgumentException("This tank is empty. You cannot export from it.");
            }

            var operation = new TankOperation
            {
                ActionAmount       = fertilizer.Amount,
                AmountBeforeAction = this.CurrentLoad,
                AmountAfterAction  = this.CurrentLoad - fertilizer.Amount,
                OperationName      = "Export",
                OperatorName       = name,
                TankId             = this.Id,
                FertilizerName     = fertilizer.Name.ToLower()
            };

            this.Operations.Add(operation);
            this.CurrentLoad -= fertilizer.Amount;

            if (this.CurrentLoad == 0)
            {
                this.CurrentFertilizer = null;
            }
        }
Beispiel #2
0
        public void AddFertilizer(Fertilizer fertilizer, string name)
        {
            if (fertilizer.Amount + this.CurrentLoad > this.MaxCapacity)
            {
                var availabaleCapacity = this.MaxCapacity - this.CurrentLoad;
                throw new ArgumentException($"You can add up to {availabaleCapacity} liters");
            }

            if (this.CurrentFertilizer != null && this.CurrentFertilizer != fertilizer.Name.ToLower())
            {
                throw new ArgumentException($"You can add only {this.CurrentFertilizer} in this tanker");
            }

            if (this.CurrentFertilizer == null)
            {
                this.CurrentFertilizer = fertilizer.Name.ToLower();
            }

            if (fertilizer.Amount <= 0)
            {
                throw new ArgumentException("Please enter positive number");
            }

            var operation = new TankOperation
            {
                ActionAmount       = fertilizer.Amount,
                AmountAfterAction  = this.CurrentLoad + fertilizer.Amount,
                AmountBeforeAction = this.CurrentLoad,
                OperationName      = "Import",
                TankId             = this.Id,
                OperatorName       = name,
                FertilizerName     = fertilizer.Name.ToLower()
            };

            this.Operations.Add(operation);

            this.CurrentLoad += fertilizer.Amount;
        }