public Task UpdateAsync(Domain.ArticleAggregate.Article article) { ArticleModel target = _dbContext.ArticleModels.Local.FirstOrDefault(am => am.Id == article.Id); _dbContext.Entry(ArticleMapper.MapToDataModel(article, target)).State = EntityState.Modified; return(Task.CompletedTask); }
public IEnumerable <ArticleDTO> GetArticlesWithTegFilter(IEnumerable <TegDTO> tegs) { IEnumerable <Article> articles = _unitOfWork.ArticleRepository.Get(includeProperties: "ArticleTegs"); List <Article> result = new List <Article>(); foreach (TegDTO teg in tegs) { Teg tegEntity; if (teg.Name != null) { tegEntity = _unitOfWork.TegRepository.Get(t => t.Name == teg.Name).FirstOrDefault(); if (tegEntity == null) { throw new ArgumentNullException(nameof(tegEntity)); } } else { throw new ArgumentNullException(nameof(teg)); } var filtered = articles.Where(a => a.ArticleTegs.Contains(a.ArticleTegs.Where(at => at.ArticleId == a.Id && at.TegId == tegEntity.Id).FirstOrDefault())); foreach (Article article in filtered) { if (!result.Contains(article)) { result.Add(article); } } } return(ArticleMapper.Map(result)); }
public async Task <ArticleDTO> GetArticleById(int id) { var article = _unitOfWork.ArticleRepository.Get(a => a.Id == id, includeProperties: "Comments,ArticleTegs").FirstOrDefault(); if (article == null) { throw new ArgumentNullException(nameof(article)); } var result = ArticleMapper.Map(article); if (article.Comments != null && article.Comments.Count > 0) { result.Comments = new List <CommentDTO>(); foreach (Comment comment in article.Comments) { CommentDTO dto = CommentMapper.Map(comment); dto.CreatorUsername = (await _userManager.FindByIdAsync(comment.UserId)).UserName; result.Comments.Add(dto); } } result.AuthorId = (await _unitOfWork.BlogRepository.GetByIdAsync(article.BlogId)).OwnerId; result.AuthorUsername = (await _userManager.FindByIdAsync(result.AuthorId)).UserName; if (article.ArticleTegs != null && article.ArticleTegs.Count > 0) { result.Tegs = new List <TegDTO>(); foreach (ArticleTeg teg in article.ArticleTegs) { result.Tegs.Add(TegMapper.Map(await _unitOfWork.TegRepository.GetByIdAsync(teg.TegId))); } } return(result); }
public void MapToViewModelMapsAllProperties() { // Arrange var article = new Article { Id = 1, Title = "Test Title", Body = "Test Body", Author = new User { UserName = "******" }, DatePublished = new DateTime(2017, 1, 1), DateModified = new DateTime(2017, 1, 2) }; var mapper = new ArticleMapper(); // Act var viewModel = new ArticleViewModel(); mapper.MapToViewModel(article, viewModel); // Assert Assert.AreEqual(article.Id, viewModel.Id); Assert.AreEqual(article.Title, viewModel.Title); Assert.AreEqual(article.Body, viewModel.Body); Assert.AreEqual(article.Author.UserName, viewModel.Author); Assert.AreEqual(article.DatePublished, new DateTime(2017, 1, 1)); Assert.AreEqual(article.DateModified, new DateTime(2017, 1, 2)); }
public void MapToModelUpdatesTitleAndBodyOnly() { // Arrange var viewModel = new ArticleViewModel { Id = 1, Title = "Test Title", Body = "Test Body", Author = "Test Author", DatePublished = new DateTime(2017, 1, 1), DateModified = new DateTime(2017, 1, 2) }; var mapper = new ArticleMapper(); // Act var model = new Article(); mapper.MapToModel(viewModel, model); // Assert Assert.AreEqual(default(int), model.Id); Assert.AreEqual(viewModel.Title, model.Title); Assert.AreEqual(viewModel.Body, model.Body); Assert.IsNull(model.Author); Assert.AreEqual(default(DateTime), model.DatePublished); Assert.AreNotEqual(default(DateTime), model.DateModified); }
public Task AddAsync(Domain.ArticleAggregate.Article article) { var mappedModel = ArticleMapper.MapToDataModel(article); _dbContext.ArticleModels.Add(mappedModel); article.SetId(mappedModel.Id); return(Task.CompletedTask); }
#pragma warning disable CS1591 // 缺少对公共可见类型或成员“WhisperController.WhisperController(IUserService, UserMapper, IArticleService, ArticleMapper)”的 XML 注释 public WhisperController(IUserService userService, UserMapper userMapper, IArticleService articleService, ArticleMapper articleMapper) #pragma warning restore CS1591 // 缺少对公共可见类型或成员“WhisperController.WhisperController(IUserService, UserMapper, IArticleService, ArticleMapper)”的 XML 注释 { this.userService = userService; this.userMapper = userMapper; this.articleService = articleService; this.articleMapper = articleMapper; }
public ActionResult PublishArticle(ArticleViewModel viewModel) { if (ModelState.IsValid) { Service.Publish(ArticleMapper.Map(viewModel)); } return(GetUserArticles()); }
public IEnumerable <ArticleDTO> GetAllArticles() { var articles = _unitOfWork.ArticleRepository.Get(); if (articles == null) { throw new ArgumentNullException(nameof(articles)); } return(ArticleMapper.Map(articles)); }
public IEnumerable <ArticleDTO> GetArticlesWihtTextFilter(string filter) { var articles = _unitOfWork.ArticleRepository.Get(a => a.Content.Contains(filter) || a.Name.Contains(filter)); if (articles == null) { throw new ArgumentNullException(nameof(articles)); } return(ArticleMapper.Map(articles)); }
#pragma warning disable CS1591 // 缺少对公共可见类型或成员“IndexController.IndexController(IArticleService, IMessageService, IUserService, ITagService, IConfiguration, ArticleMapper, MessageMapper)”的 XML 注释 public IndexController(IArticleService articleService, IMessageService messageService, IUserService userService, ITagService tagService, IConfiguration conf, ArticleMapper articleMapper, MessageMapper messageMapper) #pragma warning restore CS1591 // 缺少对公共可见类型或成员“IndexController.IndexController(IArticleService, IMessageService, IUserService, ITagService, IConfiguration, ArticleMapper, MessageMapper)”的 XML 注释 { this.articleService = articleService; this.messageService = messageService; this.userService = userService; this.tagService = tagService; this.conf = conf; this.articleMapper = articleMapper; this.messageMapper = messageMapper; }
public ActionResult Article(string alias) { ArticleViewModel article = ArticleMapper.ToViewModel(newsService.News.FirstOrDefault(x => x.Alias == alias)); if (article == null) { throw new HttpException(404, "Указанная страница не найдена!"); } return(View(article)); }
#pragma warning disable CS1591 // 缺少对公共可见类型或成员“DetailsController.DetailsController(IFileAttachmentService, IArticleService, ITagService, ICommentService, IUserService, ArticleMapper, CommentMapper, EmailHelper)”的 XML 注释 public DetailsController(IFileAttachmentService fileAttachmentService, IArticleService articleService, ITagService tagService, ICommentService commentService, IUserService userService, ArticleMapper articleMapper, CommentMapper commentMapper, EmailHelper emailHelper) #pragma warning restore CS1591 // 缺少对公共可见类型或成员“DetailsController.DetailsController(IFileAttachmentService, IArticleService, ITagService, ICommentService, IUserService, ArticleMapper, CommentMapper, EmailHelper)”的 XML 注释 { this.fileAttachmentService = fileAttachmentService; this.articleService = articleService; this.tagService = tagService; this.commentService = commentService; this.userService = userService; this.articleMapper = articleMapper; this.commentMapper = commentMapper; this.emailHelper = emailHelper; }
public override void PreInitialize() { // 配置权限功能 Configuration.Authorization.Providers.Add <ZYShopAuthorizationProvider>(); Configuration.Authorization.Providers.Add <ArticleAuthorizationProvider>(); Configuration.Authorization.Providers.Add <ArticleClassAuthorizationProvider>(); // 自定义类型映射 Configuration.Modules.AbpAutoMapper().Configurators.Add(configuration => { ArticleMapper.CreateMappings(configuration); ArticleClassMapper.CreateMappings(configuration); }); }
public void Map_GivenIsValidArticles_ShouldMapCorrectly() { var articleMapper = new ArticleMapper(); var articleRepositry = new ArticleRepository(); var articles = articleRepositry.GetAll(); var articlesDto = articleMapper.Map(articles); articlesDto.Should().BeEquivalentTo(articles, options => options .Excluding(art => art.LastModified) .Excluding(art => art.LastModifiedBy) ); }
public void Map_GivenIsValidArticle_ShouldMapCorrectly() { var articleMapper = new ArticleMapper(); var articleRepositry = new ArticleRepository(); var article = articleRepositry.FindById(1001); var articleDto = articleMapper.Map(article); articleDto.Should().BeEquivalentTo(article, options => options .Excluding(art => art.LastModified) .Excluding(art => art.LastModifiedBy) ); }
public async Task <ArticleDTO> CreateArticle(ArticleDTO article, string token) { if (article == null) { throw new ArgumentNullException(nameof(article)); } if (article.Name == null) { throw new ArgumentNullException(nameof(article.Name)); } if (article.Content == null) { throw new ArgumentNullException(nameof(article.Content)); } string ownerId = (await _unitOfWork.BlogRepository.GetByIdAsync(article.BlogId.GetValueOrDefault())).OwnerId; if (ownerId.CompareTo(_jwtFactory.GetUserIdClaim(token)) != 0) { throw new NotEnoughtRightsException(); } var articleEntity = ArticleMapper.Map(article); articleEntity.LastUpdate = DateTime.Now; _unitOfWork.ArticleRepository.Insert(articleEntity); await _unitOfWork.SaveAsync(); await AddTegs(articleEntity, article); var result = ArticleMapper.Map(articleEntity); if (articleEntity.ArticleTegs != null && articleEntity.ArticleTegs.Count > 0) { result.Tegs = new List <TegDTO>(); foreach (ArticleTeg teg in articleEntity.ArticleTegs) { result.Tegs.Add(TegMapper.Map(_unitOfWork.TegRepository.GetById(teg.TegId))); } } return(result); }
public void MapToModelUpdatesDatePublishedWhenCreatingNewModel() { // Arrange var viewModel = new ArticleViewModel { Id = 1, Title = "Test Title", Body = "Test Body", Author = "Test Author", DatePublished = new DateTime(2017, 1, 1), DateModified = new DateTime(2017, 1, 2) }; var mapper = new ArticleMapper(); // Act var model = mapper.MapToModel(viewModel); // Assert Assert.AreNotEqual(default(DateTime), model.DatePublished); }
public ActionResult Index(string tag) { ArticlesViewModel model = new ArticlesViewModel(); if (TempData["FlagError"] != null && ((bool)TempData["FlagError"]) == true) { return(View(model)); } var newsSection = sectionService.Sections.FirstOrDefault(x => x.Url == "/articles"); if (newsSection == null) { TempData["FlagError"] = true; ViewBag.ServerErrorMessage = "Ошибка сервера 500"; return(View(model)); } if (!newsSection.IsActive) { return(Redirect("/")); } if (Request.Url.Segments.Any(x => x == "index")) { return(RedirectPermanent($"/news")); } model.Tags = newsService.Tags.Where(x => x.IsActive && !x.IsDelete); var news = newsService.Get(tag); if (news != null) { model.Articles = news.Where(x => x.IsActive && !x.IsDelete) .Select(x => ArticleMapper.ToViewModel(x)); } return(View(model)); }
public override void PreInitialize() { IocManager.Register<BlogMongoDbDatabaseProvider>(); ArticleMapper.CreateMappings(); }
public void MapArticle(ArticleDTO articleDTO) { var model = ArticleMapper.MapArticle(articleDTO); Assert.Equal(articleDTO.Content, model.Content); }
public async Task <Domain.ArticleAggregate.Article> GetByIdAsync(int articleId) { return(ArticleMapper.MapToDomainModel( await _dbContext.ArticleModels.Include(a => a.ArticleTags).FirstOrDefaultAsync(a => a.Id == articleId) )); }
public ActionResult GetArticle(int articleId) { var article = Service.GetArticle(articleId); return(View("RenderTemplates/ArticleView", ArticleMapper.Map(article))); }
public ArticleRepository(IContext context) { this.Context = context; this.Mapper = new ArticleMapper(context); }
public void CreateArticle(ArticleDto input) { var article = ArticleMapper.Map(input); _articleRepository.Add(article); }
public Article CreateModel(ArticleDTO articleDto) { return(ArticleMapper.MapArticle(articleDto)); }
public void UpdateArticle(ArticleDto input) { var article = ArticleMapper.Map(input); _articleRepository.Update(article); }