示例#1
0
        public void GetFeed_feedFound()
        {
            AddTestPost();                                     // add test post to database

            List <Newspost> feed = personController.GetFeed(); // get news feed

            Newspost testPost = feed.First();

            Assert.Equal(title, testPost.Title);             // test if title is correct
            Assert.Equal(description, testPost.Description); // test if post is correct
        }
示例#2
0
	    public void Update(int Id,DateTime Createdon,int Categoryid,string Subject,string Content,bool Isurgent)
	    {
		    Newspost item = new Newspost();
	        item.MarkOld();
	        item.IsLoaded = true;
		    
			item.Id = Id;				
			item.Createdon = Createdon;
			item.Categoryid = Categoryid;				
			item.Subject = Subject;				
			item.Content = Content;				
			item.Isurgent = Isurgent;
				
	        item.Save(UserName);
	    }
示例#3
0
        public List <Newspost> GetFriendPosts()
        {
            // GetFriendPosts() gets all the posts that are posted by the Persons' friends (relationship type "IsFriendsWith") and their creators from the database and puts them in a list of Newspost objects.
            // NOTE: Posts that a friends of the Person have posted in a group will NOT be fetched.

            List <INode>    postNodes = new List <INode>();
            var             getPosts  = ConnectDb("MATCH(a:Person {PersonId:1})-[:IsFriendsWith]->(b:Person)-[:Posted]->(p:Post) WHERE NOT (:Group)-[:HasPost]->(p) RETURN p");
            var             post      = new Newspost();
            List <Newspost> postList  = new List <Newspost>();

            postNodes = getPosts.Result;
            foreach (var record in postNodes)
            {
                var nodeprops = JsonConvert.SerializeObject(record.As <INode>().Properties);
                post = (JsonConvert.DeserializeObject <Newspost>(nodeprops));

                DateTime datetime = DateTime.ParseExact(post.DateAdded.ToString(), "d-M-yyyy HH:mm:ss", new CultureInfo("nl-NL"));

                /// Another query gets the related Persons to a post from the database thus finding its creator, the result is processed similarly.
                List <INode> creatorNode = new List <INode>();
                var          getCreator  = ConnectDb("MATCH(u:Person)-[:Posted]->(p:Post) WHERE p.PostId = " + post.PostId + " RETURN u");
                var          creator     = new Person();

                creatorNode = getCreator.Result;
                foreach (var person in creatorNode)
                {
                    var Personprops = JsonConvert.SerializeObject(person.As <INode>().Properties);
                    creator = (JsonConvert.DeserializeObject <Person>(Personprops));
                }

                // After getting al the required data, it is put into a Newspost object and added to the list of newsposts.
                postList.Add(new Newspost()
                {
                    PostId      = post.PostId,
                    Title       = post.Title,
                    Description = post.Description,
                    Creator     = creator,
                    DateAdded   = post.DateAdded,
                    TimeStamp   = datetime
                });
            }

            // The final list is put into a ordered list called feed, so the results will be displayed in the right order (newest first).
            List <Newspost> feed = postList.OrderByDescending(p => p.TimeStamp).ToList();

            return(feed);
        }
示例#4
0
        //=========================================================//
        // Инициализация новостной панели,отправка post запроса... //
        //=========================================================//
        public news_panel()
        {
            InitializeComponent();
            ////////////////
            label1.Parent    = this.pictureBox1;
            label2.Parent    = this.pictureBox2;
            label3.Parent    = this.pictureBox3;
            label4.Parent    = this.pictureBox4;
            label5.Parent    = this.pictureBox5;
            label1.BackColor = Color.FromArgb(0, Color.White);
            label2.BackColor = Color.FromArgb(0, Color.White);
            label3.BackColor = Color.FromArgb(0, Color.White);
            label4.BackColor = Color.FromArgb(0, Color.White);
            label5.BackColor = Color.FromArgb(0, Color.White);
            /////////////////
            postquery postnews;

            postnews = new postquery();
            string   newspost = postnews.post("http://5game.su/test.php", "");
            Newspost news     = JsonConvert.DeserializeObject <Newspost>(newspost);

            pictureBox1.ImageLocation = news.answer[0].short_story;
            pictureBox1.SizeMode      = PictureBoxSizeMode.StretchImage;
            pictureBox2.ImageLocation = news.answer[1].short_story;
            pictureBox2.SizeMode      = PictureBoxSizeMode.StretchImage;
            pictureBox3.ImageLocation = news.answer[2].short_story;
            pictureBox3.SizeMode      = PictureBoxSizeMode.StretchImage;
            pictureBox4.ImageLocation = news.answer[3].short_story;
            pictureBox4.SizeMode      = PictureBoxSizeMode.StretchImage;
            pictureBox5.ImageLocation = news.answer[4].short_story;
            pictureBox5.SizeMode      = PictureBoxSizeMode.StretchImage;
            ///////////////////
            label1.Text = news.answer[0].title;
            label2.Text = news.answer[1].title;
            label3.Text = news.answer[2].title;
            label4.Text = news.answer[3].title;
            label5.Text = news.answer[4].title;
            //////////////////
            site1 = "http://5game.su/" + news.answer[0].id + "-" + news.answer[0].alt_name + ".html";
            site2 = "http://5game.su/" + news.answer[1].id + "-" + news.answer[1].alt_name + ".html";
            site3 = "http://5game.su/" + news.answer[2].id + "-" + news.answer[2].alt_name + ".html";
            site4 = "http://5game.su/" + news.answer[3].id + "-" + news.answer[3].alt_name + ".html";
            site5 = "http://5game.su/" + news.answer[4].id + "-" + news.answer[4].alt_name + ".html";
            /////////////////
        }
示例#5
0
        public List <Newspost> GetFeed()
        {
            // GetPosts() get all the posts and their creators from the database and puts them in a list of Newspost objects.

            List <INode>    postNodes = new List <INode>();
            var             getPosts  = ConnectDb("MATCH (p:Post) RETURN (p)");
            var             post      = new Newspost();
            List <Newspost> postList  = new List <Newspost>();

            postNodes = getPosts.Result;
            foreach (var record in postNodes)
            {
                var nodeprops = JsonConvert.SerializeObject(record.As <INode>().Properties);
                post = (JsonConvert.DeserializeObject <Newspost>(nodeprops));

                // Another query gets the related users to a post from the database thus finding its creator, the result is processed similarly.
                List <INode> userList = new List <INode>();
                var          getuser  = ConnectDb("MATCH(p: Post)--(u: Person) WHERE p.title = '" + post.Title + "' RETURN u");
                var          user     = new User();

                userList = getuser.Result;
                foreach (var person in userList)
                {
                    var userprops = JsonConvert.SerializeObject(person.As <INode>().Properties);
                    user = (JsonConvert.DeserializeObject <User>(userprops));
                }

                // After getting al the required data, it is put in Newspost object and added to the list of newsposts.
                postList.Add(new Newspost()
                {
                    PostId      = post.PostId,
                    Title       = post.Title,
                    Description = post.Description,
                    DateAdded   = post.DateAdded,
                    FirstName   = user.FirstName,
                    LastName    = user.LastName
                });
            }

            // The final list is put into a ordered list called feed, so the results will be displayed in the right order (newest first).
            List <Newspost> feed = postList.OrderByDescending(p => p.DateAdded).ToList();

            //return View(feed);
            return(feed);
        }
示例#6
0
        public int Insert(DateTime Createdon, string personName, int Categoryid, string Subject, string Content, bool Isurgent)
        {
            Newspost item = new Newspost();

            item.Createdon = Createdon;

            item.Personid = Person.FetchByUsername(personName).Id;

            item.Categoryid = Categoryid;

            item.Subject = Subject;

            item.Content = Content;

            item.Isurgent = Isurgent;

            item.Deleted = false;

            item.Save(UserName);

            return item.Id;
        }
示例#7
0
 public void SelectNewsPost(int id)
 {
     this.SelectedNewsPost = Newspost.FetchByID(id);
 }
示例#8
0
 public void SelectNewsPost(int id)
 {
     this.SelectedNewsPost = Newspost.FetchByID(id);
 }