public void CreateFullArticleEntity(FullArticleEntity fullArticle) { if (fullArticle == null) { return; } var article = new ArticleEntity() { Id = fullArticle.Id, Title = fullArticle.Title, CreationTime = fullArticle.CreationTime, Text = fullArticle.Text, TitleImage = fullArticle.TitleImage, UserId = fullArticle.User.Id, BlogId = fullArticle.Blog.Id }; uow.ArticleRepository.Create(article.ToDalArticle()); var articleTag = fullArticle.Tags.Select(x => new ArticleTagEntity() { ArticleId = fullArticle.Id, TagId = x.Id }.ToDalArticleTag()); foreach (var item in articleTag) { uow.ArticleTagRepository.Create(item); } uow.Commit(); }
//delete article with all comments public void DeleteArticle(FullArticleEntity fullArticle) { uow.ArticleRepository.Delete(fullArticle.ToDalArticle()); uow.ArticleTagRepository.DeleteAllByArticle(fullArticle.Id); uow.CommentRepository.DeleteAllByArticle(fullArticle.Id); uow.Commit(); }
public void CreateFullArticleEntity(FullArticleEntity fullArticle) { if (fullArticle == null) return; var article = new ArticleEntity() { Id = fullArticle.Id, Title = fullArticle.Title, CreationTime = fullArticle.CreationTime, Text = fullArticle.Text, TitleImage = fullArticle.TitleImage, UserId = fullArticle.User.Id, BlogId = fullArticle.Blog.Id }; uow.ArticleRepository.Create(article.ToDalArticle()); var articleTag = fullArticle.Tags.Select(x => new ArticleTagEntity() { ArticleId = fullArticle.Id, TagId = x.Id }.ToDalArticleTag()); foreach (var item in articleTag) { uow.ArticleTagRepository.Create(item); } uow.Commit(); }
public static DalArticle ToDalArticle(this FullArticleEntity article) { return(new DalArticle() { Id = article.Id, Title = article.Title, CreationTime = article.CreationTime, Text = article.Text, TitleImage = article.TitleImage, UserId = article.User.Id, BlogId = article.Blog.Id }); }
public static FullArticleViewModel ToMvcFullArticle(this FullArticleEntity article) { return new FullArticleViewModel() { Id = article.Id, Title = article.Title, CreationTime = article.CreationTime, Text = article.Text, User = article.User.ToMvcUser(), TitleImage = article.TitleImage, Blog = article.Blog?.ToMvcSimpleBlog(), Tags = article.Tags.Select( x => x.ToMvcSimpleTag()), Comments = article.Comments.Select(x => x.ToMvcFullComment()) }; }
public FullArticleEntity GetFullArticleEntity(ArticleEntity e) { if (e == null) { return(null); } var result = new FullArticleEntity() { Id = e.Id, Title = e.Title, CreationTime = e.CreationTime, Text = e.Text, User = uow.UserRepository.GetById(e.UserId)?.ToBllUser(), TitleImage = e.TitleImage, Blog = uow.BlogRepository.GetById(e.BlogId)?.ToBllBlog(), Tags = uow.ArticleTagRepository.GetAll().Where(tag => tag.ArticleId == e.Id).Select(x => uow.TagRepository.GetById(x.TagId)?.ToBllTag()), Comments = uow.CommentRepository.GetAll().Where(comment => comment.ArticleId == e.Id).Select(x => x.ToFullCommentEntity()) }; return(result); }
public FullArticleEntity GetFullArticleEntity(ArticleEntity e) { if (e == null) return null; var result = new FullArticleEntity() { Id = e.Id, Title = e.Title, CreationTime = e.CreationTime, Text = e.Text, User = uow.UserRepository.GetById(e.UserId)?.ToBllUser(), TitleImage = e.TitleImage, Blog = uow.BlogRepository.GetById(e.BlogId)?.ToBllBlog(), Tags = uow.ArticleTagRepository.GetAll().Where(tag => tag.ArticleId == e.Id).Select(x => uow.TagRepository.GetById(x.TagId)?.ToBllTag()), Comments = uow.CommentRepository.GetAll().Where(comment => comment.ArticleId == e.Id).Select(x => x.ToFullCommentEntity()) }; return result; }