Exemplo n.º 1
0
        public async Task <IActionResult> MyVote(MyVoteContract model)
        {
            //return Redirect(urlToRedirect);


            if (model.NotVoted())
            {
                return(RedirectToAction("Vote"));
            }

            if (string.IsNullOrEmpty(model.Token))
            {
                var user = this.GetUser();

                if (user == null)
                {
                    return(RedirectToAction("Signin"));
                }

                model.Email  = user.Email;
                model.UserId = user.UserId;
            }
            else
            {
                var token = await _voteTokensRepository.FindTokenAsync(model.Token);

                if (token == null)
                {
                    return(RedirectToAction("Signin"));
                }

                model.Email = token.Email;
            }

            IVote vote = await _votesRepository.GetAsync(model.Email);

            if (vote != null)
            {
                return(RedirectToAction("Success"));
            }



            await _votesRepository.VoteAsync(model);

            return(RedirectToAction("Success"));
        }
Exemplo n.º 2
0
        public async Task Seed()
        {
            // Clear database
            await EntityFrameworkTestsHelper.ClearAndMarkTestDatabase(_dbContext);

            // Setup users
            var cloudyLogin = new UserLoginInfo("e2e", "cloudy_dude");
            var cloudy      = await _usersRepository.LoadOrCreateUserFromLoginAsync(cloudyLogin.Scheme, cloudyLogin.NameIdentifier, "Cloudy Dude", new DateTimeOffset(2018, 01, 15, 15, 23, 12, TimeSpan.Zero));

            var billyLogin = new UserLoginInfo("e2e", "H4x0rs4evaaaah");
            var billy      = await _usersRepository.LoadOrCreateUserFromLoginAsync(billyLogin.Scheme, billyLogin.NameIdentifier, "Billy", new DateTimeOffset(2000, 01, 01, 00, 00, 00, TimeSpan.Zero));

            var edLogin = new UserLoginInfo("e2e", "153234");
            var ed      = await _usersRepository.LoadOrCreateUserFromLoginAsync(edLogin.Scheme, edLogin.NameIdentifier, "ed", new DateTimeOffset(2018, 03, 14, 19, 54, 48, TimeSpan.Zero));

            // Setup posts
            var gettingReadyToJumpJpg = await CreateFile(new PostFile
            {
                Filename   = "getting_ready_to_jump.jpg",
                MimeType   = "image/jpeg",
                Compressed = false,
            });

            var gettingReadyToJumpJson = await CreateFile(new PostFile
            {
                Filename   = "getting_ready_to_jump.json",
                MimeType   = "application/json",
                Compressed = true,
            });

            var gettingReadyToJumpWav = await CreateFile(new PostFile
            {
                Filename   = "getting_ready_to_jump.wav",
                MimeType   = "audio/wav",
                Compressed = true,
            });

            var gettingReadyToJumpPost = await _postsRepository.CreatePostAsync(
                cloudyLogin,
                "Jumping Lady",
                new[] { "jumping", "lady" },
                new[]
            {
                new Scene
                {
                    Name         = "getting_ready_to_jump",
                    ThumbnailUrn = gettingReadyToJumpJpg.Urn
                }
            },
                new[]
            {
                gettingReadyToJumpJson, gettingReadyToJumpJpg, gettingReadyToJumpWav
            },
                gettingReadyToJumpJpg.Urn,
                new DateTimeOffset(2018, 01, 16, 21, 02, 54, TimeSpan.Zero)
                );

            var gettingReadyToJumpPostViewModel = PostViewModel.From(gettingReadyToJumpPost, false);

            gettingReadyToJumpPostViewModel.Published = true;
            await _postsRepository.UpdatePostAsync(cloudyLogin, gettingReadyToJumpPostViewModel, new DateTimeOffset(2018, 01, 16, 21, 03, 49, TimeSpan.Zero));

            // Setup comments
            await _commentsRepository.CreatePostCommentAsync(billyLogin, gettingReadyToJumpPost.Id, "This scene rocks man", new DateTimeOffset(2018, 01, 16, 21, 02, 54, TimeSpan.Zero));

            await _commentsRepository.CreatePostCommentAsync(cloudyLogin, gettingReadyToJumpPost.Id, "Thanks!", new DateTimeOffset(2018, 01, 16, 21, 04, 24, TimeSpan.Zero));

            await _commentsRepository.CreatePostCommentAsync(edLogin, gettingReadyToJumpPost.Id, "She's not even *jumping*, _yo_.", new DateTimeOffset(2018, 01, 16, 21, 08, 07, TimeSpan.Zero));

            await _commentsRepository.CreatePostCommentAsync(billyLogin, gettingReadyToJumpPost.Id, "Get\na\nlife", new DateTimeOffset(2018, 01, 16, 21, 12, 35, TimeSpan.Zero));

            // Setup votes
            await _votesRepository.VoteAsync(cloudyLogin, gettingReadyToJumpPost.Id, 10);

            await _votesRepository.VoteAsync(billyLogin, gettingReadyToJumpPost.Id, 10);

            await _votesRepository.VoteAsync(edLogin, gettingReadyToJumpPost.Id, -2);
        }