Esempio n. 1
0
        public void CreateSpecificRoute(int routeId, DateTime departTime, int vehicleId)
        {
            using (var uow = UnitOfWorkProvider.Create())
            {
                var route = routeRepository.GetById(routeId, r => r.RouteStations);
                createSpecificRouteQuery.RouteId = routeId;
                var routeStationsTemplates = createSpecificRouteQuery.Execute().ToList();
                var seatDTOs = ListSeatsOfVehicle(vehicleId);

                foreach (var routeStationTemplate in routeStationsTemplates)
                {
                    var routeStation = new RouteStation();
                    Mapper.Map(routeStationTemplate, routeStation);
                    routeStation.DepartFromFirstStation = departTime;
                    var routeStationForGettingStation = routeStationRepository.GetById(routeStationTemplate.ID, routeStationTemplat => routeStationTemplat.Station);

                    var station = stationRepository.GetById(routeStationForGettingStation.Station.ID, s => s.RouteStations);

                    routeStation.Route = route;
                    route.RouteStations.Add(routeStation);

                    routeStation.Station = station;
                    station.RouteStations.Add(routeStation);

                    if (seatDTOs != null)
                    {
                        foreach (var seatDTO in seatDTOs)
                        {
                            var seat    = seatRepository.GetById(seatDTO.ID, s => s.Programs);
                            var program = new Program
                            {
                                IsSeatOccupied = false,
                                RouteStation   = routeStation,
                                Seat           = seat
                            };
                            seat.Programs.Add(program);
                            programRepository.Insert(program);
                            routeStation.Programs.Add(program);
                        }
                    }
                    routeStationRepository.Insert(routeStation);
                }
                uow.Commit();
            }
        }