コード例 #1
0
        public void TestMethod1()
        {
            using (var db = new FeedPostContext()) {
                int newUserid = (new Random()).Next(0, 1000000000);
                var post      = new FeedPost()
                {
                    Id = 123, UserId = newUserid
                };
                db.Posts.Add(post);
                db.SaveChanges();

                var query = from p in db.Posts
                            where p.UserId == newUserid
                            select p;

                Assert.AreEqual(query.Count(), 1);

                Console.WriteLine("All posts in the database:");
                foreach (var item in query)
                {
                    Console.WriteLine(item.UserId);
                }

                Console.WriteLine("Press any key to exit...");
            }
        }
コード例 #2
0
        public async Task <IActionResult> CommentNotification([FromBody] string content, int postId, CancellationToken ct = default)
        {
            FeedPost post = await _feedService.GetByIdAsync(postId, ct);

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

            UserBan globalBan = await _userService.GetFirstBanOfTypeIfAnyAsnc(post.PosterUUID, 1, ct);

            UserBan feedBan = await _userService.GetFirstBanOfTypeIfAnyAsnc(post.PosterUUID, 3, ct);

            if (globalBan != null || feedBan != null)
            {
                return(Ok());
            }

            Notification notification = Notification.CreateNotification(new APSAlert {
                body = content
            }, feedPostId: postId);
            ICollection <string> tokens = await _userService.GetAPNSFromUUIDAsync(post.PosterUUID);

            foreach (string token in tokens)
            {
                await _userService.PostNotification(token, notification);
            }
            return(Ok());
        }
コード例 #3
0
ファイル: PostStatusController.cs プロジェクト: lkh/thanhpham
        public JsonResult PostStatus(string msg)
        {
            Session["postStatus"] = msg;


            Facebook facebook = auth.FacebookAuth();

            if (Session["facebookQueryStringValue"] == null)
            {
                string authLink = facebook.GetAuthorizationLink();
                return(Json(authLink));
            }

            if (Session["facebookQueryStringValue"] != null)
            {
                facebook.GetAccessToken(Session["facebookQueryStringValue"].ToString());
                FBUser    currentUser = facebook.GetLoggedInUserInfo();
                IFeedPost FBpost      = new FeedPost();
                if (Session["postStatus"].ToString() != "")
                {
                    FBpost.Message = Session["postStatus"].ToString();
                    facebook.PostToWall(currentUser.id.GetValueOrDefault(), FBpost);
                }
            }
            return(Json("No"));
        }
コード例 #4
0
        public ActionResult <FeedPost> GetPostById(int postId)
        {
            try
            {
                var post = _db.Posts
                           .Include(u => u.User)
                           .SingleOrDefault(p => p.Id == postId);

                if (post != null)
                {
                    FeedPost feedPost = new FeedPost
                    {
                        Id     = post.Id,
                        Title  = post.Title,
                        Text   = post.Text,
                        ImgUrl = post.ImgUrl,
                        Likes  = post.Likes,
                        Date   = post.Date,
                        Author = post.User.FirstName + " " + post.User.LastName
                    };

                    return(feedPost);
                }
                return(StatusCode(204, "No content"));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, $"Internal server error {ex}"));
            }
        }
コード例 #5
0
        public async Task MarkPostAsDeletedAsync(int feedPostId, CancellationToken ct = default)
        {
            FeedPost post = await _context.FeedPosts.FindAsync(feedPostId);

            post.IsDeleted = true;
            _context.Update(post);
            await _context.SaveChangesAsync(ct);
        }
コード例 #6
0
 public async Task <IActionResult> CreateNewPost([FromBody] FeedPost post, CancellationToken ct = default)
 {
     if (!AuthenticationUtilities.IsAllowedFeed(User))
     {
         return(BadRequest("User has been banned from Feed"));
     }
     return(Ok(await _feedService.UploadNewPostAsync(post, ct)));
 }
コード例 #7
0
        public async Task <FeedPost> UploadNewPostAsync(FeedPost post, CancellationToken ct = default)
        {
            if (post is FeedMediaPost)
            {
                post = post as FeedMediaPost;
            }
            else
            {
                post = post as FeedPollPost;
            }

            await _context.FeedPosts.AddAsync(post, ct);

            await _context.SaveChangesAsync(ct);

            return(await GetByIdAsync(post.PostId, ct));
        }
コード例 #8
0
        public async Task ToggleLikeForPostAsync(int feedPostId, string userUUID, CancellationToken ct = default)
        {
            FeedPost post = await _context.FeedPosts
                            .AsNoTracking()
                            .Include(fp => fp.Likes)
                            .FirstOrDefaultAsync(fp => fp.PostId == feedPostId, ct);

            if (post == null)
            {
                return;
            }


            FeedLike like = post.Likes.FirstOrDefault(fl => fl.UserUUID == userUUID);

            if (await HasUserLikedPostAsync(userUUID, feedPostId))
            {
                like.IsLiked        = false;
                post.PostLikeCount -= 1;
                _context.Update(like);
                _context.Update(post);
            }
            else
            {
                if (like == null)
                {
                    FeedLike newLike = new FeedLike
                    {
                        PostId   = feedPostId,
                        UserUUID = userUUID,
                        IsLiked  = true
                    };
                    await _context.FeedPostLikes.AddAsync(newLike);

                    post.PostLikeCount += 1;
                    _context.Update(post);
                }
                else
                {
                    like.IsLiked = !like.IsLiked;
                    _context.Update(like);
                    post.PostLikeCount = like.IsLiked ? (post.PostLikeCount += 1) : (post.PostLikeCount -= 1);
                }
            }
            await _context.SaveChangesAsync();
        }
コード例 #9
0
        public async Task <IActionResult> DeletePost(int feedPostId, CancellationToken ct = default)
        {
            if (!AuthenticationUtilities.IsAllowedFeed(User))
            {
                return(BadRequest("User has been banned from Feed"));
            }
            FeedPost post = await _feedService.GetByIdAsync(feedPostId);

            if (!AuthenticationUtilities.IsSameUserOrPrivileged(User, post.PosterUUID))
            {
                return(Unauthorized("You do not have access to modify this post"));
            }

            await _feedService.MarkPostAsDeletedAsync(feedPostId, ct);

            return(Ok());
        }
コード例 #10
0
ファイル: ControllerMain.cs プロジェクト: TeVeVe/Ict4Events-B
        private void FillFeedPost()
        {
            IEnumerable <FeedPost> feedPosts = FeedPost.Select();

            View.CommentSection.FlowLayoutPanel.Controls.Clear();

            foreach (FeedPost feedPost in feedPosts)
            {
                var cc = new CommentControl();
                cc.LabelNaam.Text =
                    UserAccount.Select("UserAccountID = " + feedPost.UserAccount).FirstOrDefault().Username;
                cc.LabelContent.Text = feedPost.Content;

                Debug.WriteLine(feedPost.Content);

                View.CommentSection.Add(cc);
            }
        }
コード例 #11
0
ファイル: PostStatusController.cs プロジェクト: lkh/thanhpham
 public ActionResult Success()
 {
     if (Request.QueryString["code"] != null)
     {
         string Code = Request.QueryString["code"];
         Session["facebookQueryStringValue"] = Code;
     }
     if (Session["facebookQueryStringValue"] != null)
     {
         Facebook facebook = auth.FacebookAuth();
         facebook.GetAccessToken(Session["facebookQueryStringValue"].ToString());
         FBUser    currentUser = facebook.GetLoggedInUserInfo();
         IFeedPost FBpost      = new FeedPost();
         if (Session["postStatus"].ToString() != "")
         {
             FBpost.Message = Session["postStatus"].ToString();
             facebook.PostToWall(currentUser.id.GetValueOrDefault(), FBpost);
         }
     }
     return(View());
 }
コード例 #12
0
        public async Task <IActionResult> ResetPollVotes(int postId, CancellationToken ct = default)
        {
            if (!AuthenticationUtilities.IsAllowedFeed(User))
            {
                return(BadRequest("User has been banned from Feed"));
            }
            FeedPost post = await _feedService.GetByIdAsync(postId);

            if (!AuthenticationUtilities.IsSameUser(User, post.PosterUUID))
            {
                return(Unauthorized("You do not have access to edit this post"));
            }
            if (post == null || post.PostType != "poll")
            {
                return(BadRequest("Poll does not exist at this id"));
            }

            await _feedService.ResetPollVotesAsync(postId, ct);

            return(Ok());
        }
コード例 #13
0
        public async Task <FeedPost> GetByIdAsync(int feedPostId, CancellationToken ct = default)
        {
            FeedPost post = await _context.FeedPosts
                            .AsNoTracking()
                            .Include(fp => fp.Likes.Where(fl => fl.IsLiked))
                            .Include(fp => fp.Poster)
                            .Include(fp => fp.PostTeam)
                            .Include(fp => fp.Comments)
                            .ThenInclude(fpp => fpp.User)
                            .Include(fp => ((FeedPollPost)fp).PollAnswers)
                            .ThenInclude(fpa => fpa.Votes.Where(fpv => !fpv.IsDeleted))
                            .FirstOrDefaultAsync(fp => fp.PostId == feedPostId, ct);

            post.PosterDTO = post.Poster.ConvertToDTO();
            post.Poster    = null;
            foreach (FeedComment comment in post.Comments)
            {
                comment.UserDTO = comment.User.ConvertToDTO();
                comment.User    = null;
            }
            return(post);
        }
コード例 #14
0
ファイル: ControllerMain.cs プロジェクト: TeVeVe/Ict4Events-B
        public ControllerMain()
        {
            View.CategoryTreeView.NodeClick        += CategoryTreeView_NodeClick;
            View.CategoryFiles.AddFileButton.Click += AddFileButton_Click;

            // Fill contextmenu of category treeview.
            View.CategoryTreeView.TreeViewContextMenu.Opening += (sender, args) =>
            {
                if (View.CategoryTreeView.SelectedNode == null)
                {
                    if (View.CategoryTreeView.TreeViewContextMenu.Items["ContextMenuNodeDelete"] != null)
                    {
                        View.CategoryTreeView.TreeViewContextMenu.Items["ContextMenuNodeDelete"].Visible = false;
                    }

                    if (View.CategoryTreeView.TreeViewContextMenu.Items["ContextMenuNodeEdit"] != null)
                    {
                        View.CategoryTreeView.TreeViewContextMenu.Items["ContextMenuNodeEdit"].Visible = false;
                    }

                    if (View.CategoryTreeView.TreeViewContextMenu.Items["ContextMenuNodeAdd"] != null)
                    {
                        View.CategoryTreeView.TreeViewContextMenu.Items["ContextMenuNodeAdd"].Visible = false;
                    }
                }
                else
                {
                    if (View.CategoryTreeView.TreeViewContextMenu.Items["ContextMenuNodeDelete"] != null)
                    {
                        View.CategoryTreeView.TreeViewContextMenu.Items["ContextMenuNodeDelete"].Visible = false;
                    }

                    if (View.CategoryTreeView.TreeViewContextMenu.Items["ContextMenuNodeEdit"] != null)
                    {
                        View.CategoryTreeView.TreeViewContextMenu.Items["ContextMenuNodeEdit"].Visible = false;
                    }

                    if (View.CategoryTreeView.TreeViewContextMenu.Items["ContextMenuNodeAdd"] != null)
                    {
                        View.CategoryTreeView.TreeViewContextMenu.Items["ContextMenuNodeAdd"].Visible = true;
                    }
                }
            };

            var addToolStripButton = new ToolStripMenuItem("Toevoegen")
            {
                Name = "ContextMenuNodeAddSub"
            };
            var addSubCategoryToolStripButton = new ToolStripMenuItem("Subcategorie")
            {
                Width = TextRenderer.MeasureText("Subcategorie", addToolStripButton.Font).Width
            };
            var addCategoryToolStripButton = new ToolStripMenuItem("Categorie");
            var editToolStripButton        = new ToolStripMenuItem("Wijzigen")
            {
                Name = "ContextMenuNodeEdit"
            };
            var deleteToolStripButton = new ToolStripMenuItem("Verwijderen")
            {
                Name = "ContextMenuNodeDelete"
            };


            addCategoryToolStripButton.Click += (sender, args) =>
            {
                MainForm.PopupController <ControllerAddCategory>();
                CreateNodes();
            };

            addSubCategoryToolStripButton.Click += (sender, args) =>
            {
                if (View.CategoryTreeView.SelectedNode != null)
                {
                    MainForm.PopupController <ControllerAddCategory>(new KeyValuePair <string, object>("Parent",
                                                                                                       View.CategoryTreeView.SelectedNode.Tag));
                    CreateNodes();
                }

                else
                {
                    MessageBox.Show("Selecteer alstublieft een categorie als u een subcategorie toe wilt voegen.");
                }
            };

            View.CategoryTreeView.TreeViewContextMenu.Items.Add(addToolStripButton);
            addToolStripButton.DropDownItems.Add(addCategoryToolStripButton);
            addToolStripButton.DropDownItems.Add(addSubCategoryToolStripButton);
            View.CategoryTreeView.TreeViewContextMenu.Items.Add(editToolStripButton);
            View.CategoryTreeView.TreeViewContextMenu.Items.Add(deleteToolStripButton);
            View.CommentInput.SendCommentButton.Click += (sender, args) =>
            {
                if (View.CommentInput.CommentTextBox.Text.Length > 140)
                {
                    MessageBox.Show("Vul alstublieft niet meer dan 140 tekens in.");
                }

                else
                {
                    var comment  = new Comment();
                    var feedPost = new FeedPost();

                    feedPost.UserAccount = _userAccount.Id;
                    feedPost.Content     = View.CommentInput.CommentTextBox.Text;
                    feedPost.PostTime    = DateTime.Now;

                    feedPost.Insert();
                    View.CommentInput.CommentTextBox.Text = "";
                    FillFeedPost();
                }
            };
        }
コード例 #15
0
    protected void Page_Load(object sender, EventArgs e)
    {
        #region Get the code returned by Facebook
        lbl_status.Text = ""; btnShare.Visible = true;
        if (!String.IsNullOrEmpty(Request.QueryString["code"]) && GetSessionValue("request_session").ToString() == "true")
        {
            ImpactWorks.FBGraph.Connector.Facebook facebook = GetSessionValue("current_facebook_account") as ImpactWorks.FBGraph.Connector.Facebook;
            //Get the code returned by facebook
            string Code = Request.QueryString["code"];

            //process code for auth token
            facebook.GetAccessToken(Code);

            //Get User info
            FBUser currentUser = facebook.GetLoggedInUserInfo();
            //Link share

            IFeedPost FBpost = new FeedPost();

            //Custom Action that we can add
            FBpost.Action = new FBAction { Name = "Find more Shwe8.NET", Link = "http://shwe8.net" };
            FBpost.Caption = Caption;
            FBpost.Description = Description;
            FBpost.ImageUrl = ImageURL;
            FBpost.Message = Message;
            FBpost.Name = PostName;
            FBpost.Url = PostURL;

            var postID = facebook.PostToWall(currentUser.id.GetValueOrDefault(), FBpost);
            SetSessionValue("request_session", "false");
            lbl_status.Text = "Shared on facebook successfully. Great!";
            btnShare.Visible = false;
            //Remove Code and Session from query string
            PropertyInfo isreadonly =
          typeof(System.Collections.Specialized.NameValueCollection).GetProperty(
          "IsReadOnly", BindingFlags.Instance | BindingFlags.NonPublic);
            // make collection editable
            isreadonly.SetValue(this.Request.QueryString, false, null);
            Request.QueryString.Remove("code"); Request.QueryString.Remove("request_session");
            //Show successful alert message for sharing.
            Response.Write("<script>alert('Shared on facebook successfully. Great!')</script>");
        }

        #endregion
    }