static void SeedOperatingSystemTable() { using (var context = new MachineContext()) { var os = new OperatingSys { Name = "Windows XP", StillSupported = false }; context.OperatingSys.Add(os); os = new OperatingSys { Name = "Windows 7", StillSupported = true }; context.OperatingSys.Add(os); os = new OperatingSys { Name = "Windows 8", StillSupported = false }; context.OperatingSys.Add(os); os = new OperatingSys { Name = "Windows 8.1", StillSupported = true }; context.OperatingSys.Add(os); os = new OperatingSys { Name = "Windows 10", StillSupported = true }; context.OperatingSys.Add(os); os = new OperatingSys { Name = "Windows Server 2000", StillSupported = false }; context.OperatingSys.Add(os); //os = new OperatingSys { Name = "Windows Server 2003 R2", StillSupported = false }; //context.OperatingSys.Add(os); os = new OperatingSys { Name = "Windows Server 2008", StillSupported = true }; context.OperatingSys.Add(os); os = new OperatingSys { Name = "Windows Server 2008 R2", StillSupported = true }; context.OperatingSys.Add(os); os = new OperatingSys { Name = "Windows Server 2012", StillSupported = true }; context.OperatingSys.Add(os); os = new OperatingSys { Name = "Windows Server 2012 R2", StillSupported = true }; context.OperatingSys.Add(os); os = new OperatingSys { Name = "Windows Server 2016", StillSupported = true }; context.OperatingSys.Add(os); os = new OperatingSys { Name = "Ubuntu Server 16.14.2 LTS", StillSupported = true }; context.OperatingSys.Add(os); os = new OperatingSys { Name = "Ubuntu Server 17.04", StillSupported = true }; context.OperatingSys.Add(os); context.SaveChanges(); } }
static OperatingSys GetOperatingSystemById(int id) { var context = new MachineContext(); OperatingSys os = context.OperatingSys.FirstOrDefault(i => i.OperatingSysId == id); return(os); }
static void DeleteOperatingSystem(int id) { OperatingSys os = GetOperatingSystemById(id); if (os != null) { Console.WriteLine($"\r\nAre you sure you want to delete {os.Name}? [y or n]"); Console.ForegroundColor = ConsoleColor.White; ConsoleKeyInfo cki; string result; bool cont; do { cki = Console.ReadKey(true); result = cki.KeyChar.ToString(); cont = ValidateYorN(result); } while (!cont); if ("y" == result.ToLower()) { Console.WriteLine("\r\nDeleting record"); Console.ForegroundColor = ConsoleColor.White; using (var context = new MachineContext()) { context.Remove(os); context.SaveChanges(); } Console.WriteLine("Record Deleted"); Console.ForegroundColor = ConsoleColor.White; Console.ReadKey(); } else { Console.WriteLine("Delete Aborted\r\nHit any key to continue..."); Console.ForegroundColor = ConsoleColor.White; Console.ReadKey(); } } else { Console.WriteLine("\r\nOperating System Not Found!"); Console.ForegroundColor = ConsoleColor.White; Console.ReadKey(); SelectOperatingSystem("Delete"); } }
static void ModifyOperatingSystem(int id) { OperatingSys os = GetOperatingSystemById(id); Console.Clear(); char operation = '0'; bool cont = false; ConsoleKeyInfo cki; WriteHeader("Update Operating System"); if (os != null) { Console.WriteLine($"\r\nOS Name: {os.Name} Still Supported: {os.StillSupported}"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("To modify the name press 1\r\nTo modify if the OS is Still Supported press 2"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("Hit Esc to exit this menu"); Console.ForegroundColor = ConsoleColor.White; do { cki = Console.ReadKey(true); if (cki.Key == ConsoleKey.Escape) { cont = true; } else { if (char.IsNumber(cki.KeyChar)) { if (cki.KeyChar == '1') { Console.WriteLine("Updated Operating System Name: "); Console.ForegroundColor = ConsoleColor.White; operation = '1'; cont = true; } else if (cki.KeyChar == '2') { Console.WriteLine("Update if the OS is Still Supported [y or n]: "); Console.ForegroundColor = ConsoleColor.White; operation = '2'; cont = true; } } } } while (!cont); } if (operation == '1') { string osName; cont = false; do { osName = Console.ReadLine(); if (osName.Length >= 4) { cont = true; } else { Console.WriteLine("Please enter a vaild OS name of at least 4 characters.\r\nPress and key to continue..."); Console.ForegroundColor = ConsoleColor.White; Console.ReadKey(); } } while (!cont); os.Name = osName; } else if (operation == '2') { string k; do { cki = Console.ReadKey(true); k = cki.KeyChar.ToString(); cont = ValidateYorN(k); } while (!cont); if (k == "y") { os.StillSupported = true; } else { os.StillSupported = false; } } using (var context = new MachineContext()) { var o = context.OperatingSys.FirstOrDefault(i => i.OperatingSysId == os.OperatingSysId); if (o != null) { // just making sure o.Name = os.Name; o.StillSupported = os.StillSupported; Console.WriteLine("\r\nUpdating the database..."); Console.ForegroundColor = ConsoleColor.White; context.SaveChanges(); Console.WriteLine("Done!\r\nHit any key to continue..."); Console.ForegroundColor = ConsoleColor.White; } } Console.ReadKey(); }
static void AddOperatingSystem() { Console.Clear(); ConsoleKeyInfo cki; string result; bool cont = false; OperatingSys os = new OperatingSys(); string osName = ""; do { WriteHeader("Add New Operating System"); Console.WriteLine("Enter the Name of the Operating System and hit Enter"); Console.ForegroundColor = ConsoleColor.White; osName = Console.ReadLine(); if (osName.Length >= 4) { cont = true; } else { Console.WriteLine("Please enter a vaild OS name of at least 4 characters.\r\nPress and key to continue..."); Console.ForegroundColor = ConsoleColor.White; Console.ReadKey(); } } while (!cont); cont = false; os.Name = osName; Console.WriteLine("Is the Operating System still supported? [y or n]"); Console.ForegroundColor = ConsoleColor.White; do { cki = Console.ReadKey(); result = cki.KeyChar.ToString(); cont = ValidateYorN(result); } while (!cont); if (result.ToLower() == "y") { os.StillSupported = true; } else { os.StillSupported = false; } cont = false; do { Console.Clear(); Console.WriteLine($"You entered {os.Name} as the Operating System Name\r\nIs the OS still supported, you entered {os.StillSupported}.\r\nDo you wish to continue? [y or n]"); Console.ForegroundColor = ConsoleColor.White; cki = Console.ReadKey(); result = cki.KeyChar.ToString(); cont = ValidateYorN(result); } while (!cont); if (result.ToLower() == "y") { bool exists = CheckForExistingOS(os.Name); if (exists) { Console.WriteLine("\r\nOperating System already exists in the database\r\nPress any key to continue..."); Console.ForegroundColor = ConsoleColor.White; Console.ReadKey(); } else { using (var context = new MachineContext()) { Console.WriteLine("\r\nAttempting to save changes..."); Console.ForegroundColor = ConsoleColor.White; context.OperatingSys.Add(os); int i = context.SaveChanges(); if (i == 1) { Console.WriteLine("Contents Saved\r\nPress any key to continue..."); Console.ForegroundColor = ConsoleColor.White; Console.ReadKey(); } } } } }
public static string GetRebusCoreUri() { return(OperatingSys.IsLinux() ? "http://rebuscore:5001/" : ""); }
public static string GetFileSystemDir() { return(OperatingSys.IsLinux() ? "/app/files/" : @"C:\Users\Paulius\Desktop\"); }
public static string GetDataLocation() { return(OperatingSys.IsLinux() ? "/app/files/" : @"C:\Users\pkuprevicius\Documents\dotnet\FlightSystem2\RebusAdmin\Files\"); }