public ArticlesCategoryViewModel GetArticleCategory(int id) { var category = this.DbContext .ArticleCategories .Include(x => x.Articles) .FirstOrDefault(x => x.Id == id); if (category == null) { return(null); } List <ArticleConciseViewModel> articles = this.Mapper.Map <ICollection <ArticleConciseViewModel> >(category.Articles).ToList(); articles.ForEach(x => x.Title = Html_String_Utility.DecodeThisPropertyForMe(x.Title)); articles.ForEach(x => x.PhotoURL = Html_String_Utility.DecodeThisPropertyForMe(x.PhotoURL)); var categoryModel = new ArticlesCategoryViewModel() { CategoryName = category.CategoryName, Articles = articles }; categoryModel.CategoryName = Html_String_Utility.DecodeThisPropertyForMe(categoryModel.CategoryName); return(categoryModel); }
public void DecodeForbiddenSymbols_ShouldWorkCorrectly() { string inputForbidden = TestConstants.Helpers.ForbiddenSymbolsExpectedOutput; string resultString = Html_String_Utility.DecodeThisPropertyForMe(inputForbidden); Assert.AreEqual(resultString, TestConstants.Helpers.ForbiddenSymbolsInput); }
public ICollection <ArticleConciseViewModel> GetAllArticles() { var articles = this.DbContext .Articles .Select(x => this.Mapper.Map <ArticleConciseViewModel>(x)) .ToList(); articles.ForEach(x => x.Title = Html_String_Utility.DecodeThisPropertyForMe(x.Title)); articles.ForEach(x => x.PhotoURL = Html_String_Utility.DecodeThisPropertyForMe(x.PhotoURL)); return(articles); }
public ICollection <MemeConciseViewModel> GetAllMemes() { var memes = this.DbContext .Memes .Select(this.Mapper.Map <MemeConciseViewModel>) .ToList(); memes.ForEach(x => x.Title = Html_String_Utility.DecodeThisPropertyForMe(x.Title)); memes.ForEach(x => x.PhotoURL = Html_String_Utility.DecodeThisPropertyForMe(x.PhotoURL)); return(memes); }
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); }
public MemeDetailsViewModel GetMeme(int id) { var actualMeme = this.DbContext .Memes .Include(x => x.AddedToFavoritesBy) .FirstOrDefault(x => x.Id == id); if (actualMeme == null) { return(null); } var meme = this.Mapper.Map <MemeDetailsViewModel>(actualMeme); meme.Title = Html_String_Utility.DecodeThisPropertyForMe(meme.Title); meme.PhotoURL = Html_String_Utility.DecodeThisPropertyForMe(meme.PhotoURL); return(meme); }
public JokeDetailsViewModel GetJoke(int id) { var actualJoke = this.DbContext .Jokes .Include(x => x.AddedToFavoritesBy) .FirstOrDefault(x => x.Id == id); if (actualJoke == null) { return(null); } var joke = this.Mapper.Map <JokeDetailsViewModel>(actualJoke); joke.Title = Html_String_Utility.DecodeThisPropertyForMe(joke.Title); joke.PhotoURL = Html_String_Utility.DecodeThisPropertyForMe(joke.PhotoURL); joke.Content = Html_String_Utility.DecodeThisPropertyForMe(joke.Content); return(joke); }
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); }
public ArticleDetailsViewModel GetArticle(int id) { var actualArticle = this.DbContext .Articles .Include(x => x.ArticleCategory) .Include(x => x.AddedToFavoritesBy) .FirstOrDefault(x => x.Id == id); if (actualArticle == null) { return(null); } var article = this.Mapper.Map <ArticleDetailsViewModel>(actualArticle); article.Content = Html_String_Utility.DecodeThisPropertyForMe(actualArticle.Content); article.HighLightVideoURL = Html_String_Utility.DecodeThisPropertyForMe(actualArticle.HighLightVideoURL); article.PhotoURL = Html_String_Utility.DecodeThisPropertyForMe(actualArticle.PhotoURL); article.Title = Html_String_Utility.DecodeThisPropertyForMe(actualArticle.Title); return(article); }
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); }
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); }
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); }