public ActionResult addUser(User user, string password)
        {
            var repo = new HackerNewsRepository(Properties.Settings.Default.ConStr);

            repo.AddUser(user, password);
            FormsAuthentication.SetAuthCookie(user.Email, true);
            return(Redirect("/home/index"));
        }
Esempio n. 2
0
        public GetLatestHackerNewsStoryIdsAsyncTests()
        {
            _idList = new List <int>()
            {
                1
            };
            _apiAccessHelper = new Mock <IApiAccessHelper>(MockBehavior.Strict);
            _apiAccessHelper.Setup(x => x.GetApiAsync <List <int> >(ExternalApiUrls.HackerNewsLatestStoriesUrl)).ReturnsAsync(_idList);

            _repository = new HackerNewsRepository(_apiAccessHelper.Object);
        }
Esempio n. 3
0
        public GetHackerNewsItemAsyncTests()
        {
            _id              = 1;
            _hackerNewsItem  = MockHackerNewsContractFactory.CreateMockHackerNewsItem();
            _apiAccessHelper = new Mock <IApiAccessHelper>(MockBehavior.Strict);
            _apiAccessHelper.Setup(x =>
                                   x.GetApiAsync <HackerNewsItem>(string.Format(ExternalApiUrls.HackerNewsItemUrl, _id))
                                   ).ReturnsAsync(_hackerNewsItem);

            _repository = new HackerNewsRepository(_apiAccessHelper.Object);
        }
        public ActionResult Login(string email, string password)
        {
            var  repo = new HackerNewsRepository(Properties.Settings.Default.ConStr);
            User user = repo.Login(email, password);

            if (user == null)
            {
                return(View("Login"));
            }
            FormsAuthentication.SetAuthCookie(email, true);
            return(Redirect("/home/index"));
        }
        public ActionResult downVote(int postId)
        {
            var  repo = new HackerNewsRepository(Properties.Settings.Default.ConStr);
            Post p    = repo.DownVote(postId);

            return(Json(new
            {
                votesUp = p.UpVotes,
                votesDown = p.DownVotes,
                postId = p.Id
            }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Comments(int postId)
        {
            var repo = new HackerNewsRepository(Properties.Settings.Default.ConStr);
            var vm   = new CommentsViewModel();

            vm.Comments = repo.getComments(postId);
            vm.Post     = repo.GetPostById(postId);
            if (User.Identity.IsAuthenticated)
            {
                string email = User.Identity.Name;
                vm.User = repo.GetByEmail(email);
            }
            return(View(vm));
        }
        public ActionResult Newest()
        {
            var repo = new HackerNewsRepository(Properties.Settings.Default.ConStr);
            var vm   = new IndexViewModel();

            vm.Posts = repo.AllPosts().OrderByDescending(p => p.TimePosted).Take(10);
            if (User.Identity.IsAuthenticated)
            {
                string email = User.Identity.Name;
                User   u     = repo.GetByEmail(email);
                vm.User = u.FirstName + " " + u.LastName;
            }
            vm.Type = "Newest 10 Articles";
            return(View("Index", vm));
        }
        public ActionResult addPost(string linkTitle, string linkUrl)
        {
            var    repo  = new HackerNewsRepository(Properties.Settings.Default.ConStr);
            string email = User.Identity.Name;
            User   u     = repo.GetByEmail(email);
            Post   post  = new Post
            {
                LinkTitle  = linkTitle,
                LinkUrl    = linkUrl,
                TimePosted = DateTime.Now,
                UserId     = u.Id
            };

            repo.AddPost(post);
            return(Redirect("/home/index"));
        }
        public ActionResult UserPosts(int userId)
        {
            var repo = new HackerNewsRepository(Properties.Settings.Default.ConStr);
            var vm   = new IndexViewModel();

            vm.Posts = repo.GetPostsForUser(userId).OrderByDescending(p => p.TimePosted);
            if (User.Identity.IsAuthenticated)
            {
                string email = User.Identity.Name;
                User   u     = repo.GetByEmail(email);
                vm.User = u.FirstName + " " + u.LastName;
            }
            User user = repo.GetUserById(userId);

            vm.Type = "Posts By " + user.FirstName + " " + user.LastName;
            return(View("index", vm));
        }
Esempio n. 10
0
        public ActionResult addComment(string comment, int postId)
        {
            var     repo  = new HackerNewsRepository(Properties.Settings.Default.ConStr);
            string  email = User.Identity.Name;
            User    u     = repo.GetByEmail(email);
            Comment c     = new Comment
            {
                FirstName   = u.FirstName,
                LastName    = u.LastName,
                CommentText = comment,
                PostId      = postId,
            };

            repo.AddComment(c);
            return(Json(new {
                firstName = c.FirstName,
                lastName = c.LastName,
                commentText = c.CommentText
            }));
        }
Esempio n. 11
0
        public ActionResult Index()
        {
            var repo  = new HackerNewsRepository(Properties.Settings.Default.ConStr);
            var vm    = new IndexViewModel();
            var Posts = repo.AllPosts();

            foreach (Post p in Posts)
            {
                var hrs = p.TimePosted.Hour - DateTime.Now.Hour;
                p.Score = GetScore(p.UpVotes, p.DownVotes, hrs);
            }
            vm.Posts = Posts.OrderByDescending(p => p.Score).Take(10);
            if (User.Identity.IsAuthenticated)
            {
                string email = User.Identity.Name;
                User   u     = repo.GetByEmail(email);
                vm.User = u.FirstName + " " + u.LastName;
            }
            vm.Type = "Top 10 Articles";
            return(View(vm));
        }
Esempio n. 12
0
        public ActionResult Index()
        {
            HackerNewsRepository repo = new HackerNewsRepository();

            return(View(repo.GetTwentyTopStories()));
        }
Esempio n. 13
0
        public void setup()
        {
            mockCacheProvider = new Mock <ICacheProvider>();

            repo = new HackerNewsRepository(mockCacheProvider.Object);
        }