public void CreateArticle(ArticleViewModel value) { int insertedArticleId = _articleRepository.Create(value); var authorIds = value.Authors.Select(a => a.AuthorId).ToList(); _authorArticleRepository.AddArticleAuthors(authorIds, insertedArticleId); }
public object Create(ArticleDto articleDto) { Article create = _articleMapper.Map(articleDto); _articleRepository.Create(create); return(_articleMapper.Map(create)); }
public async Task <IActionResult> Create([Bind("ArticleID,Title,Text,TagID")] Article article, IFormFile uploadedFile) { if (ModelState.IsValid) { if (uploadedFile != null && uploadedFile.ContentType.ToLower().Contains("image")) { article.Image = await _imageService.SaveImageAsync(uploadedFile); } else { ModelState.AddModelError("Image", "Некорректный формат"); ViewData["tags"] = await _tagRepository.FindAll(); return(View(article)); } article.Profile = await _userManager.FindByNameAsync(User.Identity.Name); DateTime timeUtc = DateTime.UtcNow; TimeZoneInfo kstZone = TimeZoneInfo.FindSystemTimeZoneById("Russian Standard Time"); article.DateTime = TimeZoneInfo.ConvertTimeFromUtc(timeUtc, kstZone); article.Tag = await _tagRepository.FirstOrDefaultAsync(article.TagID); await _articleRepository.Create(article); return(RedirectPermanent("~/Home/Index")); } return(View(article)); }
public ResponseMessage Create(Article entity) { ResponseMessage response = new ResponseMessage(); _repository.Create(entity); return(response); }
public void Create(ArticleViewModel articleViewModel) { articleViewModel.Id = Guid.NewGuid(); articleViewModel.Abbreviated = _authorRepository.GetAuthor(articleViewModel.AuthorId).Abbreviated; var article = ViewModelToDomain(articleViewModel); _articleRepository.Create(article); }
public void ArticleExistFalseTest() { var repository = ArticleRepository.Create(); var service = this.GetArticlesService(repository); var result = service.ArticleExist(1); Assert.False(result); }
public void ArticleExistTrueTest() { var repository = ArticleRepository.Create(); var article = this.CreateArticle(repository, SeedArticle.Create()); var service = this.GetArticlesService(repository); var result = service.ArticleExist(article.Id); Assert.True(result); }
public void GetCountByAuthorRealIdTest() { var repository = ArticleRepository.Create(); var article = this.CreateArticle(repository, SeedArticle.Create()); var service = this.GetArticlesService(repository); var result = service.GetCountByAuthorId("ads"); Assert.Equal(1, result); }
public void GetLatesWithVideosNoMatchesTest() { var repository = ArticleRepository.Create(); var secondArticle = this.CreateArticle(repository, SeedArticle.CreateSecondArticle()); var service = this.GetArticlesService(repository); var result = service.GetLatesWithVideos <ArticleDumyModel>(); Assert.Empty(result); }
public void GetCountOfLocalArticlesNoResultTest() { var repository = ArticleRepository.Create(); var article = this.CreateArticle(repository, SeedArticle.Create()); var service = this.GetArticlesService(repository); var result = service.GetCountOfLocalArticles(); Assert.Equal(0, result); }
public void GetArticleById() { var repository = ArticleRepository.Create(); var article = this.CreateArticle(repository, SeedArticle.Create()); var service = this.GetArticlesService(repository); var result = service.GetArticleById <ArticleDumyModel>(article.Id).GetAwaiter().GetResult(); Assert.Equal(article.Title, result.Title); }
public void GetCountBySubCategoryIdNoMatchTest() { var repository = ArticleRepository.Create(); var secondArticle = this.CreateArticle(repository, SeedArticle.CreateSecondArticle()); var service = this.GetArticlesService(repository); var result = service.GetCountBySubCategoryId(1); Assert.Equal(0, result); }
public void GetCountByAuthorIdDeletedFakeIdTest() { var repository = ArticleRepository.Create(); var article = this.CreateArticle(repository, SeedArticle.Create()); var service = this.GetArticlesService(repository); var result = service.GetCountByAuthorIdDeleted("FAKE"); Assert.Equal(0, result); }
public void GetLatesMostViewedTest() { var repository = ArticleRepository.Create(); var article = this.CreateArticle(repository, SeedArticle.Create()); var secondArticle = this.CreateArticle(repository, SeedArticle.CreateSecondArticle()); var service = this.GetArticlesService(repository); var result = service.GetLatesMostViewed <ArticleDumyModel>(); Assert.Equal(secondArticle.Id, result.First().Id); }
public void GetCount() { var repository = ArticleRepository.Create(); this.CreateArticle(repository, SeedArticle.Create()); var service = this.GetArticlesService(repository); var result = service.GetCount(); Assert.Equal(1, result); }
public void GetAllBySubCategoryIdOneMatchTest() { var repository = ArticleRepository.Create(); var article = this.CreateArticle(repository, SeedArticle.Create()); var secondArticle = this.CreateArticle(repository, SeedArticle.CreateSecondArticle()); var service = this.GetArticlesService(repository); var result = service.GetAllBySubCategoryId <ArticleDumyModel>(1); Assert.Single(result); }
public void LastesArticleCreationDateTest() { var repository = ArticleRepository.Create(); var article = this.CreateArticle(repository, SeedArticle.Create()); var secondArticle = this.CreateArticle(repository, SeedArticle.CreateSecondArticle()); var service = this.GetArticlesService(repository); var result = service.LastesArticleCreationDate(); Assert.Equal(secondArticle.CreatedOn, result); }
public void GetCountByRegionNoMatchTest() { var repository = ArticleRepository.Create(); var article = this.CreateArticle(repository, SeedArticle.Create()); var secondArticle = this.CreateArticle(repository, SeedArticle.CreateSecondArticle()); var service = this.GetArticlesService(repository); var result = service.GetCountByRegion(Region.Sofia); Assert.Equal(0, result); }
public void GetSumAllSeensTest() { var repository = ArticleRepository.Create(); var article = this.CreateArticle(repository, SeedArticle.Create()); var secondArticle = this.CreateArticle(repository, SeedArticle.CreateSecondArticle()); var service = this.GetArticlesService(repository); var result = service.GetSumAllSeens(); Assert.Equal(3, result); }
public void GetAllByAtuthorIdDeletedNoMatchesTest() { var repository = ArticleRepository.Create(); var article = this.CreateArticle(repository, SeedArticle.Create()); var secondArticle = this.CreateArticle(repository, SeedArticle.CreateSecondArticle()); var service = this.GetArticlesService(repository); var result = service.GetAllByAtuthorIdDeleted <ArticleDumyModel>(article.AuthorId); Assert.Empty(result); }
public void GetLatesByCreatedTwoMatchesOnTest() { var repository = ArticleRepository.Create(); var article = this.CreateArticle(repository, SeedArticle.Create()); var secondArticle = this.CreateArticle(repository, SeedArticle.CreateSecondArticle()); var service = this.GetArticlesService(repository); var result = service.GetLatesByCreatedOn <ArticleDumyModel>(); Assert.Equal(2, result.Count()); }
public void DeleteByIdTest() { var repository = ArticleRepository.Create(); var article = this.CreateArticle(repository, SeedArticle.Create()); var secondArticle = this.CreateArticle(repository, SeedArticle.CreateSecondArticle()); var service = this.GetArticlesService(repository); service.DeleteById(article.Id).GetAwaiter(); Assert.Equal(1, repository.All().Count()); }
public void GetCountOfLocalArticlesOneMatchTest() { var repository = ArticleRepository.Create(); var article = this.CreateArticle(repository, SeedArticle.Create()); var articleWithRegion = this.CreateArticle(repository, SeedArticle.CreateSecondArticle()); var service = this.GetArticlesService(repository); var result = service.GetCountOfLocalArticles(); Assert.Equal(1, result); }
public void GetLatestByRegionOneMatchTest() { var region = Region.Burgas; var repository = ArticleRepository.Create(); var article = this.CreateArticle(repository, SeedArticle.Create()); var secondArticle = this.CreateArticle(repository, SeedArticle.CreateSecondArticle()); var service = this.GetArticlesService(repository); var result = service.GetLatestByRegion <ArticleDumyModel>(region); Assert.Single(result); }
public void GetLatestByRegionNoMatcheshTest() { var region = Region.Sofia_District; var repository = ArticleRepository.Create(); var article = this.CreateArticle(repository, SeedArticle.Create()); var secondArticle = this.CreateArticle(repository, SeedArticle.CreateSecondArticle()); var service = this.GetArticlesService(repository); var result = service.GetLatestByRegion <ArticleDumyModel>(region); Assert.Empty(result); }
public void GetLatesInternationalArticlesTwoMatchesTest() { var repository = ArticleRepository.Create(); var article = this.CreateArticle(repository, SeedArticle.Create()); var secondArticle = this.CreateArticle(repository, SeedArticle.CreateSecondArticle()); var thirdArticle = this.CreateArticle(repository, SeedArticle.CreateThirdArticle()); var service = this.GetArticlesService(repository); var result = service.GetLatesInternationalArticles <ArticleDumyModel>(); Assert.Equal(2, result.Count()); }
public void AddToSeenCountTest() { var repository = ArticleRepository.Create(); var article = this.CreateArticle(repository, SeedArticle.Create()); var service = this.GetArticlesService(repository); var seenCount = article.SeenCount; service.AddToSeenCount(article.Id).GetAwaiter().GetResult(); Assert.Equal(seenCount + 1, article.SeenCount); }
public void GetLastByCreatedOnTest() { var repository = ArticleRepository.Create(); var article = this.CreateArticle(repository, SeedArticle.Create()); var secondArticle = this.CreateArticle(repository, SeedArticle.CreateSecondArticle()); var thirdArticle = this.CreateArticle(repository, SeedArticle.CreateThirdArticle()); var service = this.GetArticlesService(repository); var result = service.GetLastByCreatedOn <ArticleDumyModel>().GetAwaiter().GetResult(); Assert.Equal(thirdArticle.Id, result.Id); }
public void GetLatesMostCommentedTest() { var repository = ArticleRepository.Create(); var article = this.CreateArticle(repository, SeedArticle.Create()); var secondArticle = this.CreateArticle(repository, SeedArticle.CreateSecondArticle()); var thirdArticle = this.CreateArticle(repository, SeedArticle.CreateThirdArticle()); var service = this.GetArticlesService(repository); var result = service.GetLatesMostCommented <ArticleDumyModel>(); Assert.Empty(result); }
public void GetLatesLocalArticlesOneMatchTest() { var repository = ArticleRepository.Create(); var article = this.CreateArticle(repository, SeedArticle.Create()); var secondArticle = this.CreateArticle(repository, SeedArticle.CreateSecondArticle()); var thirdArticle = this.CreateArticle(repository, SeedArticle.CreateThirdArticle()); var service = this.GetArticlesService(repository); var result = service.GetLatesLocalArticles <ArticleDumyModel>(); Assert.Single(result); }