Пример #1
0
        private static void AddAward()
        {
            System.Console.WriteLine("Enter USER id");

            bool correctUserId = int.TryParse(System.Console.ReadLine(), out int userId);

            while (!correctUserId)
            {
                System.Console.WriteLine("Incorrect value, try again.");
                correctUserId = int.TryParse(System.Console.ReadLine(), out userId);
            }

            System.Console.WriteLine("Enter AWARD id");

            bool correctAwardId = int.TryParse(System.Console.ReadLine(), out int awardId);

            while (!correctAwardId)
            {
                System.Console.WriteLine("Incorrect value, try again.");
                correctAwardId = int.TryParse(System.Console.ReadLine(), out awardId);
            }

            if (userLogic.AddAward(userId, awardId))
            {
                System.Console.WriteLine("Award successfully added.");
                return;
            }

            System.Console.WriteLine("Failed.");
        }
Пример #2
0
        private static void AddAwardToUser()
        {
            Console.Write("Enter ID of user: "******"Id of user must be a number");
            }

            if (_awardLogic.GetAll().Count() == 0)
            {
                Console.WriteLine("Not a single award has been created yet");
                return;
            }

            Console.WriteLine();
            ShowAwards();

            Console.WriteLine();
            Console.WriteLine("Pick one of the Id`s: ");
            if (!int.TryParse(Console.ReadLine(), out int awardId))
            {
                throw new ArgumentException("Id of award must be a number");
            }

            _userLogic.AddAward(userId, awardId);
        }
Пример #3
0
        private static void AddAwardToUser()
        {
            Console.WriteLine("Enter user id");
            int userId = int.Parse(Console.ReadLine());

            Console.WriteLine("Enter award id");
            int awardId = int.Parse(Console.ReadLine());

            userLogic.AddAward(userId, awardId);
        }
Пример #4
0
		public ActionResult AddAward(UserAwardAddingModel model)
		{
			try
			{
				var relation = new Relation(model.Id, model.SelectedAward);
				userLogic.AddAward(relation);
				return View("Details", model);
			}
			catch (KeyNotFoundException)
			{
				return HttpNotFound();
			}
			catch (ArgumentException)
			{
				return HttpNotFound();
			}
		}
Пример #5
0
        private static void AddAwardsUser(IUserLogic userLogic, IAwardLogic awardLogic)
        {
            Console.Clear();
            Print(userLogic, awardLogic);
            Console.WriteLine("Enter user id: ");
            var  userId = Console.ReadLine();
            var  users  = userLogic.GetAll();
            User user;

            if (int.TryParse(userId, out int id) && id >= 0 && users.Count() - 1 >= id)
            {
                user = users.ElementAt(int.Parse(userId));
            }
            else
            {
                Console.Clear();
                Console.WriteLine("Error: User index does not exist");
                return;
            }

            Print(awardLogic);
            Console.WriteLine("Enter award id: ");
            var awardId = Console.ReadLine();
            var awards  = awardLogic.GetAll();

            if (int.TryParse(awardId, out id) && id >= 0 && awards.Count() - 1 >= id)
            {
                if (userLogic.AddAward(user, id))
                {
                    Console.Clear();
                }
                else
                {
                    Console.Clear();
                    Console.WriteLine("Error: This user already has this award");
                }
            }
            else
            {
                Console.Clear();
                Console.WriteLine("Error: Award index does not exist");
                return;
            }
        }
Пример #6
0
        private static void AddAwardToUser(IUserLogic userLogic)
        {
            string input;

            Console.WriteLine("input user Id to take award");
            input = Console.ReadLine();

            if (!int.TryParse(input, out int userId) || userId < 0)
            {
                Console.WriteLine("user Id is not correct");
            }
            else
            {
                Console.WriteLine("input Id of award");
                input = Console.ReadLine();

                if (!int.TryParse(input, out int awardId) || awardId < 0)
                {
                    Console.WriteLine("award Id is not correct");
                }
                else
                {
                    Console.WriteLine("input Title of award");
                    input = Console.ReadLine();

                    var user = new User
                    {
                        Id = userId,
                    };

                    var award = new Award
                    {
                        Id    = awardId,
                        Title = input,
                    };

                    userLogic.AddAward(user, award);
                }
            }
        }
Пример #7
0
        private void ChooseMode(int input, IUserLogic userLogic, IAwardLogic awardLogic)
        {
            if (input == 1)
            {
                Console.WriteLine("The list of users");
                foreach (var item in userLogic.GetAll())
                {
                    Console.WriteLine(item);
                }
            }
            else if (input == 2)
            {
                while (true)
                {
                    Console.WriteLine("Please insert the information about the user you want to create");
                    Console.WriteLine("Insert name:");

                    var  name        = Console.ReadLine();
                    bool correctName = false;

                    while (!correctName)
                    {
                        if (name.Trim().Length < 1)
                        {
                            Console.WriteLine("Name cannot be empty, try again");
                            name = Console.ReadLine();
                        }
                        else
                        {
                            correctName = true;
                        }
                    }


                    Console.WriteLine("Insert date of birth ");
                    Console.WriteLine("Your input must be in format day.month.year");

                    DateTime birthdate;

                    while (!DateTime.TryParse(Console.ReadLine(), out birthdate))
                    {
                        Console.WriteLine("Incorrect input of date");
                        Console.WriteLine("Try again");
                    }

                    userLogic.AddUser(new User(name, birthdate));
                }
            }

            else if (input == 3)
            {
                Console.WriteLine("Insert the id of the user you want to delete");

                int id;

                while (!Int32.TryParse(Console.ReadLine(), out id))
                {
                    Console.WriteLine("Incorrect input of id");
                    Console.WriteLine("Try again");
                }

                userLogic.RemoveUser(id);
            }

            else if (input == 4)
            {
                Console.WriteLine("Insert id of the user you want the award to be added to");

                int userId;

                while (!Int32.TryParse(Console.ReadLine(), out userId))
                {
                    Console.WriteLine("Incorrect input of user id");
                    Console.WriteLine("Try again");
                }

                Console.WriteLine("Insert id of the award");

                int awardId;

                while (!Int32.TryParse(Console.ReadLine(), out awardId))
                {
                    Console.WriteLine("Incorrect input of user id");
                    Console.WriteLine("Try again");
                }

                userLogic.AddAward(userId, awardId);
            }
            else if (input == 5)
            {
                Console.WriteLine("Insert the title of the award");

                var   title = Console.ReadLine();
                Award award = new Award(title);

                awardLogic.CreateAward(award);
            }
        }
Пример #8
0
        private static void UserMode()
        {
            while (true)
            {
                Menu();
                if (!int.TryParse(Console.ReadLine(), out int mode))
                {
                    Console.WriteLine("Incorrect input. Try again.");
                    continue;
                }

                switch (mode)
                {
                case 1:
                {
                    User user = CreateUser();
                    _userLogic.Add(user);
                    Console.WriteLine($"User added. User  {user.Id} : {user.Name}");
                    Console.WriteLine($"Press any key to continue");
                    Console.ReadLine();
                    break;
                }

                case 2:
                {
                    int  id   = GetId();
                    User user = _userLogic.GetById(id);
                    ShowUser(user);
                    Console.WriteLine($"Press any key to continue");
                    Console.ReadLine();
                    break;
                }

                case 3:
                {
                    ShowAllUsers();
                    Console.WriteLine($"Press any key to continue");
                    Console.ReadLine();
                    break;
                }

                case 4:
                {
                    int id = GetId();
                    if (_userLogic.RemoveById(id))
                    {
                        Console.WriteLine($"User with ID = {id} is removed.");
                    }
                    else
                    {
                        Console.WriteLine("Wrong id.");
                    }
                    Console.WriteLine($"Press any key to continue");
                    Console.ReadLine();
                    break;
                }

                case 5:
                {
                    ShowAllUsers();
                    Console.WriteLine("Select User to give Award");
                    User user = _userLogic.GetById(GetId());
                    if (user == null)
                    {
                        Console.WriteLine("Wrong id.");
                        break;
                    }

                    ShowAllAwards();
                    Console.WriteLine("Select Award to give");
                    Award award = _awardLogic.GetById(GetId());
                    if (award == null)
                    {
                        Console.WriteLine("Wrong id.");
                        break;
                    }

                    if (_userLogic.AddAward(user.Id, award.Id))
                    {
                        Console.WriteLine($"The Award \"{award.Title}\" has been given to the User \"{user.Name}\".");
                    }
                    else
                    {
                        Console.WriteLine($"Can't give the Award \"{award.Title}\" to the User \"{user.Name}\".");
                    }
                    Console.WriteLine($"Press any key to continue");
                    Console.ReadLine();
                    break;
                }

                case 6:
                {
                    ShowAllUsers();
                    Console.WriteLine("Select User to remove Award");
                    User user = _userLogic.GetById(GetId());
                    if (user == null)
                    {
                        Console.WriteLine("Wrong id.");
                        break;
                    }

                    ShowAllAwards();
                    Console.WriteLine("Select Award to remove");
                    Award award = _awardLogic.GetById(GetId());
                    if (award == null)
                    {
                        Console.WriteLine("Wrong id.");
                        break;
                    }

                    if (_userLogic.RemoveAward(user.Id, award.Id))
                    {
                        Console.WriteLine($"The Award \"{award.Title}\" has been remove to the User \"{user.Name}\".");
                    }
                    else
                    {
                        Console.WriteLine($"Can't remove the Award \"{award.Title}\" to the User \"{user.Name}\".");
                    }
                    Console.WriteLine($"Press any key to continue");
                    Console.ReadLine();
                    break;
                }

                case 7:
                {
                    AwardMode();
                    break;
                }

                case 0:
                {
                    break;
                }

                default:
                {
                    Console.WriteLine("Wrong. Try again.");
                    Console.ReadLine();
                    break;
                }
                }
                if (mode == 0)
                {
                    break;
                }
                Console.Clear();
            }
        }
Пример #9
0
 public static void AddAwardToUser(int userId, int awardId)
 {
     userLogic.AddAward(userId, awardId);
 }
Пример #10
0
        private static bool ProcessInput()
        {
            string command = ReadInput();

            string[] commandArgs = command.Split(separator,
                                                 StringSplitOptions.RemoveEmptyEntries);

            switch (commandArgs[0].ToLower())
            {
            case "add":
                switch (commandArgs[1].ToLower())
                {
                case "user":
                    userLogic.Add(new User()
                    {
                        Name        = ReadInput("Name"),
                        DateOfBirth = DateTime.Parse(ReadInput("Date of birth"))
                    });
                    break;

                case "award":
                    awardLogic.Add(new Award()
                    {
                        Title = ReadInput("Title")
                    });
                    break;

                default:
                    WriteLine("Usage: add <user/award>");
                    break;
                }
                break;

            case "remove":
                switch (commandArgs[1].ToLower())
                {
                case "user":
                    userLogic.Remove(int.Parse(commandArgs[2]));
                    break;

                case "award":
                    awardLogic.Remove(int.Parse(commandArgs[2]));
                    break;

                default:
                    WriteLine("Usage: remove <user/award>");
                    break;
                }
                break;

            case "list":
                switch (commandArgs[1].ToLower())
                {
                case "users":
                    foreach (var entry in userLogic.GetAll())
                    {
                        WriteLine(entry.ToString());
                        foreach (var award in userLogic.GetAwardsFor(entry.Id, awardLogic))
                        {
                            Write(" - ");
                            WriteLine(award.ToString());
                        }
                    }
                    break;

                case "awards":
                    foreach (var entry in awardLogic.GetAll())
                    {
                        WriteLine(entry.ToString());
                    }
                    break;

                default:
                    WriteLine("Usage: list <users/awards>");
                    break;
                }
                break;

            case "award":
                switch (commandArgs[1].ToLower())
                {
                case "assign":
                    userLogic.AddAward(int.Parse(commandArgs[2]),
                                       awardLogic.GetById(int.Parse(commandArgs[3])));
                    break;

                case "revoke":
                    userLogic.RemoveAward(int.Parse(commandArgs[2]),
                                          awardLogic.GetById(int.Parse(commandArgs[3])));
                    break;

                default:
                    WriteLine("Usage: award <assign/revoke> (userId) (awardId)");
                    break;
                }
                break;

            case "exit":
                return(false);
            }
            return(true);
        }
Пример #11
0
 public static void AddAwardForUser(uint userId, uint awardId)
 {
     userLogic.AddAward(userId, awardId, awardsLogic);
     userLogic.Exit();
 }
Пример #12
0
 private static void AddAwardToUser(IUserLogic awardLogic, int userId, int awardId)
 {
     awardLogic.AddAward(userId, awardId);
 }