Exemple #1
0
        internal static void AddAwardToUser()
        {
            Console.WriteLine("Input user Id:");
            string input_user = Console.ReadLine();

            if (!UserIds.ContainsKey(int.Parse(input_user)))
            {
                Console.WriteLine("Wrong user Id!");
                return;
            }

            Guid userId = UserIds[int.Parse(input_user)];

            Console.WriteLine("Input award Id:");
            string input_award = Console.ReadLine();

            if (!AwardIds.ContainsKey(int.Parse(input_award)))
            {
                Console.WriteLine("Wrong award Id!");
                return;
            }

            Guid awardId = AwardIds[int.Parse(input_award)];

            try
            {
                if (usersmanager.AddAwardToUser(userId, awardId))
                {
                    Console.WriteLine("Award added successfully");
                }
                else
                {
                    Console.WriteLine("Award do not added");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Award do not added");
                Console.WriteLine(e.Message);
                return;
            }
        }
Exemple #2
0
        static void Run()
        {
            for (; ;)
            {
                Console.WriteLine("-----------------------------------"
                                  + Environment.NewLine + "Please choose option:"
                                  + Environment.NewLine + "\t 1: Add user"
                                  + Environment.NewLine + "\t 2: Delete user"
                                  + Environment.NewLine + "\t 3: See all users"
                                  + Environment.NewLine + "\t 4: Add award"
                                  + Environment.NewLine + "\t 5: Add award to user"
                                  + Environment.NewLine + "\t 6: Delete award"
                                  + Environment.NewLine + "\t 7: See all awards"
                                  + Environment.NewLine + "-----------------------------------");

                if (uint.TryParse(Console.ReadLine(), out uint option) &&
                    option > 0 &&
                    option < 8)
                {
                    UsersManager  manager = new UsersManager();
                    AwardsManager Manager = new AwardsManager();
                    Guid          UserId;
                    Guid          AwardId;
                    switch (option)
                    {
                    case 1:
                    {
                        Console.WriteLine("Enter user name");
                        var Name = Console.ReadLine();

                        Console.WriteLine("Enter date of birth");
                        DateTime DateOfBirth;

                        if (!DateTime.TryParse(Console.ReadLine(), out DateOfBirth))
                        {
                            Console.WriteLine("Error!!! Wrong date format");
                        }
                        else if (DateOfBirth > DateTime.Now)
                        {
                            Console.WriteLine("Error!!! Wrong date");
                        }
                        else
                        {
                            Userss newUser = new Userss(Name, DateOfBirth);

                            manager.AddUser(newUser);
                        }

                        break;
                    }

                    case 2:
                    {
                        Console.WriteLine("Enter user id");

                        if (!Guid.TryParse(Console.ReadLine(), out UserId))
                        {
                            Console.WriteLine("Error!!! Wrong id format");
                        }
                        else if (!manager.GetAllUsers().Exists(n => n.UserId == UserId))
                        {
                            Console.WriteLine("Error!!! This user does not exist");
                        }
                        else
                        {
                            manager.DeleteUser(UserId);
                        }


                        break;
                    }

                    case 3:
                    {
                        foreach (Userss user in manager.GetAllUsers())
                        {
                            Console.WriteLine(user);
                        }

                        break;
                    }

                    case 4:
                    {
                        Console.WriteLine("Enter award name");
                        var Name = Console.ReadLine();

                        Awards award = new Awards(Name);
                        Manager.AddAward(award);

                        break;
                    }

                    case 5:
                    {
                        Console.WriteLine("Enter user Id");

                        if (!Guid.TryParse(Console.ReadLine(), out UserId))
                        {
                            Console.WriteLine("Error!!! Wrong id format");
                        }
                        else if (!manager.GetAllUsers().Exists(n => n.UserId == UserId))
                        {
                            Console.WriteLine("Error!!! This user does not exist");
                        }
                        else
                        {
                            Console.WriteLine("Enter award Id");

                            if (!Guid.TryParse(Console.ReadLine(), out AwardId))
                            {
                                Console.WriteLine("Error!!! Wrong id format");
                            }
                            else if (!Manager.GetAllAwards().Exists(n => n.Id == AwardId))
                            {
                                Console.WriteLine("Error!!! This award does not exist");
                            }
                            else
                            {
                                manager.AddAwardToUser(UserId, AwardId);
                            }
                        }

                        break;
                    }

                    case 6:
                    {
                        Console.WriteLine("Enter award Id");

                        if (!Guid.TryParse(Console.ReadLine(), out AwardId))
                        {
                            Console.WriteLine("Error!!! Wrong id format");
                        }
                        else if (!Manager.GetAllAwards().Exists(n => n.Id == AwardId))
                        {
                            Console.WriteLine("Error!!! This award does not exist");
                        }
                        else
                        {
                            Manager.DeleteAward(AwardId);
                        }

                        break;
                    }

                    case 7:
                    {
                        foreach (Awards award in Manager.GetAllAwards())
                        {
                            Console.WriteLine(award);
                        }

                        break;
                    }

                    default:
                    {
                        Console.WriteLine("Unknown command!");
                        break;
                    }
                    }
                }
                else
                {
                    Console.WriteLine("Error!!! Wrong option");
                }
            }
        }