public RawArticleViewModel GetRawNewsDetails(int id)
        {
            RawArticle          articleFromDb   = dbContext.RawArticles.Find(id);
            RawArticleViewModel articleToReturn = mapper.Map <RawArticleViewModel>(articleFromDb);

            return(articleToReturn);
        }
        public async Task <Article> Create(RawArticle data)
        {
            var foundArticle = await _articles.FindAsync(a => a.Title == data.Title);

            if (await foundArticle.FirstOrDefaultAsync() != null)
            {
                return(null);
            }

            var(title, description, content, authorName, photo, category,
                site, tagNames, timePublished, url) = data;

            var article = new Article(title, description, content, url, photo, category, timePublished);
            await _articles.InsertOneAsync(article);

            var tags = await _tagService.Create(tagNames, article.Id);

            var author = await _authorService.Create(authorName, site, article.Id);

            article.TagsIds  = tags;
            article.AuthorId = author?.Id;

            await Update(article.Id, article);

            return(article);
        }
        public int?MakeRawArticleDraft(int articleId, string userId)
        {
            RawArticle rawArticle = dbContext.RawArticles.Find(articleId);

            if (rawArticle == null)
            {
                return(null);
            }
            Article newArticle = mapper.Map <Article>(rawArticle);

            newArticle.TempArticleId = rawArticle.Id;
            newArticle.Id            = 0;
            newArticle.CreationDate  = DateTime.UtcNow;
            newArticle.CreatorId     = userId;
            newArticle.State         = Data.Enums.ArticleState.Draft;
            dbContext.Articles.Add(newArticle);
            rawArticle.IsDeleted = true;
            dbContext.SaveChanges();

            ArticleSeoData articleToEditSeoData = new ArticleSeoData()
            {
                ArticleId = newArticle.Id, MetaDescription = rawArticle.Title, MetaKeyword = rawArticle.Title.Replace(" ", " ,"), MetaTitle = rawArticle.Title, SeoUrl = rawArticle.Title.Replace(" ", "-")
            };

            dbContext.ArticlesSeoData.Add(articleToEditSeoData);
            dbContext.SaveChanges();
            return(newArticle.Id);
        }
        public void Map_NullRawArticlePassed_Throws()
        {
            RawArticleToArticleMapper mapper = CreateMapper();
            RawArticle nullRawArticle        = null;

            var exception = Assert.Catch <ArgumentNullException>(
                () => mapper.Map(nullRawArticle));
        }
        public void Map_ValidRawArticleSelPassed_ReturnsSEL()
        {
            RawArticleToArticleMapper mapper = CreateMapper();
            RawArticle rawArticle            = CreateValidRawArticleSEL();

            Article article = mapper.Map(rawArticle);

            Assert.IsInstanceOf <Sel>(article);
        }
        public void Map_ValidRawArticleEpiPassed_ReturnsEPI()
        {
            RawArticleToArticleMapper mapper = CreateMapper();
            RawArticle rawArticle            = CreateValidRawArticleEPI();

            Article article = mapper.Map(rawArticle);

            Assert.IsInstanceOf <Epi>(article);
        }
        public void Map_ValidRawArticleBanalisePassed_ReturnsBanalise()
        {
            RawArticleToArticleMapper mapper = CreateMapper();
            RawArticle rawArticle            = CreateValidRawArticleBanalise();

            Article article = mapper.Map(rawArticle);

            Assert.IsInstanceOf <Banalise>(article);
        }
        public async Task <ActionResult <Article> > Create(RawArticle article)
        {
            if (await _articleService.TitleExists(article.Title))
            {
                return(Conflict());
            }

            var newArticle = await _articleService.Create(article);

            return(CreatedAtRoute("GetArticle", new { id = newArticle.Id }, newArticle));
        }
        private RawArticle CreateValidRawArticleSEL()
        {
            var validRawArticleSEL = new RawArticle()
            {
                Ref          = "I0000000",
                Libelle      = "Libelle",
                Localisation = "Localisation",
                IdMagasin    = articlesSettings.IdMagasinSEL
            };

            return(validRawArticleSEL);
        }
        private RawArticle CreateValidRawArticleBanalise()
        {
            var validRawArticleBanalise = new RawArticle()
            {
                Ref          = "N0000000",
                Libelle      = "Libelle",
                Localisation = "Localisation",
                IdMagasin    = articlesSettings.IdMagasinBanalise
            };

            return(validRawArticleBanalise);
        }
        private RawArticle CreateValidRawArticleEPI()
        {
            var validRawArticleEPI = new RawArticle()
            {
                Ref          = "N0000000",
                Libelle      = "Libelle",
                Localisation = "Localisation",
                IdMagasin    = articlesSettings.IdMagasinBanalise,
                TypeEpi      = new TypeEpi("TypeEPI")
            };

            return(validRawArticleEPI);
        }
Beispiel #12
0
        public void Map_CorrectRecordPassed_ReturnsCorrectRawArticle()
        {
            // Arrange
            var record = new Record(
                new List <string>
            {
                "Ref",
                "Libelle",
                "Division",
                "10",
                "Localisation",
                "10",
                "Flu",
                "Infos",
                "X",
                "Casque"
            }
                );

            RawArticle expectedArticle = new RawArticle
            {
                Ref                  = "REF",
                Libelle              = "Libelle",
                Localisation         = "Localisation",
                Quantite             = 10,
                IdMagasin            = 10,
                LienFlu              = "Flu",
                InfosSupplementaires = "Infos",
                TypeEpi              = new TypeEpi("Casque")
            };

            var mapper = CreateMapper();

            // Act
            RawArticle actualArticle = mapper.Map(record);


            // Assert
            Assert.AreEqual(expectedArticle, actualArticle);
        }