예제 #1
0
파일: Logic.cs 프로젝트: Tvde1/OdoriRails
        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);
        }
예제 #2
0
        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);
        }
예제 #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;
 }
예제 #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));
 }
예제 #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)
 {
 }
예제 #7
0
 public void EditTramLocation(TramLocation tramLocation)
 {
     Location = tramLocation;
 }
예제 #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();
        }
예제 #9
0
 /// <summary>
 /// Haal trams op met locatie.
 /// </summary>
 /// <param name="location"></param>
 /// <returns></returns>
 public List <Tram> GetAllTramsWithLocation(TramLocation location)
 {
     return(TramContext.GetAllTramsWithLocation(location));
 }
예제 #10
0
 public List <Tram> GetAllTramsWithLocation(TramLocation location)
 {
     return(Database.GenerateListWithFunction(Database.GetData(new SqlCommand($"SELECT * FROM Tram WHERE Location = {(int)location}")), CreateTram));
 }
예제 #11
0
 public DataTable GetAllTramsWithLocation(TramLocation location)
 {
     return(DatabaseHandler.GetData(new SqlCommand($"SELECT * FROM Tram WHERE Location = {(int) location}")));
 }