Esempio n. 1
0
        public async Task <JsonResult> PlanedRouteTrainsTable([FromBody] PlanedRouteTrain input)
        {
            await CheckPermission();

            var service = new ScheludePlanedService(_logger, _mapper);
            var result  = await service.AddTrainToPlanedRouteTrains(input);

            return(Json(result));
        }
        public async Task <PlanedRouteTrain> Add(PlanedRouteTrain input)
        {
            using (var conn = new SqlConnection(AppSettings.ConnectionString))
            {
                var id = await conn.QueryFirstOrDefaultAsync <int>(_sql.Add(input));

                return(await ById(id));
            }
        }
Esempio n. 3
0
 public string Add(PlanedRouteTrain input)
 {
     return($@"
     insert into {Table} 
     (CreateDate, Date, RouteId, TrainId, UserId) 
     values
     ('{input.CreateDate}', '{input.Date}', '{input.RouteId}' , '{input.TrainId}', '{input.TrainId}')
     SELECT SCOPE_IDENTITY()
     ");
 }
        public async Task <PlanedRouteTrain> AddTrainToPlanedRouteTrains(PlanedRouteTrain input)
        {
            using (var transaction = new TransactionScope(asyncFlowOption: TransactionScopeAsyncFlowOption.Enabled))
            {
                var sqlRTrips                    = new TripsRepository(_logger);
                var sqlRStations                 = new StantionOnTripsRepository(_logger);
                var sqlRInspectionOnRoutes       = new InspectionRoutesRepository(_logger);
                var sqlRPlanedInspectionOnRoutes = new PlanedInspectionRoutesRepository(_logger);

                var sqlRPlaneStations     = new PlanedStationOnTripsRepository(_logger);
                var sqlRPlanedRouteTrains = new PlanedRouteTrainsRepository(_logger);

                //Валидация Хуяция.
                //TODO поменять на sql
                var trainPlaneRoutes = await sqlRPlanedRouteTrains.ByTrainId(input.TrainId);

                if (trainPlaneRoutes.Any(x => x.Date.Date.Equals(input.Date.Date)))
                {
                    throw new ValidationException(Error.AlreadyAdd);
                }

                var result = await sqlRPlanedRouteTrains.Add(input);

                var trips = await sqlRTrips.GetTripsByRouteId(input.RouteId);

                //var tripsStationsDictionary = new Dictionary<Trip, List<StantionOnTrip>>();
                foreach (var trip in trips)
                {
                    var stations = await sqlRStations.ByTripId(trip.Id);

                    foreach (var station in stations)
                    {
                        var toAdd = _mapper.Map <StantionOnTrip, PlaneStantionOnTrip>(station);
                        toAdd.PlanedRouteTrainId = result.Id;
                        var newInTime = toAdd.InTime - DateTime.MinValue;
                        toAdd.InTime = input.Date.Date.Add(newInTime);

                        var newOutTime = toAdd.OutTime - DateTime.MinValue;
                        toAdd.OutTime = input.Date.Date.Add(newOutTime);

                        await sqlRPlaneStations.Add(toAdd);
                    }

                    //tripsStationsDictionary.Add(trip, stations);
                }

                //И тут я узнал что надо инспекции скопировать ебать их в рот
                var inspections = await sqlRInspectionOnRoutes.GetByRouteId(input.RouteId);

                foreach (var inspection in inspections)
                {
                    var toAdd = new PlanedInspectionRoute
                    {
                        CheckListType      = inspection.CheckListType,
                        PlanedRouteTrainId = result.Id,
                    };
                    var newInTime = inspection.Start - inspection.Start.Date;
                    toAdd.Start = input.Date.Date.Add(newInTime);
                    var newOutTime = inspection.End - inspection.End.Date;
                    toAdd.End = input.Date.Date.Add(newOutTime);
                    await sqlRPlanedInspectionOnRoutes.Add(toAdd);
                }


                transaction.Complete();
                return(result);
            }
        }