Пример #1
0
        public void EncodeForbiddenSymbols_ShouldWorkCorrectly()
        {
            string inputForbidden = TestConstants.Helpers.ForbiddenSymbolsInput;

            string resultString = Html_String_Utility.EncodeThisPropertyForMe(inputForbidden);

            Assert.AreEqual(resultString, TestConstants.Helpers.ForbiddenSymbolsExpectedOutput);
        }
Пример #2
0
        public async Task <int> AddArticleAsync(AddArticleBindingModel model)
        {
            var checkForDuplicate = this.DbContext
                                    .Articles
                                    .FirstOrDefault(x => x.Title == model.Title);

            if (checkForDuplicate != null)
            {
                return(ErrorId);
            }

            model.Content           = Html_String_Utility.EncodeThisPropertyForMe(model.Content);
            model.HighLightVideoURL = Html_String_Utility.EncodeThisPropertyForMe(model.HighLightVideoURL);
            model.PhotoURL          = Html_String_Utility.EncodeThisPropertyForMe(model.PhotoURL);
            model.Title             = Html_String_Utility.EncodeThisPropertyForMe(model.Title);

            var article = this.Mapper.Map <Article>(model);

            var articleCategory = this.DbContext
                                  .ArticleCategories
                                  .FirstOrDefault(x => x.CategoryName == model.ArticleCategoryName);

            if (articleCategory == null)
            {
                articleCategory = new ArticleCategory()
                {
                    CategoryName = model.ArticleCategoryName
                };
                await this.DbContext.ArticleCategories.AddAsync(articleCategory);

                await this.DbContext.SaveChangesAsync();
            }
            article.ArticleCategoryId = articleCategory.Id;

            if (article.HighLightVideoURL.Contains(CommonConstants.OriginalVideoUrlPart))
            {
                article.HighLightVideoURL = ModifyVideoURL_Embeded.ModifyEmbed(article.HighLightVideoURL);
            }

            await this.DbContext.Articles.AddAsync(article);

            await this.DbContext.SaveChangesAsync();

            return(article.Id);
        }
Пример #3
0
        public async Task <int> EditMemeAsync(EditMemeBindingModel model)
        {
            var meme = this.DbContext
                       .Memes
                       .FirstOrDefault(x => x.Id == model.Id);

            if (meme == null)
            {
                return(ErrorId);
            }

            meme.Title    = model.Title;
            meme.PhotoURL = model.PhotoURL;

            meme.Title    = Html_String_Utility.EncodeThisPropertyForMe(meme.Title);
            meme.PhotoURL = Html_String_Utility.EncodeThisPropertyForMe(meme.PhotoURL);

            await this.DbContext.SaveChangesAsync();

            return(meme.Id);
        }
Пример #4
0
        public async Task <int> AddMemeAsync(AddMemeBindingModel model)
        {
            var checkForDuplicate = this.DbContext
                                    .Memes
                                    .FirstOrDefault(x => x.Title == model.Title);

            if (checkForDuplicate != null)
            {
                return(ErrorId);
            }

            var meme = this.Mapper.Map <Meme>(model);

            meme.Title    = Html_String_Utility.EncodeThisPropertyForMe(meme.Title);
            meme.PhotoURL = Html_String_Utility.EncodeThisPropertyForMe(meme.PhotoURL);

            await this.DbContext.Memes.AddAsync(meme);

            await this.DbContext.SaveChangesAsync();

            return(meme.Id);
        }
Пример #5
0
        public async Task <int> EditArticleAsync(EditArticleBindingModel model)
        {
            var article = this.DbContext
                          .Articles
                          .FirstOrDefault(x => x.Id == model.Id);

            if (article == null)
            {
                return(ErrorId);
            }

            model.Content           = Html_String_Utility.EncodeThisPropertyForMe(model.Content);
            model.HighLightVideoURL = Html_String_Utility.EncodeThisPropertyForMe(model.HighLightVideoURL);
            model.PhotoURL          = Html_String_Utility.EncodeThisPropertyForMe(model.PhotoURL);

            article.Content           = model.Content;
            article.PhotoURL          = model.PhotoURL;
            article.HighLightVideoURL = model.HighLightVideoURL;

            await this.DbContext.SaveChangesAsync();

            return(article.Id);
        }
Пример #6
0
        public async Task <int> EditJokeAsync(EditJokeBindingModel model)
        {
            var joke = this.DbContext
                       .Jokes
                       .FirstOrDefault(x => x.Id == model.Id);

            if (joke == null)
            {
                return(ErrorId);
            }

            joke.Title    = model.Title;
            joke.Content  = model.Content;
            joke.PhotoURL = model.PhotoURL;

            joke.Title    = Html_String_Utility.EncodeThisPropertyForMe(joke.Title);
            joke.PhotoURL = Html_String_Utility.EncodeThisPropertyForMe(joke.PhotoURL);
            joke.Content  = Html_String_Utility.EncodeThisPropertyForMe(joke.Content);

            await this.DbContext.SaveChangesAsync();

            return(joke.Id);
        }