private void PublishExecute()
        {
            try
            {
                MessageBoxButton btnMessageBox = MessageBoxButton.YesNo;
                MessageBoxImage  icnMessageBox = MessageBoxImage.Question;

                MessageBoxResult resultMessageBox = MessageBox.Show("Are you sure you want to publish this post?", "Publish approval", btnMessageBox, icnMessageBox);

                if (resultMessageBox == MessageBoxResult.Yes)
                {
                    int userToFindID = (from r in context.tblUsers where r.Username == Username select r.UserID).FirstOrDefault();

                    tblFeed newFeed = new tblFeed();
                    newFeed.FeedContent = Post;
                    newFeed.LikeNumbers = 0;
                    newFeed.PublishDate = DateTime.Now;
                    newFeed.UserID      = userToFindID;
                    context.tblFeeds.Add(newFeed);
                    context.SaveChanges();
                    MessageBox.Show("Your post is public.");
                    UserFeedList = tool.GetFeeds();
                    Post         = "";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
예제 #2
0
        public FeedReponse PostFeed(Feed feed)
        {
            FeedReponse objFeedReponse = new FeedReponse();

            try
            {
                tblFeed objtblFeed = new tblFeed()
                {
                    CreateDate   = DateTime.UtcNow,
                    FeedType     = 1,
                    CreatedBy    = feed.CreatedBy,
                    Feed         = feed.Status,
                    MediaFolder  = feed.UniqueId,
                    IsDeleted    = false,
                    MediaContent = feed.mediaJson
                };
                objobjlovesnwishesEntities.tblFeeds.Add(objtblFeed);
                objobjlovesnwishesEntities.SaveChanges();
                objFeedReponse.Id       = objtblFeed.Id;
                objFeedReponse.UniqueId = objtblFeed.MediaFolder;
            }

            catch (Exception ex)
            {
                objFeedReponse.Id = 0;
            }
            return(objFeedReponse);
        }
        private void LikeExecute()
        {
            try
            {
                MessageBoxButton btnMessageBox = MessageBoxButton.YesNo;
                MessageBoxImage  icnMessageBox = MessageBoxImage.Information;

                MessageBoxResult resultMessageBox = MessageBox.Show("Are you sure you want to like this post?", "Like approval", btnMessageBox, icnMessageBox);

                if (resultMessageBox == MessageBoxResult.Yes)
                {
                    int     FeedID     = UserFeed.FeedID;
                    tblUser userToFind = (from r in context.tblUsers where r.Username == Username select r).FirstOrDefault();

                    if (tool.IfAlreadyLiked(FeedID, userToFind.UserID) == true && tool.AreTheyFriends(userToFind.UserID, UserFeed.UserID) == true)
                    {
                        tblFeed feedToFind = (from r in context.tblFeeds where r.FeedID == FeedID select r).FirstOrDefault();
                        feedToFind.LikeNumbers++;
                        context.SaveChanges();
                        UserFeedList = tool.GetFeeds();
                        MessageBox.Show("You liked this post.");

                        //inserting this user in like list for this post:
                        tblLikeList newList = new tblLikeList();
                        newList.Feed_ID     = FeedID;
                        newList.UserLikedID = userToFind.UserID;
                        context.tblLikeLists.Add(newList);
                        context.SaveChanges();
                    }
                    else if (tool.AreTheyFriends(userToFind.UserID, UserFeed.UserID) == false)
                    {
                        MessageBox.Show("You can not like this feed because you are not friend with the publisher.");
                    }
                    else if (tool.IfAlreadyLiked(FeedID, userToFind.UserID) == false)
                    {
                        MessageBox.Show("You have already liked this post.");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }