예제 #1
0
        public void CreateArticle(ArticleViewModel value)
        {
            int insertedArticleId = _articleRepository.Create(value);
            var authorIds         = value.Authors.Select(a => a.AuthorId).ToList();

            _authorArticleRepository.AddArticleAuthors(authorIds, insertedArticleId);
        }
예제 #2
0
        public object Create(ArticleDto articleDto)
        {
            Article create = _articleMapper.Map(articleDto);

            _articleRepository.Create(create);
            return(_articleMapper.Map(create));
        }
예제 #3
0
        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));
        }
예제 #4
0
        public ResponseMessage Create(Article entity)
        {
            ResponseMessage response = new ResponseMessage();

            _repository.Create(entity);

            return(response);
        }
예제 #5
0
        public void Create(ArticleViewModel articleViewModel)
        {
            articleViewModel.Id          = Guid.NewGuid();
            articleViewModel.Abbreviated = _authorRepository.GetAuthor(articleViewModel.AuthorId).Abbreviated;
            var article = ViewModelToDomain(articleViewModel);

            _articleRepository.Create(article);
        }
예제 #6
0
        public void ArticleExistFalseTest()
        {
            var repository = ArticleRepository.Create();
            var service    = this.GetArticlesService(repository);
            var result     = service.ArticleExist(1);

            Assert.False(result);
        }
예제 #7
0
        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);
        }
예제 #8
0
        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);
        }
예제 #9
0
        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);
        }
예제 #10
0
        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);
        }
예제 #11
0
        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);
        }
예제 #12
0
        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);
        }
예제 #13
0
        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);
        }
예제 #14
0
        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);
        }
예제 #15
0
        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);
        }
예제 #16
0
        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);
        }
예제 #17
0
        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);
        }
예제 #18
0
        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);
        }
예제 #19
0
        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);
        }
예제 #20
0
        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);
        }
예제 #21
0
        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());
        }
예제 #22
0
        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());
        }
예제 #23
0
        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);
        }
예제 #24
0
        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);
        }
예제 #25
0
        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);
        }
예제 #26
0
        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());
        }
예제 #27
0
        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);
        }
예제 #28
0
        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);
        }
예제 #29
0
        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);
        }
예제 #30
0
        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);
        }