/// <summary> /// SuperAdmin Modification Access /// </summary> /// <param name="CurrentUser"></param> public void ModifyUser(Users CurrentUser) { bool Invalid; Console.WriteLine($"--> {CurrentUser.Username}"); foreach (string name in GetUsernames(CurrentUser.Username)) { Console.WriteLine($"--> {name}"); } do { Invalid = false; Console.Write("Insert Username or 'exit' to exit editor: "); string Username = Console.ReadLine(); if (Username == "exit") { return; } //Check If User Exists if (FindUser(Username) == null) { Console.WriteLine("Username Not Found!"); Invalid = true; } else { UIProcedures UI = new UIProcedures(); Users user = FindUser(Username); UI.UIShowAccess(user); char Choice = Console.ReadKey(true).KeyChar; switch (Choice) { case '1': Console.WriteLine("You cant change Username!"); Thread.Sleep(1500); break; case '2': UserSignUp PassEncrypt = new UserSignUp(); string NewPassword = ""; if (user.Username != CurrentUser.Username) { Console.WriteLine("You cant change Password of other users!!"); Thread.Sleep(1500); break; } do { Console.Write("Current Password: "******"***NOTE***\nApplication will Restart after changes!!!"); Console.Write("New Password: "******"Invalid Password"); Invalid = true; } } while (Invalid); using (var db = new TeamsContext()) { user.Password = NewPassword; db.Entry(user).State = System.Data.Entity.EntityState.Modified; Console.WriteLine("Saving, please wait..."); db.SaveChanges(); } Console.WriteLine("Complete!\nLoging Out..."); Thread.Sleep(3000); string fileName = Assembly.GetExecutingAssembly().Location; System.Diagnostics.Process.Start(fileName); Environment.Exit(0); break; case '3': //FirstName Console.Write("New FirstName: "); string NewFirstname = Console.ReadLine(); using (var db = new TeamsContext()) { user.FirstName = NewFirstname; db.Entry(user).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); Console.WriteLine("Modify Complete!"); } break; case '4': //LastName Console.Write("New LastName: "); string NewLastname = Console.ReadLine(); using (var db = new TeamsContext()) { user.LastName = NewLastname; db.Entry(user).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); Console.WriteLine("Modify Complete!"); } break; case '5': //Date Of Birth DateTime NewDateOfBirth = new DateTime(); do { Invalid = false; Console.Write("New Date Of Birth(yyyy/mm/dd): "); try { NewDateOfBirth = DateTime.Parse(Console.ReadLine()); } catch (Exception) { Console.WriteLine("Invalid Format!"); Invalid = true; } } while (Invalid); using (var db = new TeamsContext()) { user.DateOFBirth = NewDateOfBirth; db.Entry(user).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); Console.WriteLine("Modify Complete!"); } break; case '6': //User Type if (user.UserType != "SuperAdmin") { Console.WriteLine("You cant Change your Type!"); Thread.Sleep(2000); break; } char NewUserType; do { Console.Clear(); Invalid = false; Console.WriteLine("Choose New User Type:\n1. Student\n2. Teacher\n3. Admin"); NewUserType = Console.ReadKey(true).KeyChar; switch (NewUserType) { case '1': user.UserType = "Student"; break; case '2': user.UserType = "Teacher"; break; case '3': user.UserType = "Admin"; break; default: Console.WriteLine("Wrong User Type!"); Invalid = true; break; } } while (Invalid); using (var db = new TeamsContext()) { db.Entry(user).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); Console.WriteLine("Complete!"); } break; case '7': if (user.UserType == "SuperAdmin") { Console.WriteLine("You cant delete Yourself!\nYour Are The Super Admin!"); Thread.Sleep(2000); break; } Console.WriteLine("Are you sure (y/n)?"); char IsSure = Console.ReadKey(true).KeyChar; if (IsSure == 'y') { DeleteUser(user); } break; case '0': Invalid = false; break; default: Console.WriteLine("Invalid Input!"); Invalid = true; break; } } } while (Invalid); }
/// <summary> /// Techers Modification Access /// </summary> /// <param name="CurrentUser"></param> public void TeacherModifyUser(Users CurrentUser) { bool Invalid; Console.WriteLine($"--> {CurrentUser.Username}"); foreach (string name in GetUsernames(CurrentUser.Username)) { Console.WriteLine($"--> {name}"); } do { Invalid = false; Console.Write("Insert Username or 'exit' to exit editor: "); string Username = Console.ReadLine(); Users user = FindUser(Username); if (Username == "exit") { return; } if (user == null) { Console.WriteLine("Username Not Found!"); Invalid = true; } else if (user.Username == "Admin") { Console.WriteLine("You cant Edit Admin!\nYou dont want to...Believe me!"); } else { UIProcedures UI = new UIProcedures(); UI.UIShowAccess(user); char Choice = Console.ReadKey(true).KeyChar; switch (Choice) { case '1': Console.WriteLine("You cant change Username!"); Thread.Sleep(1500); break; case '2': UserSignUp PassEncrypt = new UserSignUp(); string NewPassword = ""; if (user.Username != CurrentUser.Username) { Console.WriteLine("You cant change Password of other users!!"); Thread.Sleep(1500); break; } do { Console.WriteLine("***NOTE***\nApplication will Restart after changes!!!"); Console.Write("Current Password: "******"New Password: "******"Invalid Password"); Invalid = true; } } while (Invalid); using (var db = new TeamsContext()) { user.Password = NewPassword; db.Entry(user).State = System.Data.Entity.EntityState.Modified; Console.WriteLine("Saving, please wait..."); db.SaveChanges(); } Console.WriteLine("Complete!\nLoging Out..."); Thread.Sleep(3000); string fileName = Assembly.GetExecutingAssembly().Location; System.Diagnostics.Process.Start(fileName); Environment.Exit(0); break; case '3': //FirstName Console.Write("New FirstName: "); string NewFirstname = Console.ReadLine(); using (var db = new TeamsContext()) { user.FirstName = NewFirstname; db.Entry(user).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); Console.WriteLine("Modify Complete!"); } break; case '4': //LastName Console.Write("New LastName: "); string NewLastname = Console.ReadLine(); using (var db = new TeamsContext()) { user.LastName = NewLastname; db.Entry(user).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); Console.WriteLine("Modify Complete!"); } break; case '5': //Date Of Birth DateTime NewDateOfBirth = new DateTime(); do { Invalid = false; Console.Write("New Date Of Birth(yyyy/mm/dd): "); try { NewDateOfBirth = DateTime.Parse(Console.ReadLine()); } catch (Exception) { Console.WriteLine("Invalid Format!"); Invalid = true; } } while (Invalid); using (var db = new TeamsContext()) { user.DateOFBirth = NewDateOfBirth; db.Entry(user).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); Console.WriteLine("Modify Complete!"); } break; case '6': Console.WriteLine("You are not authorized to delete users!"); break; case '0': return; default: Console.WriteLine("Invalid Input!"); Invalid = true; break; } } } while (Invalid); }