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"); }