예제 #1
0
        public async Task <Operation> MixWine(int sectorId, int sourceContainerId, int destinationContainerId, double volume)
        {
            var sourceContainer = _context.Container.FirstOrDefault(x => x.Code == sourceContainerId && x.SectorId == sectorId);

            var destinationContainer = _context.Container.FirstOrDefault(x => x.Code == destinationContainerId && x.SectorId == sectorId);

            sourceContainer.Volume = sourceContainer.Volume - volume;

            destinationContainer.Volume = destinationContainer.Volume + volume;

            _context.Update(sourceContainer);
            _context.Update(destinationContainer);

            var operation = new Operation {
                SectorId                   = sectorId,
                SourceContainerId          = sourceContainerId,
                SourceContainerVolume      = sourceContainer.Volume,
                DestinationContainerId     = destinationContainerId,
                DestinationContainerVolume = destinationContainer.Volume,
                Volume = volume
            };

            _context.Operation.Add(operation);

            await this.SaveChangesAsync();

            return(operation);
        }