Esempio n. 1
0
        public static Dbo.Article GetArticleDbo(long articleId)
        {
            try
            {
                using (Entities bdd = new Entities())
                {
                    T_Article   article    = bdd.T_Article.Include("T_Comment.T_User").Include("T_ArticleTag.T_Tag").Where(a => a.Id == articleId).FirstOrDefault();
                    Dbo.Article dboArticle = new Dbo.Article()
                    {
                        Id           = article.Id,
                        BlogId       = article.BlogId,
                        MediaUrl     = article.MediaUrl,
                        MediaTypeId  = article.MediaTypeId,
                        Caption      = article.Text,
                        CreationDate = article.CreationDate,
                        Comments     = new List <Dbo.Comment>(),
                        Tags         = new List <Dbo.Tag>()
                    };

                    foreach (T_Comment comment in article.T_Comment)
                    {
                        dboArticle.Comments.Add(new Dbo.Comment()
                        {
                            Id           = comment.Id,
                            UserId       = comment.UserId,
                            ArticleId    = comment.ArticleId,
                            Content      = comment.Comment,
                            CreationDate = comment.CreationDate,
                            UserName     = comment.T_User.Login
                        });
                    }

                    foreach (T_ArticleTag aTag in article.T_ArticleTag)
                    {
                        Dbo.Tag tag = new Dbo.Tag();
                        tag.Id   = aTag.T_Tag.Id;
                        tag.Name = aTag.T_Tag.Name;

                        dboArticle.Tags.Add(tag);
                    }

                    return(dboArticle);
                }
            }
            catch (Exception e)
            {
                Trace.WriteLine(e.Message);
                throw;
            }
        }
Esempio n. 2
0
        public static Dbo.Article GetArticleDbo(long articleId)
        {
            try
            {
                using (Entities bdd = new Entities())
                {
                     T_Article article = bdd.T_Article.Include("T_Comment.T_User").Include("T_ArticleTag.T_Tag").Where(a => a.Id == articleId).FirstOrDefault();
                     Dbo.Article dboArticle = new Dbo.Article(){
                        Id = article.Id,
                        BlogId = article.BlogId,
                        MediaUrl = article.MediaUrl,
                        MediaTypeId = article.MediaTypeId,
                        Caption = article.Text,
                        CreationDate = article.CreationDate,
                        Comments = new List<Dbo.Comment>(),
                        Tags = new List<Dbo.Tag>()
                    };

                    foreach (T_Comment comment in article.T_Comment)
                    {
                        dboArticle.Comments.Add(new Dbo.Comment()
                        {
                            Id = comment.Id,
                            UserId = comment.UserId,
                            ArticleId = comment.ArticleId,
                            Content = comment.Comment,
                            CreationDate = comment.CreationDate,
                            UserName = comment.T_User.Login
                        });
                    }

                    foreach (T_ArticleTag aTag in article.T_ArticleTag)
                    {
                        Dbo.Tag tag = new Dbo.Tag();
                        tag.Id = aTag.T_Tag.Id;
                        tag.Name = aTag.T_Tag.Name;

                        dboArticle.Tags.Add(tag);
                    }

                    return dboArticle;
                }
            }
            catch (Exception e)
            {
                Trace.WriteLine(e.Message);
                throw;
            }
        }