Exemple #1
0
        public void OnGet()
        {
            var connection = Connection.Open();

            try
            {
                Id = int.Parse(HttpContext.Request.Query["open"]);
            }
            catch
            {
                ReturnWithError();
                return;
            }
            var reader = connection.GetDataFromDb($@"SELECT * FROM FORUM WHERE discussion_id = '{Id}'");

            if (reader.Read())
            {
                Discussion = ForumDAO.MadeNewDiscussionObject(reader, connection);
            }
            reader.Close();
            if (Discussion == null || Discussion.Name == null || Discussion.Name.Length < 1)
            {
                ReturnWithError();
                return;
            }
            reader   = CommentsDAO.GetAllComments(Id, connection);
            Comments = new List <Comments>();
            while (reader.Read())
            {
                Comments.Add(CommentsDAO.MadeNewCommentObject(reader, connection));
            }
            connection.Close();
        }
    //gets all forum topics in database
    public List<ForumTopic> getAllTopics()
    {
        ForumDAO datalayer = new ForumDAO();
        List<ForumTopic> topics = datalayer.getAllTopics();

        return topics;
    }
    //gets a forum post from the datalayer
    public ForumPost getTopic(int postID)
    {
        ForumDAO dataLayer = new ForumDAO();
        ForumPost post = dataLayer.getForumPost(postID);

        return post;
    }
    //gets all forum topics in database
    public List <ForumTopic> getAllTopics()
    {
        ForumDAO          datalayer = new ForumDAO();
        List <ForumTopic> topics    = datalayer.getAllTopics();

        return(topics);
    }
    //gets a forum post from the datalayer
    public ForumPost getTopic(int postID)
    {
        ForumDAO  dataLayer = new ForumDAO();
        ForumPost post      = dataLayer.getForumPost(postID);

        return(post);
    }
        public void OnGet()
        {
            var connection = Connection.Open();
            var reader     = ForumDAO.GetAllDiscussions(connection);

            _list = new List <Discussion>();
            while (reader.Read())
            {
                _list.Add(ForumDAO.MadeNewDiscussionObject(reader, connection));
            }
            connection.Close();
        }
    //adds a comment to a post
    public bool addComment(int postID, string username, string userComment)
    {
        Comment comment = new Comment();
        comment.forumTopic = postID;
        comment.username = username;
        comment.comment = userComment;
        comment.createdOnDate = DateTime.Now;

        ForumDAO dataLayer = new ForumDAO();
           bool success = dataLayer.addComment(comment);
           return success;
    }
    //adds a comment to a post
    public bool addComment(int postID, string username, string userComment)
    {
        Comment comment = new Comment();

        comment.forumTopic    = postID;
        comment.username      = username;
        comment.comment       = userComment;
        comment.createdOnDate = DateTime.Now;

        ForumDAO dataLayer = new ForumDAO();
        bool     success   = dataLayer.addComment(comment);

        return(success);
    }
    //adds a new post to db
    public bool addPost(string postTitle, string firstComment, string username)
    {
        ForumDAO dataLayer = new ForumDAO();
        ForumTopic topic = new ForumTopic();
        topic.createdBy = username;
        topic.createdOnDate = DateTime.Now;
        topic.title = postTitle;
        int topicID = dataLayer.createNewTopic(topic);

        Comment comment = new Comment();
        comment.comment = firstComment;
        comment.username = username;
        comment.createdOnDate = DateTime.Now;
        comment.forumTopic = topicID;
        bool success = dataLayer.addComment(comment);

        return success;
    }
    //adds a new post to db
    public bool addPost(string postTitle, string firstComment, string username)
    {
        ForumDAO   dataLayer = new ForumDAO();
        ForumTopic topic     = new ForumTopic();

        topic.createdBy     = username;
        topic.createdOnDate = DateTime.Now;
        topic.title         = postTitle;
        int topicID = dataLayer.createNewTopic(topic);

        Comment comment = new Comment();

        comment.comment       = firstComment;
        comment.username      = username;
        comment.createdOnDate = DateTime.Now;
        comment.forumTopic    = topicID;
        bool success = dataLayer.addComment(comment);

        return(success);
    }
        public void OnGet()
        {
            var connection = Connection.Open();
            var list       = UsersDAO.GetMyDiscussions(login.LoginSession, connection);

            discussions = new List <Discussion>();
            if (list != null)
            {
                var str = list.Aggregate("", (current, e) => current + ($@"'{e}'" + ","));
                str = str.Remove(str.Length - 1);
                var reader =
                    Connection.GetDataFromDb(connection, $@"SELECT * FROM FORUM WHERE discussion_id in ({str})");
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        discussions.Add(ForumDAO.MadeNewDiscussionObject(reader, connection));
                    }
                }
            }

            connection.Close();
        }
Exemple #12
0
        /// <summary> Retrieves Entity rows in a datatable which match the specified filter. It will always create a new connection to the database.</summary>
        /// <param name="selectFilter">A predicate or predicate expression which should be used as filter for the entities to retrieve.</param>
        /// <param name="maxNumberOfItemsToReturn"> The maximum number of items to return with this retrieval query.</param>
        /// <param name="sortClauses">The order by specifications for the sorting of the resultset. When not specified, no sorting is applied.</param>
        /// <param name="relations">The set of relations to walk to construct to total query.</param>
        /// <param name="pageNumber">The page number to retrieve.</param>
        /// <param name="pageSize">The page size of the page to retrieve.</param>
        /// <returns>DataTable with the rows requested.</returns>
        public static DataTable GetMultiAsDataTable(IPredicate selectFilter, long maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relations, int pageNumber, int pageSize)
        {
            ForumDAO dao = DAOFactory.CreateForumDAO();

            return(dao.GetMultiAsDataTable(maxNumberOfItemsToReturn, sortClauses, selectFilter, relations, pageNumber, pageSize));
        }