public ActionResult Test() { Article article = new Article(); Dbo.Article res = BusinessManagement.Article.GetArticleDbo(2); return(View()); }
/// <summary> /// Adds a new Article to the database and returns the success of the operation. /// The id field of the parameter will be ignored when adding to the database. /// </summary> public static bool AddArticle(Dbo.Article article) { try { using (ProjectDBEntities ctx = new ProjectDBEntities()) { ctx.T_Article.Add(new T_Article() { Title = article.Title, IdAuthor = article.IdAuthor, Date = article.Date, Image = article.Image, Text = article.Text, Viewcount = 0 }); if (ctx.SaveChanges() == 0) { return(false); } } return(true); } catch (Exception) { return(false); } }
private Article ConvertToWebArticle(Dbo.Article article) { Article result = new Article(); result.CreationDate = article.CreationDate; result.Id = article.Id; result.Text = article.Caption; result.MediaUrl = article.MediaUrl; result.Tags = new List <string>(); article.Tags.ForEach(tag => result.Tags.Add(tag.Name)); switch ((long)article.MediaTypeId) { case ((long)Tools.MediaTypes.Image): result.MediaType = MediaTypeWebService.IMAGE; break; case ((long)Tools.MediaTypes.Video): result.MediaType = MediaTypeWebService.VIDEO; break; case ((long)Tools.MediaTypes.Music): result.MediaType = MediaTypeWebService.MUSIC; break; default: result.MediaType = MediaTypeWebService.QUOTE; break; } return(result); }
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; } }
public List <Article> GetArticlesFromBlog(string blogOwner, string blogName) { List <Article> articles = new List <Article>(); Blog blog = new Blog(blogOwner, blogName); BusinessManagement.Article art = new BusinessManagement.Article(); if (!blog.Exists) { return(articles); } blog.GetArticles().ForEach(item => { Dbo.Article dboArt = BusinessManagement.Article.GetArticleDbo(item.Id); articles.Add(ConvertToWebArticle(dboArt)); }); return(articles); }
public ActionResult Display(long articleId) { Dbo.Article article = BusinessManagement.Article.GetArticleDbo(articleId); Models.ArticleModel model = new Models.ArticleModel() { ArticleId = article.Id, BlogId = article.BlogId, Caption = article.Caption, MediaType = article.MediaTypeId.Value, MediaUrl = article.MediaUrl, Tags = article.Tags, Comments = article.Comments }; //ViewData.Model = new ArticleModel(); string articleUrl = BASE_URL + "/ArticleDisplay/Display?id=" + articleId; ViewBag.urlFB = HttpUtility.UrlEncode(articleUrl); ViewBag.urlTw = articleUrl; return(View(model)); }
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; } }
/// <summary> /// Adds a new Article to the database and returns the success of the operation. /// The id field of the parameter will be ignored when adding to the database. /// </summary> public static bool AddArticle(Dbo.Article article) { return(DataAccess.Article.AddArticle(article)); }