Пример #1
0
        static void Main(string[] args)
        {
            List <Train> trains = new List <Train>()
            {
                new Train()
                {
                    Departure = City.Aktau, DepartureTime = new DateTime(2019, 05, 17, 17, 15, 0), Airrival = City.Astana, ArrivalTime = new DateTime(2019, 05, 18, 12, 15, 0), FreePlaces = 10
                },
                new Train()
                {
                    Departure = City.Astana, DepartureTime = new DateTime(2019, 06, 18, 12, 15, 0), Airrival = City.Karaganda, ArrivalTime = new DateTime(2019, 06, 18, 14, 15, 0), FreePlaces = 10
                },
                new Train()
                {
                    Departure = City.Astana, DepartureTime = new DateTime(2019, 06, 18, 17, 15, 0), Airrival = City.Karaganda, ArrivalTime = new DateTime(2019, 06, 18, 20, 15, 0), FreePlaces = 10
                },
                new Train()
                {
                    Departure = City.Aktau, DepartureTime = new DateTime(2019, 10, 25, 17, 15, 0), Airrival = City.Karaganda, ArrivalTime = new DateTime(2019, 10, 26, 12, 15, 0), FreePlaces = 10
                },
                new Train()
                {
                    Departure = City.Kokshetau, DepartureTime = new DateTime(2019, 05, 17, 17, 15, 0), Airrival = City.Almaty, ArrivalTime = new DateTime(2019, 05, 18, 12, 15, 0), FreePlaces = 10
                },
                new Train()
                {
                    Departure = City.Aktau, DepartureTime = new DateTime(2019, 05, 17, 17, 15, 0), Airrival = City.Karaganda, ArrivalTime = new DateTime(2019, 05, 20, 13, 15, 0), FreePlaces = 10
                },
                new Train()
                {
                    Departure = City.Karaganda, DepartureTime = new DateTime(2019, 05, 17, 20, 15, 0), Airrival = City.Almaty, ArrivalTime = new DateTime(2019, 05, 20, 16, 15, 0), FreePlaces = 10
                },
                new Train()
                {
                    Departure = City.Aktau, DepartureTime = new DateTime(2019, 05, 17, 17, 15, 0), Airrival = City.Astana, ArrivalTime = new DateTime(2019, 05, 18, 12, 15, 0), FreePlaces = 10
                },
                new Train()
                {
                    Departure = City.Almaty, DepartureTime = new DateTime(2019, 05, 17, 19, 15, 0), Airrival = City.Astana, ArrivalTime = new DateTime(2019, 05, 18, 12, 15, 0), FreePlaces = 10
                },
            };

            using (var context = new RailwayContext())
            {
                context.Trains.AddRange(trains);
                context.SaveChanges();
            }
        }
Пример #2
0
        public async Task <IActionResult> ResetPassword(int id, ResetPasswordViewModel model)
        {
            using (db = new RailwayContext(new DbContextOptions <RailwayContext>()))
            {
                if (ModelState.IsValid)
                {
                    var user = await db.Users.Where(u => u.Id == id).FirstOrDefaultAsync();

                    user.Password = model.Password;
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Login", "Account"));
                }
            }

            return(View(model));
        }
Пример #3
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            var train     = possibleTrains[lstTickets.SelectedIndex];
            var passenger = new Passenger();

            Ticket ticket;

            if (txtPassengerName.Text.Length != 0)
            {
                passenger.FullName = txtPassengerName.Text;
            }
            else
            {
                MessageBox.Show("You have to enter your name");
            }
            if (lstTickets.SelectedIndex >= 0)
            {
                ticket = new Ticket
                {
                    //Train = train,
                    TrainId = train.Id,
                    //Passenger = passenger,
                    PassengerId = passenger.Id,
                };
                try { passenger.Tickets.Add(ticket); }
                catch
                {
                    passenger.Tickets = new List <Ticket>();
                    passenger.Tickets.Add(ticket);
                }
                using (var context = new RailwayContext())
                {
                    context.Tickets.Add(ticket);
                    context.Passengers.Add(passenger);
                    var result = context.Trains.SingleOrDefault(t => t.Id == train.Id);
                    context.SaveChanges();
                    MessageBox.Show("Your order has been admitted");
                }
            }
            else
            {
                MessageBox.Show("You have to choose a ticket");
            }
        }
Пример #4
0
 private void btnFind_Click(object sender, EventArgs e)
 {
     using (var context = new RailwayContext())
     {
         allTrains = context.Trains.ToList();
         foreach (var train in allTrains)
         {
             if (train.Departure.ToString() == comboListFrom.Text &&
                 train.Airrival.ToString() == comboListTo.Text &&
                 train.DepartureTime.Date == dateTimeDeparture.Value.Date &&
                 train.FreePlaces > 0)
             {
                 possibleTrains.Add(train);
                 lstTickets.Items.Add($"{train.Departure} - {train.Airrival}Departure Time{train.DepartureTime}\nArrival Time{train.ArrivalTime}\n\n");
             }
         }
         if (lstTickets.Items.Count == 0)
         {
             MessageBox.Show("Sorry no available train");
         }
     }
 }
Пример #5
0
        private static void SeedDatabase(IHost host)
        {
            //https://stackoverflow.com/a/53809870
            using (var scope = host.Services.CreateScope())
            {
                RailwayContext dbContext = scope.ServiceProvider.GetRequiredService <RailwayContext>();

                var transaction = dbContext.Database.BeginTransaction();

                try
                {
                    string seedScript = File.ReadAllText("StartupInsertConfigScript.sql");

                    dbContext.Database.ExecuteSqlRaw(seedScript);

                    transaction.Commit();
                }
                catch (SqlException exception)
                {
                    Console.WriteLine(exception.ToString());
                    transaction.Rollback();
                }
            }
        }
Пример #6
0
 public SqlStation(RailwayContext context)
 {
     _context = context;
 }
 public TripRepository(RailwayContext context)
 {
     _context   = context;
     viewModels = new List <Models.ViewModel.Trip.IndexViewModel>();
 }
Пример #8
0
 public RoutesController(RailwayContext context, RoutRepository repository)
 {
     _context    = context;
     _repository = repository;
 }
 public RoutRepository(RailwayContext context)
 {
     _context = context;
 }
Пример #10
0
 public TripController(RailwayContext context)
 {
     _context = context;
 }
Пример #11
0
 public SqlRailway(RailwayContext context)
 {
     _context = context;
 }
 public WagonRepository(RailwayContext context)
 {
     _context = context;
 }
Пример #13
0
 public WagonStore()
 {
     _context = new RailwayContext(new DbContextOptions <RailwayContext>());
 }
Пример #14
0
 public RailwayTicketsController(RailwayContext context)
 {
     _context = context;
 }
Пример #15
0
 public RailwayContext Init()
 {
     return(dbContext ?? (dbContext = new RailwayContext()));
 }
Пример #16
0
 public RailwayService(RailwayContext context)
 {
     this.context = context;
 }
Пример #17
0
 public SearchController(RailwayContext context_)
 {
     context = context_;
 }
Пример #18
0
 public PassengerService(RailwayContext railwayContext)
 {
     _railwayContext = railwayContext;
 }
Пример #19
0
 public AccountController(RailwayContext context)
 {
     db = context;
 }
Пример #20
0
 public UserController(RailwayContext context)
 {
     db = context;
 }
Пример #21
0
 public OnlineController(RailwayContext _context)
 {
     context = _context;
 }
 public ManageController(RailwayContext context)
 {
     db = context;
 }