Example #1
0
        public static string GetUrl(this PostHomepageViewModel post)
        {
            if (post == null)
            {
                return(string.Empty);
            }

            return(string.Format("/{0}-b{1}.html", post.Title?.Editor(), post.Id));
        }
Example #2
0
 public UpdateCommand(PostHomepageViewModel post)
 {
     this.Post = post;
 }
Example #3
0
 public AddCommand(PostHomepageViewModel post)
 {
     this.Post = post;
 }
Example #4
0
        public async Task <PostHomepageViewModel> GetPost(int postId, string lang = "vi")
        {
            PostHomepageViewModel result = null;
            string cmd = $@"SELECT p.*, top.*, pl.* FROM `post` p
							LEFT JOIN `topic_post` tp On tp.post_id = p.id
							LEFT JOIN `topic` top ON top.id = tp.topic_id
                            LEFT JOIN `post_language` pl ON p.id = pl.post_id
                            WHERE p.is_deleted = 0 and p.id = {postId}";

            if (DbConnection != null)
            {
                var rd = await DbConnection.QueryMultipleAsync(cmd, transaction : DbTransaction);

                rd.Read <Post, Topic, PostLanguage, PostHomepageViewModel>(
                    (pRs, topicRs, plRs) =>
                {
                    if (result == null)
                    {
                        result = CommonHelper.Mapper <Post, PostHomepageViewModel>(pRs);
                    }


                    if (plRs != null)
                    {
                        result.PostLanguages.Add(plRs);
                    }
                    if (topicRs != null)
                    {
                        var topic = result.Topics.FirstOrDefault(tps => tps.Id == topicRs.Id);
                        if (topic == null)
                        {
                            result.Topics.Add(topicRs);
                        }
                    }

                    return(result);
                }
                    );

                return(result);
            }
            else
            {
                using (var conn = DALHelper.GetConnection())
                {
                    var rd = await conn.QueryMultipleAsync(cmd);

                    rd.Read <Post, Topic, PostLanguage, PostHomepageViewModel>(
                        (pRs, topicRs, plRs) =>
                    {
                        if (result == null)
                        {
                            result = CommonHelper.Mapper <Post, PostHomepageViewModel>(pRs);
                        }


                        if (plRs != null)
                        {
                            result.PostLanguages.Add(plRs);
                        }
                        if (topicRs != null)
                        {
                            var topic = result.Topics.FirstOrDefault(tps => tps.Id == topicRs.Id);
                            if (topic == null)
                            {
                                result.Topics.Add(topicRs);
                            }
                        }

                        return(result);
                    }
                        );

                    return(result);
                }
            }
        }