Пример #1
0
        public void AddTransfer(TransferCommand command)
        {
            var barrelFrom = _barrelRepository.GetById(command.BarrelFromId);
            var barrelTo   = _barrelRepository.GetById(command.BarrelToId);

            var transfer = new Transfer(command);

            if ((barrelFrom.CurrentCapacity >= command.Amount) &&
                (barrelTo.Capacity >= barrelTo.CurrentCapacity + command.Amount))
            {
                barrelFrom.RemoveAmount(command.Amount);
                barrelTo.AddAmount(command.Amount);
            }
            else
            {
                throw new Exception("Specified amount can't fit into the barrels");
            }

            using (var scope = new TransactionScope())
            {
                _barrelRepository.UpdateBarrel(command.BarrelFromId, barrelFrom);
                _barrelRepository.UpdateBarrel(command.BarrelToId, barrelTo);
                _transferRepository.AddTransfer(transfer);

                scope.Complete();
            }
        }
Пример #2
0
        public void UpdateBarrel(int id, BarrelCommand command)
        {
            var barrel = _repository.GetById(id);

            barrel.Update(command);

            _repository.UpdateBarrel(id, barrel);
        }