Пример #1
0
 public General(IServiceProvider serviceProvider) : base(serviceProvider)
 {
     _serviceProvider   = serviceProvider;
     _pollRepository    = _serviceProvider.GetRequiredService <PollRepository>();
     _commandService    = _serviceProvider.GetRequiredService <CommandService>();
     _moderationService = _serviceProvider.GetRequiredService <ModerationService>();
 }
Пример #2
0
        public async Task deleted_user_cannot_create_poll()         // Nicolas
        {
            using (PollContext pollContext = TestHelpers.CreatePollContext())
            {
                PollContextAccessor pollContextAccessor = new PollContextAccessor(pollContext);
                UserRepository      userRepository      = new UserRepository(pollContextAccessor);
                PollRepository      pollRepository      = new PollRepository(pollContextAccessor);

                Result <User> user = await TestHelpers.UserService.CreateUser(userRepository, $"test-{Guid.NewGuid()}@test.fr", $"Test-{Guid.NewGuid()}", "validpassword");

                Result <User> userGuest = await TestHelpers.UserService.CreateUser(userRepository, $"test-{Guid.NewGuid()}@test.fr", $"Test-{Guid.NewGuid()}", "validpassword");

                Result res = await TestHelpers.UserService.DeleteUser(pollContext, userRepository, pollRepository, user.Value.UserId);

                res.IsSuccess.Should().BeTrue();

                Result <Poll> pollRes = await TestHelpers.PollService.CreatePoll(pollContext, pollRepository, userRepository, new NewPollDto()
                {
                    AuthorId       = user.Value.UserId,
                    Question       = "A question",
                    Proposals      = new string[] { "Proposal A", "Proposal B" },
                    GuestNicknames = new string[] { userGuest.Value.Nickname }
                });

                pollRes.Error.Should().Be(Errors.AccountDeleted);
            }
        }
Пример #3
0
        public PollController()
        {
            var pollRepo = new PollRepository(_data);

            _poll     = new PollManager(pollRepo);
            _response = new ResponseManager(new ResponseRepository(_data));
        }
Пример #4
0
        public async Task guest_add_answer_to_proposal()
        {
            using (PollContext pollContext = TestHelpers.CreatePollContext())
            {
                PollContextAccessor pollContextAccessor = new PollContextAccessor(pollContext);
                var pollRepository = new PollRepository(pollContextAccessor);
                var userRepository = new UserRepository(pollContextAccessor);


                string email    = $"test-{Guid.NewGuid()}@test.fr";
                string nickname = $"Test-{Guid.NewGuid()}";

                Result <User> user = await TestHelpers.UserService.CreateUser(userRepository, email, nickname, "validpassword");

                Result <User> guest = await TestHelpers.UserService.CreateUser(userRepository, $"{email}-guest", $"{nickname}-guest", "validpassword");

                var pollDto = new NewPollDto
                {
                    AuthorId       = user.Value.UserId,
                    Question       = "Test-Question ",
                    GuestNicknames = new[] { guest.Value.Nickname },
                    Proposals      = new[] { "proposal1", "proposal2" },
                };
                var pollCreated = await TestHelpers.PollService.CreatePoll(pollContext, pollRepository, userRepository, pollDto);

                var addAnswer = await TestHelpers.PollService.Answer(pollContext, pollRepository, pollCreated.Value.PollId, guest.Value.UserId, pollCreated.Value.Proposals[0].ProposalId);

                addAnswer.IsSuccess.Should().BeTrue();
                await TestHelpers.PollService.DeletePoll(pollContext, pollRepository, pollCreated.Value.PollId);

                await TestHelpers.UserService.DeleteUser(pollContext, userRepository, pollRepository, user.Value.UserId);

                await TestHelpers.UserService.DeleteUser(pollContext, userRepository, pollRepository, guest.Value.UserId);
            }
        }
Пример #5
0
        public async Task create_poll()
        {
            using (PollContext pollContext = TestHelpers.CreatePollContext())
            {
                PollContextAccessor pollContextAccessor = new PollContextAccessor(pollContext);
                PollRepository      sut = new PollRepository(pollContextAccessor);

                // We should create user for create poll associated with this user
                UserRepository userRepository = new UserRepository(pollContextAccessor);
                string         email          = $"{Guid.NewGuid()}@test.org";
                string         nickname       = $"Test-{Guid.NewGuid()}";
                User           user           = new User(0, email, nickname, "hash", false);
                Result         userCreated    = await userRepository.Create(user);

                Model.Poll poll = new Model.Poll(0, user.UserId, "Question?", false);

                Result creationStatus = await sut.Create(poll);

                userCreated.IsSuccess.Should().BeTrue();
                creationStatus.IsSuccess.Should().BeTrue();
                Result <Model.Poll> foundPoll = await sut.FindById(poll.PollId);

                foundPoll.IsSuccess.Should().BeTrue();
                foundPoll.Value.AuthorId.Should().Be(poll.AuthorId);
                foundPoll.Value.PollId.Should().Be(poll.PollId);
                foundPoll.Value.Question.Should().Be(poll.Question);
                foundPoll.Value.IsDeleted.Should().BeFalse();

                await TestHelpers.PollService.DeletePoll(pollContext, sut, poll.PollId);

                await TestHelpers.UserService.DeleteUser(pollContext, userRepository, sut, user.UserId);
            }
        }
Пример #6
0
        public UnitOfWork(ApplicationDbContext dbContext)
        {
            _dbContext = dbContext;

            Users   = new UserRepository(dbContext);
            Polls   = new PollRepository(dbContext);
            Answers = new AnswerRepository(dbContext);
        }
Пример #7
0
        public HomeController()
        {
            var PollRepo = new PollRepository(new DataEntities());

            _poll = new PollManager(PollRepo);

            _vote = new VoteService();
        }
Пример #8
0
        public void TestInitialize()
        {
            _mockPolls = new Mock <IDbSet <Poll> >();
            var mockContext = new Mock <IApplicationDbContext>();

            mockContext.SetupGet(c => c.Polls).Returns(_mockPolls.Object);
            _pollRepository = new PollRepository(mockContext.Object);
        }
Пример #9
0
 public Moderator(IServiceProvider serviceProvider) : base(serviceProvider)
 {
     _serviceProvider   = serviceProvider;
     _userRepository    = _serviceProvider.GetRequiredService <UserRepository>();
     _pollRepository    = _serviceProvider.GetRequiredService <PollRepository>();
     _muteRepository    = _serviceProvider.GetRequiredService <MuteRepository>();
     _moderationService = _serviceProvider.GetRequiredService <ModerationService>();
 }
Пример #10
0
        public async Task create_poll()
        {
            using (PollContext pollContext = TestHelpers.CreatePollContext())
            {
                var pollContextAccessor = new PollContextAccessor(pollContext);
                var userRepository      = new UserRepository(pollContextAccessor);
                var sut         = new PollRepository(pollContextAccessor);
                var userService = TestHelpers.UserService;

                // create the user that'll later be the poll author
                var email    = $"{Guid.NewGuid()}@test.org";
                var nickname = $"Test-{Guid.NewGuid()}";
                await userService.CreateUser(
                    userRepository,
                    email,
                    nickname,
                    "test-hash"
                    );

                var author = await userService.FindByNickname(userRepository, nickname);

                // create the guests that'll be used to create the poll
                var guest1 = await TestHelpers.UserService.CreateUser(
                    userRepository,
                    $"{Guid.NewGuid()}@test.org",
                    $"Test-{Guid.NewGuid()}",
                    "test-hash"
                    );

                var guest2 = await TestHelpers.UserService.CreateUser(
                    userRepository,
                    $"{Guid.NewGuid()}@test.org",
                    $"Test-{Guid.NewGuid()}",
                    "test-hash"
                    );

                var poll = new Model.Poll(0, author.Value.UserId, "question?", false);
                poll.AddGuest(guest1.Value.UserId, await sut.GetNoProposal());
                poll.AddGuest(guest2.Value.UserId, await sut.GetNoProposal());
                poll.AddProposal("P1");
                poll.AddProposal("P2");

                var result = await sut.Create(poll);

                result.IsSuccess.Should().BeTrue();
                poll.PollId.Should().NotBe(0);

                var createdPoll = await sut.FindById(poll.PollId);

                createdPoll.Value.PollId.Should().Be(poll.PollId);

                await TestHelpers.UserService.DeleteUser(pollContext, userRepository, sut, author.Value.UserId);

                await TestHelpers.UserService.DeleteUser(pollContext, userRepository, sut, guest1.Value.UserId);

                await TestHelpers.UserService.DeleteUser(pollContext, userRepository, sut, guest2.Value.UserId);
            }
        }
Пример #11
0
 public UnitOfWork(ApplicationDbContext context)
 {
     _context        = context;
     Polls           = new PollRepository(_context);
     Answers         = new AnswerRepository(_context);
     Users           = new UserRepository(_context);
     DailyStatistics = new DailyStatisticsRepository(_context);
     UniqueVisitors  = new UniqueVisitorsRepository(_context);
 }
Пример #12
0
        public UnitOfWork(RingkeyDbContext context)
        {
            _context = context;

            Account     = new AccountRepository(_context);
            Message     = new MessageRepository(_context);
            BannedWords = new BannedWordsRepository(_context);
            Report      = new ReportRepository(_context);
            Role        = new RoleRepository(_context);
            Permission  = new PermissionRepository(_context);
            Poll        = new PollRepository(_context);
            Category    = new CategoryRepository(_context);
        }
Пример #13
0
        public ActionResult Index([Bind(Include = "Genre, Age, MusicGenres, Content, Proposals")] PollViewModel vPollModel)
        {
            var repo = new PollRepository();

            if (ModelState.IsValid)
            {
                repo.SavePoll(vPollModel);
            }
            else
            {
                return(View("~/Views/Poll/Index.cshtml", vPollModel));
            }
            return(View(repo.GetAll()));
        }
Пример #14
0
        public AutoDeletePolls(IServiceProvider serviceProvider)
        {
            _serviceProvider = serviceProvider;
            _pollRepo        = _serviceProvider.GetService <PollRepository>();
            _client          = _serviceProvider.GetService <DiscordSocketClient>();

            ObjectState StateObj = new ObjectState();

            TimerCallback TimerDelegate = new TimerCallback(DeletePolls);

            _timer = new Timer(TimerDelegate, StateObj, TimeSpan.FromMilliseconds(500), Config.AUTO_DELETE_POLLS_COOLDOWN);

            StateObj.TimerReference = _timer;
        }
Пример #15
0
        public AutoDeletePolls(IServiceProvider serviceProvider)
        {
            _serviceProvider = serviceProvider;
            _pollRepo        = _serviceProvider.GetService <PollRepository>();
            _client          = _serviceProvider.GetService <DiscordSocketClient>();

            ObjectState StateObj = new ObjectState();

            TimerCallback TimerDelegate = new TimerCallback(DeletePolls);

            _timer = new Timer(TimerDelegate, StateObj, TimeSpan.Zero, Config.AutoDeletePollsCooldown);

            StateObj.TimerReference = _timer;
        }
Пример #16
0
        public async Task create_poll_with_invalid_authorId_should_return_an_error()
        {
            using (PollContext pollContext = TestHelpers.CreatePollContext())
            {
                var pollContextAccessor = new PollContextAccessor(pollContext);
                var userRepository      = new UserRepository(pollContextAccessor);
                var sut         = new PollRepository(pollContextAccessor);
                var userService = TestHelpers.UserService;

                var poll   = new Model.Poll(0, -424, "question?", false);
                var result = await sut.Create(poll);

                result.IsSuccess.Should().BeFalse();
            }
        }
Пример #17
0
        public async Task create_poll()
        {
            using (PollContext pollContext = TestHelpers.CreatePollContext())
            {
                PollContextAccessor pollContextAccessor = new PollContextAccessor(pollContext);
                var pollRepository = new PollRepository(pollContextAccessor);
                var userRepository = new UserRepository(pollContextAccessor);


                string email    = $"test-{Guid.NewGuid()}@test.fr";
                string nickname = $"Test-{Guid.NewGuid()}";

                Result <User> user = await TestHelpers.UserService.CreateUser(userRepository, email, nickname, "validpassword");

                Result <User> guest = await TestHelpers.UserService.CreateUser(userRepository, $"{email}-guest", $"{nickname}-guest", "validpassword");

                var pollDto = new NewPollDto
                {
                    AuthorId       = user.Value.UserId,
                    Question       = "Test-Question ",
                    GuestNicknames = new[] { guest.Value.Nickname },
                    Proposals      = new[] { "proposal1", "proposal2" }
                };
                var pollCreated = await TestHelpers.PollService.CreatePoll(pollContext, pollRepository, userRepository, pollDto);

                pollCreated.IsSuccess.Should().BeTrue();
                pollCreated.Value.Guests.Should().HaveCount(pollDto.GuestNicknames.Length);
                pollCreated.Value.Proposals.Should().HaveCount(pollDto.Proposals.Length);
                pollCreated.Value.AuthorId.Should().Be(pollDto.AuthorId);
                pollCreated.Value.Question.Should().Be(pollDto.Question);

                var poll = await TestHelpers.PollService.FindById(pollRepository, pollCreated.Value.PollId);

                poll.IsSuccess.Should().BeTrue();

                await TestHelpers.PollService.DeletePoll(pollContext, pollRepository, pollCreated.Value.PollId);

                await TestHelpers.UserService.DeleteUser(pollContext, userRepository, pollRepository, user.Value.UserId);

                await TestHelpers.UserService.DeleteUser(pollContext, userRepository, pollRepository, guest.Value.UserId);
            }
        }
Пример #18
0
        public async Task create_user()
        {
            using (PollContext pollContext = TestHelpers.CreatePollContext())
            {
                PollContextAccessor pollContextAccessor = new PollContextAccessor(pollContext);
                UserRepository      sut = new UserRepository(pollContextAccessor);
                string        email     = $"{Guid.NewGuid()}@test.org";
                string        nickname  = $"Test-{Guid.NewGuid()}";
                Result <User> user      = User.Create(email, nickname, "test-hash");

                Result creationStatus = await sut.Create(user.Value);

                creationStatus.IsSuccess.Should().BeTrue();
                Result <User> foundUser = await sut.FindByEmail(email);

                foundUser.IsSuccess.Should().BeTrue();
                foundUser.Value.Should().BeEquivalentTo(user.Value);

                PollRepository pollRepository = new PollRepository(pollContextAccessor);
                await TestHelpers.UserService.DeleteUser(pollContext, sut, pollRepository, foundUser.Value.UserId);
            }
        }
Пример #19
0
        public async Task create_poll()
        {
            using (PollContext pollContext = TestHelpers.CreatePollContext())
            {
                PollContextAccessor pollContextAccessor = new PollContextAccessor(pollContext);
                PollRepository      pollRepository      = new PollRepository(pollContextAccessor);
                UserRepository      userRepository      = new UserRepository(pollContextAccessor);

                // We should create Author user for create poll associated with this user
                string        emailAuthor       = $"{Guid.NewGuid()}@test.org";
                string        nicknameAuthor    = $"Test-{Guid.NewGuid()}";
                Result <User> userAuthorCreated = await TestHelpers.UserService.CreateUser(userRepository, emailAuthor, nicknameAuthor, "hashpassword");

                // We should create Guest user for create poll associated with this user
                string        emailGuest       = $"{Guid.NewGuid()}@test.org";
                string        nicknameGuest    = $"Test-{Guid.NewGuid()}";
                Result <User> userGuestCreated = await TestHelpers.UserService.CreateUser(userRepository, emailGuest, nicknameGuest, "hashpassword");

                NewPollDto newPollDto = new NewPollDto();
                newPollDto.AuthorId       = userAuthorCreated.Value.UserId;
                newPollDto.Question       = "Question?";
                newPollDto.GuestNicknames = new string[] { userGuestCreated.Value.Nickname };
                newPollDto.Proposals      = new string[] { "P1", "P2" };

                Result <Poll> poll = await TestHelpers.PollService.CreatePoll(pollContext, pollRepository, userRepository, newPollDto);


                poll.IsSuccess.Should().BeTrue();
                Result <Poll> foundPoll = await TestHelpers.PollService.FindById(pollRepository, poll.Value.PollId);

                poll.Should().BeEquivalentTo(foundPoll);

                await TestHelpers.PollService.DeletePoll(pollContext, pollRepository, poll.Value.PollId);

                await TestHelpers.UserService.DeleteUser(pollContext, userRepository, pollRepository, userAuthorCreated.Value.UserId);

                await TestHelpers.UserService.DeleteUser(pollContext, userRepository, pollRepository, userGuestCreated.Value.UserId);
            }
        }
Пример #20
0
        public async Task create_user()
        {
            using (PollContext pollContext = TestHelpers.CreatePollContext())
            {
                PollContextAccessor pollContextAccessor = new PollContextAccessor(pollContext);
                UserRepository      userRepository      = new UserRepository(pollContextAccessor);
                string email    = $"test-{Guid.NewGuid()}@test.fr";
                string nickname = $"Test-{Guid.NewGuid()}";

                Result <User> user = await TestHelpers.UserService.CreateUser(userRepository, email, nickname, "validpassword");

                user.IsSuccess.Should().BeTrue();
                user.Value.Email.Should().Be(email);
                user.Value.Nickname.Should().Be(nickname);

                user = await TestHelpers.UserService.FindByNickname(userRepository, nickname);

                user.IsSuccess.Should().BeTrue();

                PollRepository pollRepository = new PollRepository(pollContextAccessor);
                await TestHelpers.UserService.DeleteUser(pollContext, userRepository, pollRepository, user.Value.UserId);
            }
        }
Пример #21
0
 public PollController()
 {
     _repo   = new PollRepository();
     _mailer = new UserMailer();
 }
Пример #22
0
 public HomeController()
 {
     _repo = new PollRepository();
 }
Пример #23
0
        static void Main(string[] args)
        {
            IKernel kernel = new StandardKernel();

            #region BindingOnly
            kernel.Bind <IPollRepository>().To <PollRepository>();
            kernel.Bind <IRegionRepository>().To <RegionRepository>();
            kernel.Bind <IUserRepository>().To <UserRepository>();
            kernel.Bind <IVoteRepository>().To <VoteRepository>();

            kernel.Bind <IManagePolicy>().To <ManagePolicy>();
            kernel.Bind <IPolicyChecker>().To <PolicyChecker>();
            kernel.Bind <IPollService>().To <PollService>();
            kernel.Bind <IRegistrationUserService>().To <RegistrationUserService>();
            kernel.Bind <IVoteService>().To <VoteService>();

            ContextRegistration contextRegistration = new ContextRegistration();
            UserRepository      userRepository      = new UserRepository();
            VoteRepository      voteRepository      = new VoteRepository();
            RegionRepository    regionRepository    = new RegionRepository();
            PollRepository      pollRepository      = new PollRepository();
            UserService         userService         = new UserService(userRepository);
            PollService         pollService         = new PollService(userRepository, regionRepository, pollRepository);
            PolicyChecker       policyChecker       = new PolicyChecker(userService);
            VoteService         voteService         = new VoteService(voteRepository, pollRepository);
            var managePolicy = new ManagePolicy(userRepository);
            IRegistrationUserService registrationUserService = new RegistrationUserService(contextRegistration,
                                                                                           voteRepository,
                                                                                           regionRepository,
                                                                                           userRepository);
            #endregion
            while (true)
            {
                Console.Clear();
                System.Console.WriteLine($"Hello, Person. Here's some service for you to make your own choice for the future of your country \n" +
                                         $"Please enter your passport data to verify your identity:");
                string passport = Console.ReadLine();
                Console.WriteLine("Now identification code:");
                int indefcode = Int32.Parse(Console.ReadLine());
                contextRegistration.SetPasswordInfo(passport, indefcode);
                //int user_temp_id = userService.GetUserByMainInfo(contextRegistration.GetPassportInfo().Item1, contextRegistration.GetPassportInfo().Item2).Id;
                bool response;
                try
                {
                    response = registrationUserService.ValidateUser(contextRegistration.GetPassportInfo().Item1,
                                                                    contextRegistration.GetPassportInfo().Item2);
                }
                catch (Exception)
                {
                    Console.WriteLine("We don't have information about you");
                    response = false;
                }
                if (response == false)
                {
                    Console.WriteLine("Sorry, but you are not allowed to vote");
                }
                else
                {
                    bool choice = true;

                    int user_temp_id = userService.GetUserByMainInfo(contextRegistration.GetPassportInfo().Item1, contextRegistration.GetPassportInfo().Item2).Id;
                    while (choice)
                    {
                        Console.Clear();
                        Console.WriteLine("Welcome to our service!");
                        Console.WriteLine("Select option:\n" +
                                          "1. Create Poll;\n" +
                                          "2. Add Choice to Poll;\n" +
                                          "3. Vote;\n" +
                                          "4. Give Policy;\n" +
                                          "0. Exit this shit;");
                        var answer = Int32.Parse(Console.ReadLine());
                        switch (answer)
                        {
                            #region Create Poll
                        case 1:
                            Console.WriteLine("Create your poll:\n Enter name: ");
                            string name = Console.ReadLine();
                            Console.WriteLine("Description:");
                            string desc        = Console.ReadLine();
                            int    ownerpollId = userRepository.GetUser(contextRegistration.GetPassportInfo().Item1,
                                                                        contextRegistration.GetPassportInfo().Item2).Id;
                            Console.WriteLine("Enter Date of poll start (dd/MM/YYYY): ");
                            var start = Convert.ToDateTime(Console.ReadLine());
                            Console.WriteLine("Enter Date of poll end (dd/MM/YYYY): ");
                            var end = Convert.ToDateTime(Console.ReadLine());
                            Console.WriteLine("Allow multiple selection? (Y/N)");
                            bool   multiple;
                            string temp_ans = Console.ReadKey().ToString();
                            Console.ReadLine();
                            if (temp_ans == "Y")
                            {
                                multiple = true;
                            }
                            else
                            {
                                multiple = false;
                            }
                            int creation_response = pollService.CreatePoll(name, desc, ownerpollId, start, end, multiple);
                            managePolicy.GiveAdminPolicyToUser(ownerpollId, creation_response);
                            break;
                            #endregion

                            #region AddChoice
                        case 2:
                            Console.WriteLine("Enter PollName to add an option:");
                            string pollName1       = Console.ReadLine();
                            Poll   poll1           = pollService.GetPoll(pollName1);
                            bool   policyresponse1 = policyChecker.CheckAdminPolicy(user_temp_id, poll1.Id);
                            if (policyresponse1 == false)
                            {
                                Console.WriteLine("You have no rights to create options for this poll!");
                                Console.ReadLine();
                                break;
                            }
                            Console.WriteLine("Enter Option Name: ");
                            string optionName = Console.ReadLine();
                            Console.WriteLine("Enter option description: ");
                            string descr = Console.ReadLine();
                            pollService.CreateChoice(optionName, descr, poll1.Id);
                            break;

                            #endregion

                            #region Vote
                        case 3:
                            Console.WriteLine("Available polls: ");
                            foreach (var a in pollService.ShowAllPolls())
                            {
                                Console.WriteLine($"{a.Name} \n {a.Description}\n Time left: {a.PollEndDate - DateTime.Now} \n");
                            }
                            Console.WriteLine("Choose the poll:");
                            string poll_temp_name       = Console.ReadLine();
                            Poll   poll2                = pollService.GetPoll(poll_temp_name);
                            bool   policyresponse2      = policyChecker.CheckPolicy(user_temp_id, poll2.Id);
                            bool   multiplevoteresponse = voteService.CheckVote(user_temp_id);
                            if (multiplevoteresponse == false)
                            {
                                Console.WriteLine("You cant vote more");
                                Console.ReadLine();
                                break;
                            }
                            if (policyresponse2 == false)
                            {
                                Console.WriteLine("Sorry, but you cannot vote!");
                                Console.ReadLine();
                                break;
                            }
                            foreach (var a in pollService.GetChoices(poll_temp_name))
                            {
                                Console.WriteLine($"{a.Name} \n {a.Description} \n");
                            }
                            Console.WriteLine("Write what you choose:");
                            List <string> allChoices = new List <string>();
                            if (poll2.MutlipleSelection == true)
                            {
                                string option = Console.ReadLine();
                                allChoices.Add(option);
                                Console.WriteLine("Do you want to choose smth more? (Y/N)");
                                string multipleResponse = Console.ReadLine();
                                while (multipleResponse == "Y")
                                {
                                    option = Console.ReadLine();
                                    allChoices.Add(option);
                                    Console.WriteLine("Do you want to choose smth more? (Y/N)");
                                    multipleResponse = Console.ReadLine();
                                }
                            }
                            else
                            {
                                string option = Console.ReadLine();
                                allChoices.Add(option);
                            }
                            foreach (var a in allChoices)
                            {
                                voteService.Vote(user_temp_id, pollService.GetChoices(poll_temp_name).FirstOrDefault(c => c.Name == a).Id);
                            }
                            break;

                            #endregion
                            #region Policy
                        case 4:

                            Console.WriteLine("Enter PollName for future policy:");
                            string pollName       = Console.ReadLine();
                            Poll   poll           = pollService.GetPoll(pollName);
                            bool   policyresponse = policyChecker.CheckAdminPolicy(user_temp_id, poll.Id);
                            if (policyresponse == false)
                            {
                                Console.WriteLine("You have no rights to give policy for this poll!");
                                Console.ReadLine();
                                break;
                            }
                            Console.WriteLine("Which rights do you want to give? (Admin/Access)");
                            string answer_for_rights = Console.ReadLine();
                            if (answer_for_rights == "Admin")
                            {
                                Console.WriteLine("Enter email for user who you want to give policy:");
                                string email = Console.ReadLine();
                                User   user  = userService.GetUserByEmail(email);
                                managePolicy.GiveAdminPolicyToUser(user.Id, poll.Id);
                            }
                            else if (answer_for_rights == "Access")
                            {
                                Console.WriteLine("Enter email for user who you want to give policy:");
                                string email = Console.ReadLine();
                                User   user  = userService.GetUserByEmail(email);
                                managePolicy.GivePolicyToUser(user.Id, poll.Id);
                            }
                            else
                            {
                                Console.WriteLine("F**k you dumbass paralytic idiot who cannot type needed shit!");
                            }
                            break;

                            #endregion
                            #region Exit
                        case 0:
                            choice = false;
                            break;

                            #endregion
                        default:
                            break;
                        }
                    }
                }
            }
        }
Пример #24
0
 public Polls(ModerationService moderationService, PollRepository pollRepo)
 {
     _moderationService = moderationService;
     _pollRepo          = pollRepo;
 }
Пример #25
0
 public PollServiceImpl(neighlinkdbContext dbContext)
 {
     _pollRepository = new PollRepository(dbContext);
 }
Пример #26
0
        public ActionResult Index()
        {
            var repo = new PollRepository();

            return(View(repo.GetAll()));
        }
 public PollControllerTest()
 {
     _pollRepository = new PollRepositoryImp(_dbContext);
     _pollController = new PollController(_pollRepository, _mapper);
 }
Пример #28
0
        static void Main(string[] args)
        {
            IKernel kernel = new StandardKernel();

            #region BindingOnly
            kernel.Bind <IPollRepository>().To <PollRepository>();
            kernel.Bind <IRegionRepository>().To <RegionRepository>();
            kernel.Bind <IUserRepository>().To <UserRepository>();
            kernel.Bind <IVoteRepository>().To <VoteRepository>();

            kernel.Bind <IManagePolicy>().To <ManagePolicy>();
            kernel.Bind <IPolicyChecker>().To <PolicyChecker>();
            kernel.Bind <IPollService>().To <PollService>();
            kernel.Bind <IRegistrationUserService>().To <RegistrationUserService>();
            kernel.Bind <IVoteService>().To <VoteService>();


            UserRepository      userRepository      = new UserRepository();
            ContextRegistration contextRegistration = new ContextRegistration(userRepository);
            var              managePolicy           = new ManagePolicy(userRepository);
            VoteRepository   voteRepository         = new VoteRepository();
            RegionRepository regionRepository       = new RegionRepository();
            PollRepository   pollRepository         = new PollRepository();
            PolicyChecker    policyChecker          = new PolicyChecker(userRepository, contextRegistration);
            VoteService      voteService            = new VoteService(voteRepository, pollRepository, contextRegistration);
            PollService      pollService            = new PollService(contextRegistration, regionRepository,
                                                                      pollRepository, managePolicy,
                                                                      voteService, policyChecker, voteRepository);
            UserInterface            userInterface           = new UserInterface(userRepository, contextRegistration, pollRepository, policyChecker);
            IRegistrationUserService registrationUserService = new RegistrationUserService(contextRegistration,
                                                                                           voteRepository,
                                                                                           regionRepository,
                                                                                           userRepository);
            #endregion
            while (true)
            {
                Console.Clear();
                System.Console.WriteLine($"Hello, Person. Here's some service for you to make your own choice for the future of your country \n" +
                                         $"Please enter your passport data to verify your identity:");
                string passport = Console.ReadLine();
                Console.WriteLine("Now identification code:");
                int indefcode = Int32.Parse(Console.ReadLine());
                contextRegistration.SetPasswordInfo(passport, indefcode);
                //int user_temp_id = userService.GetUserByMainInfo(contextRegistration.GetPassportInfo().Item1, contextRegistration.GetPassportInfo().Item2).Id;
                bool response;
                try
                {
                    response = userRepository.UserExists(contextRegistration.GetPassportInfo().Item1,
                                                         contextRegistration.GetPassportInfo().Item2);
                }
                catch (Exception)
                {
                    Console.WriteLine("We don't have information about you");
                    Console.ReadLine();
                    response = false;
                }
                if (response == false)
                {
                    Console.WriteLine("Sorry, but you are not allowed to vote");
                }
                else
                {
                    bool choice = true;

                    int user_temp_id = userRepository.GetUser(contextRegistration.GetPassportInfo().Item1, contextRegistration.GetPassportInfo().Item2).Id;
                    while (choice)
                    {
                        Console.Clear();
                        Console.WriteLine("Welcome to our service!");
                        Console.WriteLine("Select option:\n" +
                                          "1. Create Poll;\n" +
                                          "2. Add Choice to Poll;\n" +
                                          "3. Vote;\n" +
                                          "4. Give Policy;\n" +
                                          "5. Show poll results;\n" +
                                          "0. Exit this shit;");
                        var answer = Int32.Parse(Console.ReadLine());
                        switch (answer)
                        {
                            #region Create Poll
                        case 1:
                            PollCreationDTO pollCreation = userInterface.CreatePollConsole();
                            pollService.CreatePoll(pollCreation);
                            break;

                            #endregion
                            #region AddChoice
                        case 2:
                            ChoiceCreationDTO choiceCreation = userInterface.CreateChoiceConsole();
                            if (choiceCreation == null)
                            {
                                break;
                            }
                            pollService.CreateChoice(choiceCreation);
                            break;

                            #endregion
                            #region Vote
                        case 3:
                            userInterface.ShowPollsConsole();
                            Console.WriteLine("Choose the poll:");
                            string poll_temp_name         = Console.ReadLine();
                            var    pollPolicyFailedChecks = pollService.CheckAllPolicy(poll_temp_name);
                            if (pollPolicyFailedChecks.Count > 0)
                            {
                                foreach (var a in pollPolicyFailedChecks)
                                {
                                    Console.WriteLine(a.Value);
                                    Console.ReadLine();
                                }
                                break;
                            }

                            Poll poll1 = pollRepository.Get(poll_temp_name);
                            foreach (var a in poll1.Choices)
                            {
                                Console.WriteLine($"{a.Name} \n {a.Description} \n");
                            }
                            Console.WriteLine("Write what you choose:");
                            List <int> allChoices = new List <int>();
                            if (poll1.MutlipleSelection == true)
                            {
                                string option = Console.ReadLine();
                                allChoices.Add(poll1.GetChoiceByName(option).Id);
                                Console.WriteLine("Do you want to choose smth more? (Y/N)");
                                string multipleResponse = Console.ReadLine();
                                while (multipleResponse == "Y")
                                {
                                    option = Console.ReadLine();
                                    allChoices.Add(poll1.GetChoiceByName(option).Id);
                                    Console.WriteLine("Do you want to choose smth more? (Y/N)");
                                    multipleResponse = Console.ReadLine();
                                }
                            }
                            else
                            {
                                string option = Console.ReadLine();
                                allChoices.Add(poll1.GetChoiceByName(option).Id);
                            }

                            voteService.Vote(allChoices);
                            break;

                            #endregion
                            #region Policy
                        case 4:
                            userInterface.ShowPollsConsole();
                            Console.WriteLine("Enter PollName for future policy:");
                            string pollName = Console.ReadLine();

                            int?pollId = pollRepository.GetPollId(pollName);

                            if (pollId == null)
                            {
                                Console.WriteLine("Invalid poll name");
                                Console.ReadLine();
                                break;
                            }

                            bool policyresponse = policyChecker.CheckAdminPolicy(pollId.Value);

                            if (policyresponse == false)
                            {
                                Console.WriteLine("You have no rights to give policy for this poll!");
                                Console.ReadLine();
                                break;
                            }
                            Console.WriteLine("Which rights do you want to give? (Admin/Access)");
                            string answer_for_rights = Console.ReadLine();
                            if (!Enum.TryParse(answer_for_rights, out PolicyType policyType))
                            {
                                Console.WriteLine("F**k you dumbass paralytic idiot who cannot type needed shit!");
                                break;
                            }

                            Console.WriteLine("Enter email for user who you want to give policy:");
                            string email = Console.ReadLine();

                            User user = userRepository.GetUser(email);
                            managePolicy.GivePolicyToUser(user.Id, pollId.Value, policyType);
                            break;

                            #endregion
                            #region Results
                        case 5:
                            userInterface.ShowPollsConsole();
                            Console.WriteLine("Enter Pollname to see the results:");
                            string pollResultName = Console.ReadLine();
                            foreach (var a in voteService.GetPollResult(pollResultName))
                            {
                                Console.WriteLine($"{a.Key.ToString()}  - {a.Value.ToString()} ");
                            }
                            Console.ReadLine();
                            break;

                            #endregion
                            #region Exit
                        case 0:
                            choice = false;
                            break;

                            #endregion
                        default:
                            break;
                        }
                    }
                }
            }
        }
Пример #29
0
 public PollController(PollRepository pollSrv, IMapper mapper)
 {
     _pollRepository = pollSrv;
     _mapper         = mapper;
 }