Exemple #1
0
        public void DeletePost()
        {
            bool  Invalid;
            int   ID = 0;
            Posts post;

            GetPosts();
            do
            {
                Console.Write("Select Post ID to delete or '0' to exit: ");
                Invalid = false;
                try
                {
                    ID = int.Parse(Console.ReadLine());
                }
                catch (Exception)
                {
                    Console.WriteLine("Invalid Input!");
                    Invalid = true;
                }
            } while (Invalid);
            if (ID == 0)
            {
                return;
            }
            post = FindPost(ID);
            using (var db = new TeamsContext())
            {
                post = db.Posts.Find(ID);
                db.Entry(post).State = EntityState.Deleted;
                db.SaveChanges();
            }
        }
        public void DeleteUserMessages(string Username)
        {
            List <Messages> messages;

            using (var db = new TeamsContext())
            {
                Console.WriteLine("Deleting messages...");
                messages = db.Messages.Where(m => m.UsernameSender == Username || m.Receiver == Username).Select(m => m).ToList();

                foreach (var message in messages)
                {
                    db.Entry(message).State = EntityState.Deleted;
                    db.SaveChanges();
                }
            }
        }
        /// <summary>
        /// Deletes Posts, Messages and the User.
        /// </summary>
        /// <param name="user"></param>
        public void DeleteUser(Users user)
        {
            MessageManager messages = new MessageManager();
            PostManager    posts    = new PostManager();

            Console.WriteLine("Please wait...\nRemoving Users data...");
            posts.DeleteUserPosts(user.Username);
            messages.DeleteUserMessages(user.Username);
            using (var db = new TeamsContext())
            {
                Console.WriteLine("Finishing...");
                db.Entry(user).State = System.Data.Entity.EntityState.Deleted;
                db.SaveChanges();
            }
            Console.WriteLine("Remove Complete!");
        }
Exemple #4
0
        public void DeleteUserPosts(string Username)
        {
            List <Posts> Posts;

            using (var db = new TeamsContext())
            {
                Console.WriteLine("Deleting Posts...");
                Posts = db.Posts.Where(p => p.UsernameSender == Username).Select(p => p).ToList();

                foreach (var item in Posts)
                {
                    db.Entry(item).State = EntityState.Deleted;
                    db.SaveChanges();
                }
            }
        }
        /// <summary>
        /// Creates A new User
        /// </summary>
        /// <param name="user"></param>
        public void CreateNewUser(UserDTO user)
        {
            Users NewUser = new Users();

            NewUser.Username    = user.username;
            NewUser.Password    = user.password;
            NewUser.FirstName   = user.firstname;
            NewUser.LastName    = user.lastname;
            NewUser.DateOFBirth = user.dateofbirth.Date;
            NewUser.UserType    = user.usertype;

            using (var db = new TeamsContext())
            {
                db.Users.Add(NewUser);
                db.SaveChanges();
            }

            Console.WriteLine($"{NewUser.FirstName} wellcome to BetterTeams!");
        }
Exemple #6
0
        public void CreatePost(string Sender, string Post)
        {
            Posts post = new Posts()
            {
                UsernameSender = Sender,
                DateTime       = DateTime.Now,
                Post           = Post
            };

            try
            {
                using (var db = new TeamsContext())
                {
                    db.Posts.Add(post);
                    db.SaveChanges();
                }
            }
            catch (Exception)
            {
                Console.WriteLine("Post Is Empty!!!");
            }
        }
        public void DeleteMessage()
        {
            int      ID;
            Messages message = null;

            GetMessages();
            Console.Write("Select Message ID to Delete Or 0 to Go Back:");

            try
            {
                ID      = int.Parse(Console.ReadLine());
                message = FindMessage(ID);
            }
            catch
            {
                ID = 0;
            }
            if (ID == 0)
            {
                return;
            }
            if (message != null)
            {
                using (var db = new TeamsContext())
                {
                    db.Entry(message).State = EntityState.Deleted;

                    db.SaveChanges();
                }
                Console.WriteLine("Removal Complete!");
            }
            else
            {
                Console.WriteLine("Message Not Found");
            }
        }
        public void SendMessage(string Sender, string Receiver)
        {
            Messages message = new Messages();

            string TextMessage    = Console.ReadLine();
            string FirstPartText  = "";
            string SecondPartText = "";

            if (TextMessage == null || TextMessage == " ")
            {
                TextMessage = "Empty Message";
            }
            if (TextMessage.Length <= 250)
            {
                message.UsernameSender = Sender;
                message.Receiver       = Receiver;
                message.DateTime       = DateTime.Now;
                message.Message        = TextMessage;
                using (var db = new TeamsContext())
                {
                    Console.WriteLine("Sending...");
                    db.Messages.Add(message);
                    db.SaveChanges();
                }
                Console.WriteLine("Μessage sent successfully!");
            }
            else
            {
                for (int i = 0; i < TextMessage.Length; i++)
                {
                    if (i < TextMessage.Length / 2)
                    {
                        FirstPartText = FirstPartText + TextMessage[i];
                    }
                    else
                    {
                        SecondPartText = SecondPartText + TextMessage[i];
                    }
                }
                message.UsernameSender = Sender;
                message.Receiver       = Receiver;
                message.DateTime       = DateTime.Now;
                message.Message        = FirstPartText;
                using (var db = new TeamsContext())
                {
                    Console.WriteLine("Sending (1/2)...");
                    db.Messages.Add(message);
                    db.SaveChanges();
                }
                Console.WriteLine("1/2 Complete");
                message.UsernameSender = Sender;
                message.Receiver       = Receiver;
                message.DateTime       = DateTime.Now;
                message.Message        = FirstPartText;
                using (var db = new TeamsContext())
                {
                    Console.WriteLine("Sending (2/2)...");
                    db.Messages.Add(message);
                    db.SaveChanges();
                }
                Console.WriteLine("Μessage sent!");
            }
        }
        /// <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);
        }
        /// <summary>
        /// Students Modification Access
        /// </summary>
        /// <param name="CurrentUser"></param>
        public void StudentModifyUser(Users User)
        {
            UIProcedures UI       = new UIProcedures();
            char         TryAgain = '0';

            UI.ShowProfile(User);
            ConsoleKeyInfo editChoice = Console.ReadKey(true);

            switch (editChoice.KeyChar)
            {
            case '1':
                Console.WriteLine("You cant change Username!");
                Thread.Sleep(1500);
                break;

            case '2':
                Console.WriteLine("***NOTE***\nApplication will Restart after changes!!!");
                UserSignUp EncryptPass = new UserSignUp();
                do
                {
                    Console.Write("Current Password: "******"New Password: "******"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);
                    }
                    else
                    {
                        Console.WriteLine("Invalid Password");
                        Console.WriteLine("Press 1 to Try Again");
                        TryAgain = Console.ReadKey(true).KeyChar;
                    }
                } while (TryAgain == '1');
                break;

            case '3':
                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();
                }
                break;

            case '4':
                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();
                }
                break;

            case '5':
                do
                {
                    Console.Write("New Date Of Birth(yyyy/mm/dd): ");
                    try
                    {
                        DateTime NewDateofbirth = DateTime.Parse(Console.ReadLine());
                        using (var db = new TeamsContext())
                        {
                            User.DateOFBirth     = NewDateofbirth;
                            db.Entry(User).State = System.Data.Entity.EntityState.Modified;
                            db.SaveChanges();
                        }
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Wrong Input!\nPress 1 to Try Again");
                        TryAgain = Console.ReadKey(true).KeyChar;
                    }
                } while (TryAgain == '1');
                break;

            case '0':
                return;

            default:
                break;
            }
        }