Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace UserLogin
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.OutputEncoding = Encoding.UTF8;
- Console.Write("Enter username: ");
- string username = Console.ReadLine();
- Console.Write("Enter password: ");
- string password = Console.ReadLine();
- LoginValidation validation = new LoginValidation(username, password, ExceptionAction);
- User user = new User();
- if (validation.ValidateUserInput(user))
- {
- Console.WriteLine();
- Console.WriteLine("-----Sucessfull login!-----");
- Console.WriteLine();
- switch (LoginValidation.currentUserRole)
- {
- case UserRoles.ADMIN:
- Console.WriteLine("Welcome, ADMIN!");
- user.PrintInfo();
- AdminActions();
- break;
- case UserRoles.INSPECTOR:
- Console.WriteLine("Welcome, INSPECTOR!");
- user.PrintInfo();
- break;
- case UserRoles.PROFESSOR:
- Console.WriteLine("Welcome, PROFESSOR!");
- user.PrintInfo();
- break;
- case UserRoles.STUDENT:
- Console.WriteLine("Welcome, STUDENT!");
- user.PrintInfo();
- break;
- }
- Console.WriteLine();
- }
- else
- {
- //Console.WriteLine(validation.ErrorMessage);
- }
- //Console.ReadLine();
- }
- public static void AdminActions()
- {
- Console.WriteLine("----------------------------------");
- Console.WriteLine("Изберете опция:");
- Console.WriteLine("0: Изход");
- Console.WriteLine("1: Промяна на роля на потребител");
- Console.WriteLine("2: Промяна на активност на потребител");
- Console.WriteLine("3: Списък на потребителите");
- Console.WriteLine("4: Преглед на лог на актовност");
- Console.WriteLine("5: Преглед текуща активност");
- Console.Write("\nИзбор: ");
- int choice = int.Parse(Console.ReadLine());
- switch (choice)
- {
- case 0:
- Environment.Exit(1);
- break;
- case 1:
- ChangeUserRole();
- break;
- case 2:
- ChangeUserActivity();
- break;
- case 3:
- ListAllUsers();
- break;
- case 4:
- ListLogActivity();
- break;
- case 5:
- GetCurrentSessionActivities();
- break;
- default:
- Console.WriteLine("Oops! Невалиден избор");
- AdminActions();
- break;
- }
- }
- public static void GetCurrentSessionActivities()
- {
- Console.WriteLine("Въведете филтър за търсене: ");
- string filter = Console.ReadLine();
- Logger.GetCurrentSessionActivities(filter);
- AdminActions();
- }
- public static void ListLogActivity()
- {
- if (File.Exists("log.txt") == true)
- {
- using (StreamReader Reader = new StreamReader("log.txt"))
- {
- StringBuilder Sb = new StringBuilder();
- Sb.Append(Reader.ReadToEnd());
- {
- Console.WriteLine("The Log File is read");
- }
- Console.WriteLine(Sb);
- Reader.Close();
- }
- }
- AdminActions();
- }
- public static void ListAllUsers()
- {
- Dictionary<string, int> allUsers = UserData.AllUsersUsernames();
- foreach (KeyValuePair<string, int> user in allUsers)
- {
- Console.WriteLine(user.Value + ". " + user.Key);
- }
- AdminActions();
- }
- public static void ChangeUserRole()
- {
- Console.WriteLine();
- Console.Write("Потребителско име: ");
- string userToEdit = Console.ReadLine();
- Dictionary<string, int> allUsers = UserData.AllUsersUsernames();
- if (!allUsers.ContainsKey(userToEdit) || userToEdit.Equals(String.Empty))
- {
- Console.WriteLine();
- Console.WriteLine("Несъществуващ потребител!");
- AdminActions();
- }
- Console.WriteLine("1.ADMIN, 2.INSPECTOR, 3.PROFESSOR, 4.STUDENT");
- Console.Write("Нова роля: ");
- int role = int.Parse(Console.ReadLine());
- if (role != 1 && role != 2 && role !=3 && role != 4)
- {
- Console.WriteLine("Oops! Невалидна роля!");
- ChangeUserRole();
- }
- if (allUsers.ContainsKey(userToEdit))
- {
- UserData.AssignUserRole(allUsers[userToEdit], (UserRoles)role);
- Console.WriteLine();
- Console.WriteLine("Успешно променена роля!");
- AdminActions();
- }
- else
- {
- Console.WriteLine();
- Console.WriteLine("Невалиден потребител!");
- AdminActions();
- }
- }
- public static void ChangeUserActivity()
- {
- Console.WriteLine();
- Console.Write("Потребителско име: ");
- string userToEdit = Console.ReadLine();
- Dictionary<string, int> allUsers = UserData.AllUsersUsernames();
- Console.Write("Нова дата на активност: ");
- string date = Console.ReadLine();
- DateTime validTo;
- if (DateTime.TryParse(date, out validTo))
- {
- if (allUsers.ContainsKey(userToEdit))
- {
- UserData.SetUserActiveTo(allUsers[userToEdit], validTo);
- Console.WriteLine();
- Console.WriteLine("Успешно сменена дата!");
- AdminActions();
- }
- else
- {
- Console.WriteLine("Невалиден потребител!");
- AdminActions();
- }
- }
- else
- {
- Console.WriteLine("Невалидна дата!");
- AdminActions();
- }
- }
- public static void ExceptionAction(string s)
- {
- Console.WriteLine("Oops! " + s);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement