Exemple #1
0
        public bool SortMovingTrams(TramLocation location)
        {
            SortingAlgoritm sorter      = new SortingAlgoritm(AllTracks, repo);
            List <Tram>     movingTrams = repo.GetAllTramsWithLocation(location);

            if (movingTrams.Count != 0)
            {
                for (int i = 0; i < movingTrams.Count; i++)
                {
                    BeheerTram beheerTram = BeheerTram.ToBeheerTram(movingTrams[i]);
                    if (location == TramLocation.ComingIn)
                    {
                        if (movingTrams[i].DepartureTime == null)
                        {
                            GetExitTime(beheerTram);
                        }
                        SortTram(sorter, beheerTram);
                    }
                    else if (location == TramLocation.GoingOut)
                    {
                        beheerTram.EditTramLocation(TramLocation.Out);
                        movingTrams[i] = beheerTram;
                        repo.EditTram(movingTrams[i]);
                        repo.WipeSectorByTramId(movingTrams[i].Number);
                    }
                }
                FetchUpdates();
                return(true);
            }
            return(false);
        }
        private bool SortMovingTrams(TramLocation location)
        {
            var movingTrams = _repo.GetAllTramsWithLocation(location);

            if (movingTrams.Count != 0)
            {
                UpdateTracks();
                var sorter = new TramSortingAlgoritm(_allTracks, _repo);
                for (var i = 0; i < movingTrams.Count; i++)
                {
                    var beheerTram = BeheerTram.ToBeheerTram(movingTrams[i]);
                    if (location == TramLocation.ComingIn)
                    {
                        if (beheerTram.DepartureTime == null)
                        {
                            beheerTram.EditTramDepartureTime(GetExitTime(beheerTram));
                        }
                        sorter.AssignTramLocation(beheerTram);
                    }
                    else if (location == TramLocation.GoingOut)
                    {
                        beheerTram.EditTramLocation(TramLocation.Out);
                        movingTrams[i] = beheerTram;
                        _repo.EditTram(movingTrams[i]);
                        _repo.WipeSectorByTramId(movingTrams[i].Number);
                        Console.WriteLine($"Tram {beheerTram.Number} left the remise.");
                    }
                }
                return(true);
            }
            return(false);
        }
Exemple #3
0
 public BeheerTram(int number, TramStatus status, int line, User driver, TramModel model, TramLocation location, DateTime?departureTime) : base(number, status, line, driver, model, location, departureTime)
 {
     Number        = number;
     Status        = status;
     Line          = line;
     Driver        = driver;
     Model         = model;
     Location      = location;
     DepartureTime = departureTime;
 }
 public WebTramLocation(TramLocation data)
 {
     Status    = data.Status;
     FirstLine = data.FirstLine;
     Lon       = data.Lon;
     Lines     = data.Lines;
     Time      = data.Time;
     Lat       = data.Lat;
     LowFloor  = data.LowFloor;
     Brigade   = data.Brigade;
 }
Exemple #5
0
 /// <summary>
 ///     Haal trams op met locatie.
 /// </summary>
 /// <param name="location"></param>
 /// <returns></returns>
 public List <Tram> GetAllTramsWithLocation(TramLocation location)
 {
     return(ObjectCreator.GenerateListWithFunction(_tramContext.GetAllTramsWithLocation(location),
                                                   _objectCreator.CreateTram));
 }
Exemple #6
0
 public InUitRitTram(int number, TramStatus status, int line, User driver, TramModel model,
                     TramLocation location, DateTime?departureTime) : base(number, status, line, driver, model, location,
                                                                           departureTime)
 {
 }
Exemple #7
0
 public void EditTramLocation(TramLocation tramLocation)
 {
     Location = tramLocation;
 }
Exemple #8
0
        public static void Initialize(DatabaseContext context)
        {
            context.Database.EnsureCreated();

            if (context.Users.Any())
            {
                return;
            }

            string adminPassword = "******";
            string userPassword  = "******";

            var users = new User[]
            {
                new User {
                    Name = "AdminUser", Login = "******", Password = HashPassword(adminPassword)
                },
                new User {
                    Name = "NormalUser", Login = "******", Password = HashPassword(userPassword)
                },
            };

            foreach (User user in users)
            {
                context.Users.Add(user);
            }
            context.SaveChanges();

            var roles = new Role[]
            {
                new Role {
                    Id = 1, Code = "ADMIN", Name = "AdminRole", Description = "Role for administrators that can refresh data in DB"
                },
                new Role {
                    Id = 2, Code = "USER", Name = "UserRole", Description = "Role for normal users. Just an example."
                }
            };

            foreach (Role role in roles)
            {
                context.Roles.Add(role);
            }
            context.SaveChanges();

            var userRoles = new UserRole[]
            {
                new UserRole {
                    Id = 1, RoleId = 1, UserId = 1
                },
                new UserRole {
                    Id = 2, RoleId = 2, UserId = 2
                }
            };

            foreach (UserRole userRole in userRoles)
            {
                context.UserRoles.Add(userRole);
            }
            context.SaveChanges();

            var tramLocations = new TramLocation[]
            {
                new TramLocation {
                    Brigade = "1", LowFloor = true, FirstLine = "12", Lon = 21.3123, Lat = 21.3123, Time = DateTime.Now, Status = "Test status", Lines = "12, 14"
                }
            };

            foreach (TramLocation tramLocation in tramLocations)
            {
                context.TramLocations.Add(tramLocation);
            }
            context.SaveChanges();
        }
 /// <summary>
 /// Haal trams op met locatie.
 /// </summary>
 /// <param name="location"></param>
 /// <returns></returns>
 public List <Tram> GetAllTramsWithLocation(TramLocation location)
 {
     return(TramContext.GetAllTramsWithLocation(location));
 }
Exemple #10
0
 public List <Tram> GetAllTramsWithLocation(TramLocation location)
 {
     return(Database.GenerateListWithFunction(Database.GetData(new SqlCommand($"SELECT * FROM Tram WHERE Location = {(int)location}")), CreateTram));
 }
Exemple #11
0
 public DataTable GetAllTramsWithLocation(TramLocation location)
 {
     return(DatabaseHandler.GetData(new SqlCommand($"SELECT * FROM Tram WHERE Location = {(int) location}")));
 }