public ActionResult Create(PostViewModel post)
        {
            var response = new JsonResponse<PostViewModel>();
            var newPost = new Post();

            try
            {
                newPost.Board = _repository.GetBoardById(post.BoardId);
                newPost.Owner = _repository.GetCompetitorByUserName(post.BoardId, User.Identity.Name);
                newPost.Body = post.Body;

                _repository.Add(newPost);
                _repository.CommitChanges();

                newPost.Owner.LastViewedPostId = newPost.PostId;
                _repository.CommitChanges();

                response.Result = new PostViewModel(newPost);
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                response.Error = true;
            }

            return (Json(response));
        }
Esempio n. 2
0
 public PostViewModel(Post post)
 {
     var g = new NGravatar.Gravatar();
     
     BoardId = post.Board.BoardId;
     PostId = post.PostId;
     OwnerId = post.Owner.CompetitorId;
     OwnerName = post.Owner.Name;
     GravatarLink = g.GetImageSource(post.Owner.Profile.EmailAddress);
     Body = HtmlSanitizer.Sanitizer(post.Body, new Regex("^(br|a)$"), HtmlSanitizer.ForbiddenTags).Val;
     Created = String.Format("{0:g}", post.Created);
     Edited = String.Format("{0:g}", post.Edited);
 }
Esempio n. 3
0
 public void Delete(Post post)
 {
     _posts.Remove(post);
 }
Esempio n. 4
0
 public void Add(Post post)
 {
     _posts.Add(post);
 }
 public void Add(Post post)
 {
     Db.Posts.Add(post);
 }
Esempio n. 6
0
        public static IRepository CreatePopulatedRepository()
        {
            var repository = new InMemoryRepository();

            var competitorOwnerProfile = new UserProfile
            {
                UserId = 0,
                UserName = "******"
                
            };

            var competitorProfile1 = new UserProfile
            {
                UserId = 1,
                UserName = "******"
            };

            var competitorProfile2 = new UserProfile
            {
                UserId = 2,
                UserName = "******"
            };

            var boardOwner = new Competitor
            {
                Name = competitorOwnerProfile.UserName,
                ProfileUserId = 0,
                Profile = competitorOwnerProfile,
                Rating = 1500,
                LastViewedPostId = 0
            };

            var competitor1 = new Competitor
            {
                Name = competitorProfile1.UserName,
                ProfileUserId = 1,
                Profile = competitorProfile1,
                Rating = 1500,
                LastViewedPostId = 0
            };

            var competitor2 = new Competitor
            {
                Name = competitorProfile2.UserName,
                ProfileUserId = 2,
                Profile = competitorProfile2,
                Rating = 1500,
            };

            var board = new Board
            {
                BoardId = 1,
                AutoVerification = 1,
                Created = DateTime.Now,
                Description = "Test Board",
                End = DateTime.Now.AddDays(30),
                Name = "Test Board",
                Owner = boardOwner,
                Started = DateTime.Now,
                StartingRating = 1500,
                Competitors = new[] { boardOwner, competitor1, competitor2 }
            };

            // Unresolved match
            var match1 = new Match
            {
                Board = board,
                Created = DateTime.Now,
                Loser = competitor2,
                Winner = competitor1,
                VerificationDeadline = DateTime.Now.AddHours(board.AutoVerification),
                MatchId = 1,
                LoserRatingDelta = -10,
                WinnerRatingDelta = 10
            };

            // Unresolved match
            var match2 = new Match
            {
                Board = board,
                Created = DateTime.Now.AddHours(-1),
                Loser = competitor1,
                Winner = competitor2,
                VerificationDeadline = DateTime.Now.AddHours(board.AutoVerification-1),
                MatchId = 2,
                LoserRatingDelta = -10,
                WinnerRatingDelta = 10
            };

            // Unresolved match
            var match3 = new Match
            {
                Board = board,
                Created = DateTime.Now.AddHours(-2),
                Loser = competitor2,
                Winner = competitor1,
                VerificationDeadline = DateTime.Now.AddHours(board.AutoVerification-2),
                MatchId = 3,
                LoserRatingDelta = -10,
                WinnerRatingDelta = 10
            };

            // Resolved Match [Verified]
            var match4 = new Match
            {
                Board = board,
                Created = DateTime.Now.AddDays(-7),
                Loser = competitor1,
                Winner = competitor2,
                VerificationDeadline = DateTime.Now.AddHours(board.AutoVerification),
                MatchId = 4,
                LoserRatingDelta = -10,
                WinnerRatingDelta = 10,
                Resolved = DateTime.Now.AddHours(board.AutoVerification),
                Verified = true
            };

            // Resolved Match [Rejected]
            var match5 = new Match
            {
                Board = board,
                Created = DateTime.Now.AddDays(-7),
                Loser = competitor2,
                Winner = competitor1,
                VerificationDeadline = DateTime.Now.AddHours(board.AutoVerification),
                MatchId = 4,
                LoserRatingDelta = -10,
                WinnerRatingDelta = 10,
                Resolved = DateTime.Now.AddHours(board.AutoVerification),
                Rejected = true
            };

            var post1 = new Post
            {
                Board = board,
                Created = DateTime.Now,
                Owner = competitor1,
                PostId = 1
            };

            var post2 = new Post
            {
                Board = board,
                Created = DateTime.Now,
                Owner = competitor2,
                PostId = 2
            };

            var post3 = new Post
            {
                Board = board,
                Created = DateTime.Now,
                Owner = competitor2,
                PostId = 3
            };

            board.Matches = new[] { match1, match2, match3 };

            // Boards
            repository.Add(board);
            
            // User Profiles
            repository.Add(competitorOwnerProfile);
            repository.Add(competitorProfile1);
            repository.Add(competitorProfile2);
            
            // Competitors
            repository.Add(boardOwner);
            repository.Add(competitor1);
            repository.Add(competitor2);
            
            // Matches
            repository.Add(match1);
            repository.Add(match2);
            repository.Add(match3);
            repository.Add(match4);
            repository.Add(match5);

            // Posts
            repository.Add(post1);
            repository.Add(post2);
            repository.Add(post3);

            return (repository);
        }