Exemplo n.º 1
0
        public List <News> GetNews()
        {
            Dse.ISession session = SessionManager.GetSession();
            List <News>  news    = new List <News>();

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

            var newsData = session.Execute("select * from \"News\"");

            foreach (var noveltyData in newsData)
            {
                News novelty = new News();
                novelty.newsID      = noveltyData["newsID"] != null ? noveltyData["newsID"].ToString() : string.Empty;
                novelty.title       = noveltyData["title"] != null ? noveltyData["title"].ToString() : string.Empty;
                novelty.imageURL    = noveltyData["imageurl"] != null ? noveltyData["imageurl"].ToString() : string.Empty;
                novelty.description = noveltyData["description"] != null ? noveltyData["description"].ToString() : string.Empty;
                novelty.likes       = noveltyData["likes"] != null?Int32.Parse(noveltyData["likes"].ToString()) : -1;

                novelty.dislikes = noveltyData["dislikes"] != null?Int32.Parse(noveltyData["dislikes"].ToString()) : -1;

                novelty.dateOfPublication = noveltyData["date_of_publication"] != null ? noveltyData["date_of_publication"].ToString() : string.Empty;
                novelty.journalist        = noveltyData["journalist"] != null ? noveltyData["journalist"].ToString() : string.Empty;
                novelty.tags = (string[])noveltyData["tags"];

                news.Add(novelty);
            }

            return(news);
        }
Exemplo n.º 2
0
        public ActionResult Post([FromBody] News _news)
        {
            Dse.ISession session = SessionManager.GetSession();
            News         news    = new News();

            if (_news != null)
            {
                news = _news;
            }

            if (session == null)
            {
                return(StatusCode(500));
            }

            string formatedTags = getFormatedTags(news.tags);

            RowSet newsData = session.Execute("insert into \"News\" (\"newsID\", title, imageURL, description, likes, dislikes, journalist, tags, date_of_publication) " +
                                              "values ('" + news.newsID + "', '" + news.title + "', '" + news.imageURL + "', '" + news.description + "', " + news.likes + ", " + news.dislikes + ", '" + news.journalist + "', [" + formatedTags + "],'" + news.dateOfPublication + "')");

            foreach (string tag in news.tags)
            {
                session.Execute("insert into \"TagNews\" (\"tagID\", \"newsID\", title, imageURL, description, journalist, date_of_publication) values " +
                                "('" + tag + "', '" + news.newsID + "', '" + news.title + "', '" + news.imageURL + "', '" + news.description + "', '" + news.journalist + "', '" + news.dateOfPublication + "')");
            }
            return(StatusCode(200));
        }
Exemplo n.º 3
0
        public List <TagNews> GetNewsByTag(string tagId)
        {
            Dse.ISession session = SessionManager.GetSession();

            List <TagNews> listOfTagedNews = new List <TagNews>();

            if (session == null)
            {
                return(null);
            }
            string query   = "select * from \"TagNews\" where \"tagID\"=\'" + tagId + "\'";
            var    allRows = session.Execute(query);

            if (allRows != null)
            {
                foreach (var tagNewsData in allRows)
                {
                    TagNews news = new TagNews();
                    news.newsID            = tagNewsData["newsID"] != null ? tagNewsData["newsID"].ToString() : string.Empty;
                    news.tagID             = tagNewsData["tagID"] != null ? tagNewsData["tagID"].ToString() : string.Empty;
                    news.title             = tagNewsData["title"] != null ? tagNewsData["title"].ToString() : string.Empty;
                    news.imageURL          = tagNewsData["imageurl"] != null ? tagNewsData["imageurl"].ToString() : string.Empty;
                    news.description       = tagNewsData["description"] != null ? tagNewsData["description"].ToString() : string.Empty;
                    news.dateOfPublication = tagNewsData["date_of_publication"] != null ? tagNewsData["date_of_publication"].ToString() : string.Empty;
                    news.journalist        = tagNewsData["journalist"] != null ? tagNewsData["journalist"].ToString() : string.Empty;
                    listOfTagedNews.Add(news);
                }
            }
            if (listOfTagedNews.Count == 0)
            {
                return(null);
            }
            return(listOfTagedNews);
        }
Exemplo n.º 4
0
        public News Get(string newsID)
        {
            Dse.ISession session = SessionManager.GetSession();
            News         news    = new News();

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

            Row newsData = session.Execute("select * from \"News\" where \"newsID\"='" + newsID + "'").FirstOrDefault();

            if (newsData != null)
            {
                news.newsID      = newsData["newsID"] != null ? newsData["newsID"].ToString() : string.Empty;
                news.title       = newsData["title"] != null ? newsData["title"].ToString() : string.Empty;
                news.imageURL    = newsData["imageurl"] != null ? newsData["imageurl"].ToString() : string.Empty;
                news.description = newsData["description"] != null ? newsData["description"].ToString() : string.Empty;
                news.likes       = newsData["likes"] != null?Int32.Parse(newsData["likes"].ToString()) : -1;

                news.dislikes = newsData["dislikes"] != null?Int32.Parse(newsData["dislikes"].ToString()) : -1;

                news.dateOfPublication = newsData["date_of_publication"] != null ? newsData["date_of_publication"].ToString() : string.Empty;
                news.journalist        = newsData["journalist"] != null ? newsData["journalist"].ToString() : string.Empty;
                news.tags = (string[])newsData["tags"];
            }

            return(news);
        }
Exemplo n.º 5
0
        public BookmarkNews AddBookmark([FromBody] BookmarkNews _bookmarkNews)
        {
            Dse.ISession session  = SessionManager.GetSession();
            BookmarkNews bookMark = new BookmarkNews();

            if (session == null)
            {
                StatusCode(204);
                return(null);
            }

            session.Execute("insert into \"BookmarkNews\" (\"username\", \"newsID\", title, imageURL, description, journalist, date_of_publication) values " +
                            "('" + _bookmarkNews.username + "', '" + _bookmarkNews.newsID + "', '" + _bookmarkNews.title + "', '" + _bookmarkNews.imageURL + "', '" + _bookmarkNews.description + "', '" + _bookmarkNews.journalist + "', '" + _bookmarkNews.dateOfPublication + "')");


            var data = session.Execute("select * from \"BookmarkNews\" where \"username\"='" + _bookmarkNews.username + "' and \"newsID\"='" + _bookmarkNews.newsID + "'");

            foreach (var bookmarkedNewsData in data)
            {
                bookMark.username          = bookmarkedNewsData["username"] != null ? bookmarkedNewsData["username"].ToString() : string.Empty;
                bookMark.newsID            = bookmarkedNewsData["newsID"] != null ? bookmarkedNewsData["newsID"].ToString() : string.Empty;
                bookMark.title             = bookmarkedNewsData["title"] != null ? bookmarkedNewsData["title"].ToString() : string.Empty;
                bookMark.imageURL          = bookmarkedNewsData["imageurl"] != null ? bookmarkedNewsData["imageurl"].ToString() : string.Empty;
                bookMark.description       = bookmarkedNewsData["description"] != null ? bookmarkedNewsData["description"].ToString() : string.Empty;
                bookMark.dateOfPublication = bookmarkedNewsData["date_of_publication"] != null ? bookmarkedNewsData["date_of_publication"].ToString() : string.Empty;
                bookMark.journalist        = bookmarkedNewsData["journalist"] != null ? bookmarkedNewsData["journalist"].ToString() : string.Empty;
            }
            StatusCode(200);
            return(bookMark);
        }
Exemplo n.º 6
0
        public List <BookmarkNews> GetNewsByTag(string username)
        {
            Dse.ISession session = SessionManager.GetSession();

            List <BookmarkNews> listOfTagedNews = new List <BookmarkNews>();

            if (session == null)
            {
                return(null);
            }
            string query   = "select * from \"BookmarkNews\" where \"username\"=\'" + username + "\'";
            var    allRows = session.Execute(query);

            if (allRows != null)
            {
                foreach (var BookmarkNewsData in allRows)
                {
                    BookmarkNews news = new BookmarkNews();
                    news.newsID            = BookmarkNewsData["newsID"] != null ? BookmarkNewsData["newsID"].ToString() : string.Empty;
                    news.username          = BookmarkNewsData["username"] != null ? BookmarkNewsData["username"].ToString() : string.Empty;
                    news.title             = BookmarkNewsData["title"] != null ? BookmarkNewsData["title"].ToString() : string.Empty;
                    news.imageURL          = BookmarkNewsData["imageurl"] != null ? BookmarkNewsData["imageurl"].ToString() : string.Empty;
                    news.description       = BookmarkNewsData["description"] != null ? BookmarkNewsData["description"].ToString() : string.Empty;
                    news.dateOfPublication = BookmarkNewsData["date_of_publication"] != null ? BookmarkNewsData["date_of_publication"].ToString() : string.Empty;
                    news.journalist        = BookmarkNewsData["journalist"] != null ? BookmarkNewsData["journalist"].ToString() : string.Empty;
                    listOfTagedNews.Add(news);
                }
            }
            return(listOfTagedNews);
        }
Exemplo n.º 7
0
 public ActionResult Post([FromBody] UserLikes value)
 {
     Dse.ISession session = SessionManager.GetSession();
     if (session != null)
     {
         Row hasLiked = session.Execute("select count(*), username, \"newsID\", \"isLike\" from \"UserLikes\" where username = '******' and \"newsID\" =" + "'" + value.NewsID + "'").FirstOrDefault();
         if (Int32.Parse(hasLiked["count"].ToString()) == 0)
         {
             session.Execute("insert into \"UserLikes\"(\"username\", \"newsID\", \"isLike\") values('" + value.Username + "', '" + value.NewsID + "', " + value.IsLike + ")");
             if (value.IsLike)
             {
                 session.Execute("update \"OnlineNews\".\"News\" set likes = " + (value.NumberOfLikes + 1) + " where \"newsID\" = '" + value.NewsID + "'");
                 return(StatusCode(200));
             }
             else
             {
                 session.Execute("update \"OnlineNews\".\"News\" set dislikes = " + (value.NumberOfDislikes + 1) + " where \"newsID\" = '" + value.NewsID + "'");
                 return(StatusCode(200));
             }
         }
         else if (value.IsLike)
         {
             if (Boolean.Parse(hasLiked["isLike"].ToString()))
             {
                 session.Execute("delete from \"UserLikes\" where username = '******' and \"newsID\" ='" + value.NewsID + "'");
                 session.Execute("update \"OnlineNews\".\"News\" set likes = " + (value.NumberOfLikes - 1) + " where \"newsID\" = '" + value.NewsID + "'");
                 return(StatusCode(200));
             }
             else
             {
                 session.Execute("update \"OnlineNews\".\"UserLikes\" set \"isLike\" = " + true + " where username = '******' and \"newsID\" ='" + value.NewsID + "'");
                 session.Execute("update \"OnlineNews\".\"News\" set likes = " + (value.NumberOfLikes + 1) + ", dislikes = " + (value.NumberOfDislikes - 1) + " where \"newsID\" = '" + value.NewsID + "'");
                 return(StatusCode(200));
             }
         }
         else if (!value.IsLike)
         {
             if (!Boolean.Parse(hasLiked["isLike"].ToString()))
             {
                 session.Execute("delete from \"UserLikes\" where username = '******' and \"newsID\" ='" + value.NewsID + "'");
                 session.Execute("update \"OnlineNews\".\"News\" set dislikes = " + (value.NumberOfDislikes - 1) + " where \"newsID\" = '" + value.NewsID + "'");
                 return(StatusCode(200));
             }
             else
             {
                 session.Execute("update \"OnlineNews\".\"UserLikes\" set \"isLike\" = " + false + " where username = '******' and \"newsID\" ='" + value.NewsID + "'");
                 session.Execute("update \"OnlineNews\".\"News\" set likes = " + (value.NumberOfLikes - 1) + ", dislikes = " + (value.NumberOfDislikes + 1) + " where \"newsID\" = '" + value.NewsID + "'");
                 return(StatusCode(200));
             }
         }
     }
     return(StatusCode(500));
 }
Exemplo n.º 8
0
        public void Delete(string newsID)
        {
            Dse.ISession session = SessionManager.GetSession();
            News         news    = new News();

            if (session == null)
            {
                return;
            }

            RowSet newsData = session.Execute("delete from \"News\" where \"newsID\" = '" + newsID + "'");
        }
Exemplo n.º 9
0
        public ActionResult Post([FromBody] User _user)
        {
            Dse.ISession session = SessionManager.GetSession();
            User         user    = new User();

            if (_user != null)
            {
                user = _user;
            }
            if (session == null)
            {
                return(StatusCode(500));
            }
            Row userData = session.Execute("select * from \"User\" where \"username\"='" + user.Username + "'").FirstOrDefault();

            if (userData != null)
            {
                return(StatusCode(500));
            }
            session.Execute("insert into \"User\"(\"username\", \"password\", \"isJournalist\") values('" + user.Username + "', '" + user.Password + "', " + user.isJournalist + ")");
            return(StatusCode(200));
        }
Exemplo n.º 10
0
        public object Get(string username)
        {
            Dse.ISession     session         = SessionManager.GetSession();
            List <UserLikes> listOfNewsLiked = new List <UserLikes>();

            if (session != null)
            {
                UserLikes tmp;
                var       rows = session.Execute("select * from \"UserLikes\" where username = '******'");
                if (rows != null)
                {
                    foreach (var row in rows)
                    {
                        tmp          = new UserLikes();
                        tmp.NewsID   = row["newsID"].ToString();
                        tmp.Username = row["username"].ToString();
                        tmp.IsLike   = Boolean.Parse(row["isLike"].ToString());
                        listOfNewsLiked.Add(tmp);
                    }
                }
            }
            return(listOfNewsLiked);
        }
Exemplo n.º 11
0
        public User LogIn([FromBody] User _user)
        {
            Dse.ISession session = SessionManager.GetSession();
            User         user    = new User();

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


            Row userData = session.Execute("select * from \"User\" where \"username\"='" + _user.Username + "'").FirstOrDefault();

            if (userData != null)
            {
                if (userData["password"].ToString().Trim() == _user.Password)
                {
                    user.Username     = userData["username"].ToString();
                    user.isJournalist = Boolean.Parse(userData["isJournalist"].ToString());
                    return(user);
                }
            }
            return(null);
        }