Ejemplo n.º 1
0
        public async Task <TopicHomepageViewModel> GetTopicById(int topicId, string lang = "vi")
        {
            TopicHomepageViewModel result = null;
            string cmd = $@"SELECT * FROM `topic` t
                            LEFT JOIN `topic_language` tl ON t.id = tl.topic_id
                            WHERE t.is_deleted = 0 and t.id = {topicId}";

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

                rd.Read <Topic, TopicLanguage, TopicHomepageViewModel>(
                    (fRs, flRs) =>
                {
                    if (result == null)
                    {
                        result = CommonHelper.Mapper <Topic, TopicHomepageViewModel>(fRs);
                    }


                    if (flRs != null)
                    {
                        result.TopicLanguages.Add(flRs);
                    }

                    return(result);
                }
                    );

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

                    rd.Read <Topic, TopicLanguage, TopicHomepageViewModel>(
                        (fRs, flRs) =>
                    {
                        if (result == null)
                        {
                            result = CommonHelper.Mapper <Topic, TopicHomepageViewModel>(fRs);
                        }

                        if (flRs != null)
                        {
                            result.TopicLanguages.Add(flRs);
                        }

                        return(result);
                    }
                        );

                    return(result);
                }
            }
        }
Ejemplo n.º 2
0
 public UpdateCommand(TopicHomepageViewModel topic)
 {
     this.Topic = topic;
 }
Ejemplo n.º 3
0
 public AddCommand(TopicHomepageViewModel topic)
 {
     this.Topic = topic;
 }