Exemplo n.º 1
0
        private static void AwardUser(IUserLogic userLogic, IAwardLogic awardLogic, IUserAwardLogic userAwardLogic)
        {
            var useraward = new UserAward();

            Console.WriteLine();
            try
            {
                while (true)
                {
                    int _userId = ReadInt("Enter the Id of User you want to award: ");
                    if (userLogic.CheckById(_userId))
                    {
                        useraward.UserId = _userId;
                        break;
                    }
                    else
                    {
                        Console.WriteLine("There's no user with such Id");
                    }
                }

                Console.WriteLine();

                while (true)
                {
                    int _awardId = ReadInt("Enter the Id of Award you want to award with: ");
                    if (awardLogic.CheckById(_awardId))
                    {
                        useraward.AwardId = _awardId;
                        break;
                    }
                    else
                    {
                        Console.WriteLine("There's no award with such Id");
                    }
                }

                var getUsersWithSameId             = userAwardLogic.GetAll().Where(x => x.UserId == useraward.UserId);
                var getUsersWithSameIdAndSameAward = getUsersWithSameId.Where(x => x.AwardId == useraward.AwardId).Count();

                if (getUsersWithSameIdAndSameAward > 0)
                {
                    Console.WriteLine();
                    Console.WriteLine("This user already have award with id \"{0}\". He can't get this award twice.", useraward.AwardId);
                }
                else
                {
                    userAwardLogic.Add(useraward);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: {0}", ex.Message);
            }

            Console.WriteLine();
            Init();
        }