Beispiel #1
0
        public async Task <Train> AddTrainAsync(TrainModel TrainModel, string station)
        {
            _logger.LogInformation("Got trainModel to create", TrainModel);

            var train = _imapper.Map <Train>(TrainModel);

            train.FormStation = _context.Station.Where(s => s.Code.StartsWith(TrainModel.Index.Substring(0, 4)))
                                .Select(s => s.Code)
                                .FirstOrDefault();
            train.DestinationStation = _context.Station.Where(s => s.Code.StartsWith(TrainModel.Index.Substring(9, 4)))
                                       .Select(s => s.Code)
                                       .FirstOrDefault();
            train.Dislocation = station;
            train.Ordinal     = await GetNextOrdinal(station);

            _logger.LogDebug("Found {FormStation} {DestinationStation}", train.FormStation, train.DestinationStation);

            _logger.LogInformation("Saving train", train);
            _context.Train.Add(train);

            var result = await _context.SaveChangesAsync();

            _logger.LogInformation($"Saved {result} of 1 record");

            return(train);
        }
        public async Task CreateTrain(Guid trainId, DateTime dateOper, string station)
        {
            var opTrain = new OpTrain
            {
                SourceStation = station,
                Datop         = dateOper,
                Kop           = OperationCode.TrainComposition,
                Msgid         = DateTime.Now,
                TrainId       = trainId,
                LastOper      = true
            };

            _context.Add(opTrain);
            _logger.LogInformation("Saving operation to train", opTrain);
            var affected = await _context.SaveChangesAsync();

            _logger.LogInformation($"Saved {affected} of 1 records");
        }
        public async Task AttachToTrain(Guid trainId, List <VagonModel> wagons, DateTime timeOper, string sourceStation, string destinationStation)
        {
            var newWagOpers = _imapper.Map <List <OpVag> >(wagons);

            await CheckWagonOperationsToAdd(newWagOpers, sourceStation);

            foreach (OpVag vagon in newWagOpers)
            {
                vagon.LastOper      = true;
                vagon.Source        = sourceStation;
                vagon.TrainId       = trainId;
                vagon.DateOper      = timeOper;
                vagon.CodeOper      = OperationCode.TrainComposition;
                vagon.PlanForm      = destinationStation;
                vagon.NumNavigation = _context.Vagon.Where(v => v.Id == vagon.Num).FirstOrDefault();
            }

            _context.Add(newWagOpers);
            var affected = await _context.SaveChangesAsync();

            _logger.LogInformation($"Saved {affected} of {newWagOpers.Count()} records");
        }