示例#1
0
        /// <summary>
        /// Get Posts with paging.
        /// </summary>
        /// <param name="PageSize">Number of results per page.</param>
        /// <param name="Index">Last Index of result</param>
        /// <returns></returns>
        public List <PostsModels> GetPosts(int PageSize, int Index)
        {
            MensaheRepository mr  = new MensaheRepository();
            TagIyaRepository  tir = new TagIyaRepository();

            try
            {
                var msgs = mr.GetAllMessage().OrderByDescending(m => m.DatePosted).ToList();

                if (msgs.Count > PageSize)
                {
                    msgs = msgs.GetRange(Index, PageSize);
                }

                List <PostsModels> posts = new List <PostsModels>();

                foreach (Mensahe msg in msgs)
                {
                    var tagIya = tir.GetUserbyMsgId(msg.MessageId);
                    // we don't want to display the message for those non-existing users
                    if (tagIya != null)
                    {
                        PostsModels post = this.GetPostsModel(tagIya, msg);
                        posts.Add(post);
                    }
                }
                return(posts);
            }
            catch
            {
                throw;
            }
        }
示例#2
0
        /// <summary>
        /// Get Post by Message id
        /// </summary>
        /// <param name="MessageId">Message Id</param>
        /// <returns></returns>
        public static PostsModels GetPostByMessageId(int MessageId)
        {
            MensaheRepository mr  = new MensaheRepository();
            TagIyaRepository  tir = new TagIyaRepository();

            try
            {
                var msg    = mr.GetMessage(MessageId);
                var tagIya = tir.GetUserbyMsgId(MessageId);

                PostsModels post = new PostsModels();
                post = post.GetPostsModel(tagIya, msg);

                return(post);
            }
            catch
            {
                throw;
            }
        }