private void loginbtn_Click(object sender, RoutedEventArgs e)
        {
            string tx = passtxtbox.Text;

            if (tx.Length >= 8)
            {
                this.id       = this.idtxtbox.Text;
                this.password = this.passtxtbox.Text;
                this.result   = this.l.IsLogInValid(id, password);

                if (result == 1)
                {
                    this.Hide();
                    Admin.Admin a = new Admin.Admin();
                    a.Show();
                }
                else if (result == 2)
                {
                    this.Hide();
                    Employee.Employee ee = new Employee.Employee();
                    ee.Show();
                }
                else if (result == 0)
                {
                    MessageBox.Show("Invalid ID or Password");
                }
                else
                {
                }
            }
            else
            {
                MessageBox.Show("Wrong Password");
            }
        }
Esempio n. 2
0
        public static void Initialize()
        {
            // Admin
            AdminService = new NUnitTester.Admin.Admin();
            ReplaceServiceUrl(AdminService, SystemType.CprBroker);
            Console.WriteLine(AdminService.Url);

            AdminApplicationHeader = new NUnitTester.Admin.ApplicationHeader()
            {
                ApplicationToken = TestData.BaseAppToken, UserToken = TestData.userToken
            };
            AdminService.ApplicationHeaderValue = AdminApplicationHeader;

            // Part
            PartService = new CprBroker.NUnitTester.Part.Part();
            ReplaceServiceUrl(PartService, SystemType.CprBroker);
            Console.WriteLine(PartService.Url);

            PartApplicationHeader = new Part.ApplicationHeader()
            {
                ApplicationToken = TestData.BaseAppToken, UserToken = TestData.userToken
            };
            PartService.ApplicationHeaderValue = PartApplicationHeader;

            // Subscriptions
            SubscriptionsService = new NUnitTester.Subscriptions.Subscriptions();
            ReplaceServiceUrl(SubscriptionsService, SystemType.EventBroker);
            Console.WriteLine(SubscriptionsService.Url);

            SubscriptionsApplicationHeader = new CprBroker.NUnitTester.Subscriptions.ApplicationHeader()
            {
                ApplicationToken = TestData.BaseAppToken, UserToken = TestData.userToken
            };
            SubscriptionsService.ApplicationHeaderValue = SubscriptionsApplicationHeader;

            // Events
            EventsService = new CprBroker.NUnitTester.Events.Events();
            ReplaceServiceUrl(EventsService, SystemType.CprBroker);
            Console.WriteLine(EventsService.Url);

            EventsApplicationHeader = new CprBroker.NUnitTester.Events.ApplicationHeader()
            {
                ApplicationToken = TestData.BaseAppToken, UserToken = TestData.userToken
            };
            EventsService.ApplicationHeaderValue = EventsApplicationHeader;

            // Notification
            NotificationService = new CprBroker.NUnitTester.Notification.Notification();
            ReplaceServiceUrl(NotificationService, SystemType.EventBroker);
            Console.WriteLine(NotificationService.Url);
        }
Esempio n. 3
0
        static void LookingAround(ref User.User user, ref Admin.Admin a)
        {
            Console.Clear();
            Console.WriteLine("1) For View Post");
            Console.WriteLine("2) For Like Post");
            string ch = Console.ReadLine();

            Console.Clear();
            if (Convert.ToInt32(ch) == 1)
            {
                foreach (var item in a.Posts)
                {
                    item.Show();
                }
                Console.WriteLine("Enter post id:");
                int ab = LookForPost(a.Posts, Console.ReadLine());
                if (ab != -1)
                {
                    Console.Clear();
                    a.Posts[ab].Show();
                    SendMail(a.Email, a.Posts, ab, user, "View");
                    a.Posts[ab].ViewCount += 1;
                    Console.Clear();
                }
            }
            else if (Convert.ToInt32(ch) == 2)
            {
                foreach (var item in a.Posts)
                {
                    item.Show();
                }
                Console.WriteLine("Enter post id:");
                dynamic ab = LookForPost(a.Posts, Console.ReadLine());
                if (ab != -1)
                {
                    SendMail(a.Email, a.Posts, ab, user, "Like");
                    a.Posts[ab].LikeCount += 1;
                }
                Console.Clear();
            }
            else
            {
                throw new Exception("Invalid choose!");
            }
        }
Esempio n. 4
0
        public void RemoveAdmin(int id)
        {
            var adminIndex = Array.FindIndex(Admins, admin => admin.Id == id);

            if (adminIndex < 0)
            {
                throw new DatabaseException($"There is no admin associated this id -> {id}");
            }

            var temp = new Admin.Admin[Admins.Length - 1];

            if (temp != null)
            {
                Array.Copy(Admins, temp, adminIndex);
                Array.Copy(Admins, adminIndex + 1, temp, adminIndex, Admins.Length - adminIndex - 1);
            }

            Admins = temp;
        }
Esempio n. 5
0
        public void AddAdmin(ref Admin.Admin admin)
        {
            var newLength = (Admins != null) ? Admins.Length + 1 : 1;
            var temp      = new Admin.Admin[newLength];

            if (temp == null)
            {
                throw new DatabaseException("Can not allocate new memory!");
            }

            if (Admins != null)
            {
                Array.Copy(Admins, temp, Admins.Length);
            }

            temp[newLength - 1] = admin;

            Admins = temp;
        }
Esempio n. 6
0
        static char Choosing(string choose, ref Admin.Admin a, ref User.User[] users)
        {
            Console.Clear();
            if (Convert.ToInt32(choose) == 1)
            {
                Console.Write("Enter mail: ");
                mail = Console.ReadLine();
                Console.Write("Enter password: "******"Enter mail: ");
                mail = Console.ReadLine();
                Console.Write("Enter password: "******"Invalid mail or password");
                }
            }
            else
            {
                throw new Exception("Invalid choose");
            }
        }
Esempio n. 7
0
        static void AddOrNot(ref Admin.Admin a)
        {
            Console.Write("Do you wanna add post (1 for yes): ");
            bool isInt = int.TryParse(Console.ReadLine(), out int res);

            if (isInt)
            {
                if (res == 1)
                {
                    Console.Clear();
                    Console.Write("Enter content: ");
                    a.addPost(new Post.Post()
                    {
                        Content = Console.ReadLine(), CreatingDate = DateTime.Now, LikeCount = 0, ViewCount = 0
                    });
                }
            }
            else
            {
                throw new Exception("Invalid type!");
            }
        }
Esempio n. 8
0
        public IAdmin AddAdmin(IClient client, string name)
        {
            IAdmin admin = new Admin.Admin(Guid.NewGuid(), name);

            admin.SendData      += PlayerOnSendData;
            admin.PageData      += PlayerOnPageData;
            client.DataReceived += ClientPlayingOnDataReceived;
            PlayingClient playingClient = new PlayingClient
            {
                Client = client,
                Player = admin
            };

            lock (_playingClientLockObject)
            {
                _players.TryAdd(admin, playingClient);
                _clients.TryAdd(client, playingClient);
            }

            admin.Send("Welcome master {0}", name);

            return(admin);
        }
Esempio n. 9
0
        public void Start()
        {
            Admin.Admin admin = new Admin.Admin()
            {
                Username = "******",
                Email    = "*****@*****.**",
                Password = "******",
            };
            User.User u1 = new User.User()
            {
                Name     = "User",
                Surname  = "Number 1",
                Email    = "*****@*****.**",
                Password = "******"
            };
            User.User u2 = new User.User()
            {
                Name     = "Sun",
                Surname  = "Glasses",
                Email    = "*****@*****.**",
                Password = "******"
            };
            User.User u3 = new User.User()
            {
                Name     = "Moon",
                Surname  = "Shine",
                Email    = "*****@*****.**",
                Password = "******"
            };
            Post.Post p1 = new Post.Post()
            {
                Content      = "Forest Holiday",
                CreatingDate = new DateTime(2017, 2, 25),
                LikeCount    = 100,
                ViewCount    = 160
            };

            Post.Post p2 = new Post.Post()
            {
                Content      = "Snowing woww!",
                CreatingDate = new DateTime(2015, 12, 13),
                LikeCount    = 20,
                ViewCount    = 22
            };

            Post.Post p3 = new Post.Post()
            {
                Content      = "Happy Easter everyone!",
                CreatingDate = new DateTime(2021, 3, 17),
                LikeCount    = 2,
                ViewCount    = 14
            };

            admin.addPost(p1);
            admin.addPost(p2);
            admin.addPost(p3);

            User.User[] users = new User.User[3] {
                u1, u2, u3
            };
            dynamic a;

            while (true)
            {
                Console.WriteLine("1)Admin");
                Console.WriteLine("2)User");
                try
                {
                    a = Choosing(Console.ReadLine(), ref admin, ref users);
                    Console.Clear();
                    if (a == 'u')
                    {
                        while (true)
                        {
                            try
                            {
                                LookingAround(ref users[indexofuser], ref admin);
                                break;
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
Esempio n. 10
0
 public void WriteNotification(Admin.Admin admin, Notification.Notification newnot)
 {
     admin.AddNotification(newnot);
 }
Esempio n. 11
0
        static void Main(string[] args)
        {
            var db      = new Database.Database();
            var session = new Session.LoginAccountSession();
            var user    = new User.User
            {
                Email      = "*****@*****.**", Name = "test", Surname = "testov", Username = "******", Password = "******",
                Activation = true
            };

            var admin = new Admin.Admin
            {
                Email    = "*****@*****.**",
                Username = "******",
                Password = "******"
            };

            db.AddUser(ref user);

            db.AddAdmin(ref admin);
            var mainMenuLoop = true;

            while (mainMenuLoop)
            {
                ConsoleInterface.PrintMenu(ConsoleInterface.MainMenuOptions);

                switch ((MainMenuOptions)ConsoleInterface.InputChoice(ConsoleInterface.MainMenuOptions.Length))
                {
                case MainMenuOptions.ADMIN:
                {
                    if (!session.Status)
                    {
                        Console.Clear();
                        string username, password;


                        Console.Write("Username: "******"Password: "******"Username: "******"Password: "******"Username: "******"Name: ");

                                name = Console.ReadLine();

                                try
                                {
                                    UserHelper.CheckForbiddenCharacter(name);
                                    break;
                                }
                                catch (Exception e)
                                {
                                    var line = Console.CursorTop;
                                    Console.ForegroundColor = ConsoleColor.DarkRed;
                                    Console.WriteLine(e.Message);
                                    ConsoleHelper.ClearConsole(line - 1, 10);
                                }
                            }

                            var surname = String.Empty;

                            while (true)
                            {
                                Console.Write("Surname: ");

                                surname = Console.ReadLine();

                                try
                                {
                                    UserHelper.CheckForbiddenCharacter(surname);
                                    break;
                                }
                                catch (Exception e)
                                {
                                    var line = Console.CursorTop;
                                    Console.ForegroundColor = ConsoleColor.DarkRed;
                                    Console.WriteLine(e.Message);
                                    ConsoleHelper.ClearConsole(line - 1, 10);
                                }
                            }

                            var age = 0;

                            while (true)
                            {
                                try
                                {
                                    Console.Write("Age: ");

                                    age = Convert.ToInt32(Console.ReadLine());
                                    UserHelper.CheckAge(age);
                                    break;
                                }
                                catch (Exception e)
                                {
                                    var line = Console.CursorTop;
                                    Console.ForegroundColor = ConsoleColor.DarkRed;
                                    Console.WriteLine(e.Message);
                                    ConsoleHelper.ClearConsole(line - 1, 10);
                                }
                            }

                            var email = String.Empty;

                            while (true)
                            {
                                Console.Write("E-mail: ");

                                email = Console.ReadLine();

                                try
                                {
                                    MailHelper.ValidateMail(email);
                                    break;
                                }
                                catch (Exception e)
                                {
                                    var line = Console.CursorTop;
                                    Console.ForegroundColor = ConsoleColor.DarkRed;
                                    Console.WriteLine(e.Message);
                                    ConsoleHelper.ClearConsole(line - 1, 10);
                                }
                            }

                            var password = String.Empty;

                            while (true)
                            {
                                Console.Write("Password: "******"Confirmation code sent! Check your mail!");
                                Console.ResetColor();

                                var accountCreated = false;
                                var tryCount       = 3;
                                while (tryCount-- > 0)
                                {
                                    Console.Write("Code > ");
                                    Console.ForegroundColor = ConsoleColor.DarkGreen;

                                    var code = Console.ReadLine();

                                    Console.ResetColor();

                                    if (CreateAccountSession.ConfirmAccount(ref newUser, code))
                                    {
                                        CreateAccountSession.Registration(ref db, ref newUser);
                                        session.Status          = true;
                                        session.User            = newUser;
                                        accountCreated          = true;
                                        Console.ForegroundColor = ConsoleColor.DarkRed;
                                        Console.WriteLine("Account activated!");
                                        Console.ResetColor();
                                        break;
                                    }

                                    Console.ForegroundColor = ConsoleColor.DarkRed;
                                    Console.WriteLine("Code is wrong! Try again.");
                                    Console.WriteLine($"You can try {tryCount} more!");
                                    Helper.ConsoleHelper.ClearConsole();
                                }

                                if (!accountCreated)
                                {
                                    Console.WriteLine("You can try later!");
                                }
                            }
                            catch (Exception e)
                            {
                                Console.ForegroundColor = ConsoleColor.DarkRed;
                                Console.WriteLine(e.Message);
                                Helper.ConsoleHelper.ClearConsole();
                            }


                            break;
                        }

                        case LoginMenuOptions.BACK:
                        {
                            loginMenuLoop = false;
                            break;
                        }
                        }
                        //user choices
                    }
                    break;
                }

                case MainMenuOptions.EXIT:
                {
                    mainMenuLoop = false;
                    break;
                }

                default:
                    break;
                }
            }
        }