Example #1
0
 public PostController(IPostRepo postRepo, IMapper mapper, ICategoryRepo categoryRepo, ISettingsRepo settingsRepo)
 {
     _postRepo     = postRepo;
     _mapper       = mapper;
     _categoryRepo = categoryRepo;
     _settingsRepo = settingsRepo;
 }
Example #2
0
        protected async override Task <CommentView> HandleInput(CommentDeleteParams input)
        {
            using (var connection = database.GetConnection()) {
                ICommentRepo commentRepo = database.GetRepo <ICommentRepo>(connection);
                IPostRepo    postRepo    = database.GetRepo <IPostRepo>(connection);

                Comment?comment = await commentRepo.FindById(input.CommentId);

                if (comment == null)
                {
                    throw new InvalidOperationException();
                }

                // Check to see if they have permission first.
                if (!(await this.permissionHandler.HasPermission(input.User, PermissionAction.DeleteComment, comment)))
                {
                    throw new AuthorizationException();
                }

                // (Hopefully) it would be impossible for post to be null if a comment exists...
                Post post = (await postRepo.FindById(comment.PostId)) !;

                post.CommentCount -= (comment.ChildCount() + 1);

                using (var transaction = connection.BeginTransaction()) {
                    await commentRepo.Delete(comment);

                    await postRepo.Update(post);

                    transaction.Commit();
                }

                return(commentMapper.Map(comment));
            }
        }
Example #3
0
 public PostController(IPostRepo postRepo, IUserRepo userRepo, ICommentRepo commentRepo, IBlobService blobService)
 {
     _postRepo    = postRepo;
     _userRepo    = userRepo;
     _commentRepo = commentRepo;
     _blobService = blobService;
 }
Example #4
0
        protected override async Task <PostView> HandleInput(PostUpdateParams input)
        {
            using (var connection = database.GetConnection()) {
                IPostRepo postRepo = database.GetRepo <IPostRepo>(connection);
                Post?     post     = await postRepo.FindById(input.PostId);

                if (post == null)
                {
                    throw new InvalidOperationException();
                }

                if (!(await this.postPermissionHandler.HasPermission(input.User, PermissionAction.UpdatePost, post)))
                {
                    throw new AuthorizationException();
                }

                if (post.Type == PostType.Link)
                {
                    throw new InvalidOperationException("Link posts can't be updated.");
                }

                if (post.WasDeleted)
                {
                    throw new InvalidOperationException("Post has already been deleted.");
                }


                post.Body = input.Body;
                await postRepo.Update(post);

                return(postMapper.Map(post));
            }
        }
Example #5
0
 public PostDataAccess(IPostRepo postRepo, IPostValidator postValidator, IAuthorRepo authorRepo, IAuthorValidator authorValidator)
 {
     _postRepo        = postRepo;
     _postValidator   = postValidator;
     _authorRepo      = authorRepo;
     _authorValidator = authorValidator;
 }
Example #6
0
 public PostController(IPostRepo postRepository, SignInManager <IdentityUser> signInManager,
                       UserManager <IdentityUser> userManager)
 {
     _postRepository = postRepository;
     _signInManager  = signInManager;
     _userManager    = userManager;
 }
Example #7
0
 public PostsController(
     IPostRepo repository,
     IMapper mapper
     )
 {
     _repository = repository;
     _mapper     = mapper;
 }
 public HomePageController(ICommentLikeRepo CommentLike, ICommentRepo PostComments, IPostRepo Post, IFriendRepo Friends, IPostLikeRepo PostLikes)
 {
     _Post         = Post;
     _Friends      = Friends;
     _PostLikes    = PostLikes;
     _PostComments = PostComments;
     _CommentLike  = CommentLike;
 }
Example #9
0
 public UserController(IUserRepo userrepo, IGender gender, ICommentRepo comments, IPostRepo post, ICodeRepo code)
 {
     this._user     = userrepo;
     this._gender   = gender;
     this._comm     = comments;
     this._postrepo = post;
     this._coderepo = code;
 }
Example #10
0
        static void Main(string[] args)
        {
            IPostRepo repo = Container.DIContainer.Resolve <IPostRepo>();

            foreach (var item in repo.GetPosts(1, 0, 1))
            {
                Console.WriteLine(item.Id);
            }
        }
 public ProfileController(ICommentLikeRepo CommentLike, IUserRepo User, ICommentRepo PostComments, IPostRepo Post, IFriendRepo Friends, IPostLikeRepo PostLikes)
 {
     _Post         = Post;
     _Friends      = Friends;
     _PostLikes    = PostLikes;
     _PostComments = PostComments;
     _CommentLike  = CommentLike;
     _User         = User;
 }
 public ProfileController(ApplicationDbContext db, ICommentLikeRepo CommentLike, IUserRepo User, ICommentRepo PostComments, IPostRepo Post, IFriendRepo Friends, IPostLikeRepo PostLikes)
 {
     _Post         = Post;
     _Friends      = Friends;
     _PostLikes    = PostLikes;
     _PostComments = PostComments;
     _CommentLike  = CommentLike;
     _User         = User;
     this.db       = db;
 }
Example #13
0
 public Server_ForumHandler()
 {
     _postRepo     = new PostRepo();
     _commentRepo  = new CommentRepo();
     _postList     = new List <PostModel>();
     _commentList  = new List <CommentModel>();
     _ratingRepo   = new RatingRepo();
     _reportRepo   = new ReportRepo();
     _reportModels = new List <ReportModel>();
 }
Example #14
0
        protected async override Task <CommentView> HandleInput(CommentCreateParams input)
        {
            using (var connection = database.GetConnection()) {
                IPostRepo    postRepo    = database.GetRepo <IPostRepo>(connection);
                ICommentRepo commentRepo = database.GetRepo <ICommentRepo>(connection);
                IVoteRepo    voteRepo    = database.GetRepo <IVoteRepo>(connection);

                // Locate the post to ensure it actually exists.
                Post?post = await postRepo.FindById(input.PostId);

                if (post == null)
                {
                    throw new InvalidOperationException();
                }

                using (var transaction = connection.BeginTransaction()) {
                    Comment comment = new Comment()
                    {
                        User         = input.User,
                        PostId       = post.Id,
                        Body         = input.Body,
                        CreationDate = DateTime.UtcNow
                    };

                    // Set the parent comment if needed.
                    if (input.ParentId != 0)
                    {
                        comment.Parent = await commentRepo.FindById(input.ParentId);
                    }

                    // Update the comment count cache on the post.
                    post.CommentCount++;

                    comment.Upvotes++;
                    await commentRepo.Add(comment);

                    Vote upvote = new Vote()
                    {
                        User         = input.User,
                        ResourceId   = comment.Id,
                        ResourceType = VoteResourceType.Comment,
                        Direction    = VoteDirection.Up
                    };

                    await postRepo.Update(post);

                    await voteRepo.Add(upvote);

                    comment.Vote = upvote;
                    transaction.Commit();

                    return(commentMapper.Map(comment));
                }
            }
        }
Example #15
0
 public ProjectController(IPostRepo repo,
                          UserManager <AppUser> userManager,
                          AppDbContext context,
                          IBidService bidService,
                          IPostService postService)
 {
     this.repo        = repo;
     this.userManager = userManager;
     this.context     = context;
     this.bidService  = bidService;
     this.postService = postService;
 }
Example #16
0
        private async Task <IResponse <bool> > CrawlNewPostAsync(IPostRepo postRepo, Page page, int newPostCount)
        {
            try
            {
                var postCount    = 0;
                var haveNextPage = false;
                var cursor       = string.Empty;
                var postList     = new List <CrawledPostDto>();

                do
                {
                    #region Call Instagram Post Api
                    var postInquiry = await CrawlPostFromInstagramAsync(page.UniqueId, newPostCount, cursor);

                    if (postInquiry.status != "ok")
                    {
                        return new Response <bool> {
                                   IsSuccessful = false, Message = ServiceMessage.Error
                        }
                    }
                    ;

                    var postCollection = postInquiry.data.user.edge_Owner_To_Timeline_Media.edges;
                    var totalPostCount = postInquiry.data.user.edge_Owner_To_Timeline_Media.count;
                    cursor       = postInquiry.data.user.edge_Owner_To_Timeline_Media.page_Info.end_cursor;
                    haveNextPage = postInquiry.data.user.edge_Owner_To_Timeline_Media.page_Info.has_next_page;
                    #endregion

                    foreach (var post in postCollection)
                    {
                        postCount += 1;

                        var newPost = ConvertToCrawledPostDto(post);

                        newPost.PageId = page.PageId;
                        await postRepo.AddAsync(newPost);
                    }
                } while (haveNextPage == true && postCount < newPostCount);

                return(new Response <bool> {
                    Result = true, IsSuccessful = true, Message = ServiceMessage.Success
                });
            }
            catch (Exception e)
            {
                FileLoger.Error(e);
                return(new Response <bool> {
                    IsSuccessful = false, Message = ServiceMessage.Exception
                });
            }
        }
Example #17
0
        protected override async Task <VoteView> HandleInput(VoteOnPostParams input)
        {
            using (var connection = database.GetConnection()) {
                IVoteRepo voteRepo = database.GetRepo <IVoteRepo>(connection);
                IPostRepo postRepo = database.GetRepo <IPostRepo>(connection);
                IUserRepo userRepo = database.GetRepo <IUserRepo>(connection);

                using (var transaction = connection.BeginTransaction()) {
                    Post post    = (await postRepo.FindById(input.PostId)) !;
                    Vote?oldVote = await voteRepo.FindByUserAndPost(input.User.Username, input.PostId);


                    // Wipe out the old one...
                    if (oldVote != null)
                    {
                        post.RemoveVote(oldVote.Direction);
                        await voteRepo.Delete(oldVote);

                        if (post.Type != PostType.Text)
                        {
                            post.User.PostKarma -= (int)oldVote.Direction;
                        }
                    }

                    // Create the new vote, and update the comment's karma cache.
                    Vote newVote = new Vote()
                    {
                        User         = input.User,
                        ResourceType = VoteResourceType.Post,
                        ResourceId   = input.PostId,
                        Direction    = input.Vote
                    };

                    post.AddVote(newVote.Direction);

                    if (post.Type != PostType.Text)
                    {
                        post.User.PostKarma += (int)newVote.Direction;
                    }

                    await voteRepo.Add(newVote);

                    await postRepo.Update(post);

                    await userRepo.Update(post.User);

                    transaction.Commit();
                    return(voteViewMapper.Map(newVote));
                }
            }
        }
Example #18
0
        protected override async Task <PostView?> HandleInput(PostCreateParams input)
        {
            using (var connection = database.GetConnection()) {
                ISpaceRepo spaceRepo = database.GetRepo <ISpaceRepo>(connection);
                IPostRepo  postRepo  = database.GetRepo <IPostRepo>(connection);
                IVoteRepo  voteRepo  = database.GetRepo <IVoteRepo>(connection);

                Space?space = await spaceRepo.FindByName(input.Space);

                if (space == null)
                {
                    throw new InvalidOperationException($"No space with name ${input.Space} found.");
                }

                using (var transaction = connection.BeginTransaction()) {
                    Post post = new Post()
                    {
                        Type         = input.Type,
                        Title        = input.Title,
                        Body         = input.Body,
                        User         = input.User,
                        CreationDate = DateTime.UtcNow,
                        Space        = space
                    };

                    if (post.Type == PostType.Link && !System.Text.RegularExpressions.Regex.IsMatch(post.Body, Regex.UrlProtocol))
                    {
                        post.Body = $"http://{post.Body}";
                    }

                    // Not liking these count caches. Makes no sense?
                    post.Upvotes++;
                    await postRepo.Add(post);

                    Vote upvote = new Vote()
                    {
                        User         = input.User,
                        ResourceId   = post.Id,
                        ResourceType = VoteResourceType.Post,
                        Direction    = VoteDirection.Up
                    };

                    await voteRepo.Add(upvote);

                    post.Vote = upvote;

                    transaction.Commit();
                    return(postMapper.Map(post));
                }
            }
        }
Example #19
0
        protected override async Task <PagedResultSet <PostView> > HandleInput(FindByValueParams <string> input)
        {
            using (var connection = database.GetConnection()) {
                IPostRepo postRepo = database.GetRepo <IPostRepo>(connection);
                IVoteRepo voteRepo = database.GetRepo <IVoteRepo>(connection);

                PagedResultSet <Post> posts = await postRepo.FindByUser(input.Value, input.Pagination?.PageNumber ?? 0, input.Pagination?.PageSize ?? Post.PageSize);

                if (input.User != null)
                {
                    foreach (Post p in posts)
                    {
                        p.Vote = await voteRepo.FindByUserAndPost(input.User.Username, p.Id);
                    }
                }

                return(new PagedResultSet <PostView>(posts.Items.Select(p => postMapper.Map(p)), posts.Pagination));
            }
        }
        public void initNonExistingRepo(bool withUnitOfWork = false)
        {
            // Als we een repo met UoW willen gebruiken en als er nog geen uowManager bestaat:
            // Dan maken we de uowManager aan en gebruiken we de context daaruit om de repo aan te maken.

            if (withUnitOfWork)
            {
                if (uowManager == null)
                {
                    uowManager = new UnitOfWorkManager();
                    repo       = new PostRepo(uowManager.UnitOfWork);
                }
            }
            // Als we niet met UoW willen werken, dan maken we een repo aan als die nog niet bestaat.
            else
            {
                repo = (repo == null) ? new PostRepo() : repo;
            }
        }
Example #21
0
 public IndexModel
     (IMeProvider meProvider
     , IEventRepo eventRepo
     , IMembershipRepo membershipRepo
     , IParticipationRepo participationRepo
     , IParticipationTextProvider participationTextProvider
     , IPostRepo postRepo
     , IMailService mailService
     )
 {
     //this.dbContext = dbContext;
     this.meProvider                = meProvider;
     this.eventRepo                 = eventRepo;
     this.membershipRepo            = membershipRepo;
     this.participationRepo         = participationRepo;
     this.participationTextProvider = participationTextProvider;
     this.postRepo    = postRepo;
     this.mailService = mailService;
 }
Example #22
0
        protected async override Task <PostView?> HandleInput(FindByValueParams <int> input)
        {
            using (var connection = database.GetConnection()) {
                IPostRepo postRepo = database.GetRepo <IPostRepo>(connection);
                IVoteRepo voteRepo = database.GetRepo <IVoteRepo>(connection);

                Post?post = await postRepo.FindById(input.Value);

                if (post == null)
                {
                    return(null);
                }

                //Pull in the vote if needed.
                if (input.User != null)
                {
                    post.Vote = await voteRepo.FindByUserAndPost(input.User.Username, input.Value);
                }

                return(postMapper.Map(post));
            }
        }
Example #23
0
        protected override async Task <PostView?> HandleInput(PostDeleteParams input)
        {
            using (var connection = database.GetConnection()) {
                IPostRepo postRepo = database.GetRepo <IPostRepo>(connection);

                Post?p = await postRepo.FindById(input.PostId);

                if (p == null)
                {
                    throw new InvalidOperationException();
                }

                if (!(await this.permissionHandler.HasPermission(input.User, PermissionAction.DeletePost, p)))
                {
                    throw new AuthorizationException();
                }

                await postRepo.Delete(p);

                return(postMapper.Map(p));
            }
        }
Example #24
0
 /// <summary>
 /// Constructor PostController
 /// </summary>
 /// <param name="postRepo"></param>
 public PostController(IPostRepo postRepo)
 {
     this._postRepo = postRepo;
 }
Example #25
0
 public PostController(IPostRepo repo, ForumDbContext context)
 {
     _repo    = repo;
     _context = context;
 }
Example #26
0
 public CommentController(ICommentRepo commentRepo, IUserRepo userRepo, IPostRepo postRepo)
 {
     _commentRepo = commentRepo;
     _userRepo    = userRepo;
     _postRepo    = postRepo;
 }
Example #27
0
 public PostService(IEventBus bus, IPostFactory factory, IPostRepo repo)
 {
     this.bus     = bus;
     this.factory = factory;
     this.repo    = repo;
 }
Example #28
0
 public ForumController(IPostRepo p, UserManager <AppUser> usrMgr)
 {
     userManager = usrMgr;
     pRepo       = p;
 }
Example #29
0
 public HomeController(IPostRepo postRepository)
 {
     repo = postRepository;
 }
Example #30
0
 /// <summary>
 /// One-argument constructor initializing the post repository
 /// </summary>
 /// <param name="postRepo">the given value for the post repo</param>
 public PostSocket(IPostRepo postRepo)
 {
     this.postRepo = postRepo;
     FILE_PATH     = ImagesUtil.FILE_PATH;
 }