public virtual ActionResult PostsSeries(string sectionTitle) { ViewBag.SectionTitle = sectionTitle; var series = RavenSession.Query <Posts_Series.Result, Posts_Series>() .Where(x => x.Count > 1) .OrderByDescending(x => x.MaxDate) .Take(5) .ToList(); var vm = series.Select(result => new RecentSeriesViewModel { SeriesId = result.SerieId, SeriesSlug = SlugConverter.TitleToSlug(result.Series), SeriesTitle = TitleConverter.ToSeriesTitle(result.Posts.First().Title), PostsCount = result.Count, PostInformation = result.Posts .OrderByDescending(post => post.PublishAt) .FirstOrDefault(post => post.PublishAt <= DateTimeOffset.Now) }) .Where(x => x.PostInformation != null) .ToList(); return(View(vm)); }
private SeriesInfo GetSeriesInfo(string title) { SeriesInfo seriesInfo = null; string seriesTitle = TitleConverter.ToSeriesTitle(title); if (!string.IsNullOrEmpty(seriesTitle)) { var series = RavenSession.Query <Posts_Series.Result, Posts_Series>() .Where(x => x.Series.StartsWith(seriesTitle) && x.Count > 1) .OrderByDescending(x => x.MaxDate) .FirstOrDefault(); if (series == null) { return(null); } var postsInSeries = GetPostsForCurrentSeries(series); seriesInfo = new SeriesInfo { SeriesId = series.SerieId, SeriesTitle = seriesTitle, PostsInSeries = postsInSeries }; } return(seriesInfo); }
public async Task <IActionResult> EditArticle(ArticleEditViewModel model, IFormFile pic) { var article = _articleService.GetById(model.Id); if (ModelState.IsValid) { var titleConv = new TitleConverter(); var urlConv = new UrlConverter(); if (pic != null) { var extension = Path.GetExtension(pic.FileName); var name = urlConv.StringReplace(model.Title) + extension; var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/img/article-cover/" + name); using var stream = new FileStream(path, FileMode.Create); await pic.CopyToAsync(stream); model.Picture = name; article.Picture = model.Picture; } article.Title = titleConv.TitleToPascalCase(model.Title); article.Content = model.Content.Replace(" ", " "); article.Url = urlConv.StringReplace(model.Title); article.CategoryId = model.CategoryId; _articleService.Update(article); return(RedirectToAction("Index", "Article", new { area = "Admin" })); } return(View(model)); }
public void TitleConverter_Empty() { var src = new TitleConverter(); var type = typeof(string); var ci = CultureInfo.CurrentCulture; var dest = src.Convert(new object[0], type, null, ci) as string; Assert.That(dest, Is.EqualTo("CubePDF Utility")); }
public string TitleConverter(string src, bool modified) { var fi = src.HasValue() ? IO.Get(src) : null; var args = new object[] { fi, modified }; var type = typeof(string); var ci = CultureInfo.CurrentCulture; var dest = new TitleConverter(); Assert.That(dest.ProvideValue(null), Is.EqualTo(dest)); return(dest.Convert(args, type, null, ci) as string); }
public void ConvertTest() { var converter = new TitleConverter(); Assert.AreEqual("App Title", converter.Convert(new[] { "App Title", null }, null, null, CultureInfo.InvariantCulture)); Assert.AreEqual("Document1.rtf - App Title", converter.Convert(new[] { "App Title", "Document1.rtf" }, null, null, CultureInfo.InvariantCulture)); Assert.AreEqual(DependencyProperty.UnsetValue, converter.Convert(null, null, null, null)); Assert.AreEqual(DependencyProperty.UnsetValue, converter.Convert(new[] { "Wrong" }, null, null, null)); Assert.AreEqual(DependencyProperty.UnsetValue, converter.Convert(new object[] { 4, 2 }, null, null, null)); AssertHelper.ExpectedException <NotSupportedException>(() => converter.ConvertBack(null, null, null, null)); }
public IActionResult EditCategory(CategoryEditViewModel model) { if (ModelState.IsValid) { var convertor = new UrlConverter(); var titleConvertor = new TitleConverter(); var category = _categoryService.GetById(model.Id); category.Name = titleConvertor.TitleToPascalCase(model.Name); category.Url = convertor.StringReplace(model.Name); _categoryService.Update(category); return(RedirectToAction("Index", "Category", new { area = "Member" })); } return(View(model)); }
private ActionResult ListView(int count, IList <Post> posts) { ViewBag.ChangeViewStyle = true; var summaries = posts.MapTo <PostsViewModel.PostSummary>(); var serieTitles = summaries .Select(x => TitleConverter.ToSeriesTitle(x.Title)) .Where(x => string.IsNullOrEmpty(x) == false) .Distinct() .ToList(); var series = RavenSession .Query <Posts_Series.Result, Posts_Series>() .Where(x => x.Series.In(serieTitles) && x.Count > 1) .ToList(); foreach (var post in posts) { var postSummary = summaries.First(x => x.Id == RavenIdResolver.Resolve(post.Id)); postSummary.IsSerie = series.Any(x => string.Equals(x.Series, TitleConverter.ToSeriesTitle(postSummary.Title), StringComparison.OrdinalIgnoreCase)); if (string.IsNullOrWhiteSpace(post.AuthorId)) { continue; } var author = RavenSession.Load <User>(post.AuthorId); if (author == null) { continue; } postSummary.Author = author.MapTo <PostsViewModel.PostSummary.UserDetails>(); } return(View("List", new PostsViewModel { PageSize = BlogConfig.PostsOnPage, CurrentPage = CurrentPage, PostsCount = count, Posts = summaries })); }
private IList <PostInSeries> GetPostsForCurrentSeries(Posts_Series.Result series) { IList <PostInSeries> postsInSeries = null; if (series != null) { postsInSeries = series .Posts .Select(s => new PostInSeries { Id = RavenIdResolver.Resolve(s.Id), Slug = SlugConverter.TitleToSlug(s.Title), Title = HttpUtility.HtmlDecode(TitleConverter.ToPostTitle(s.Title)), PublishAt = s.PublishAt }) .OrderByDescending(p => p.PublishAt) .ToList(); } return(postsInSeries); }
public IActionResult AddCategory(CategoryAddViewModel model) { if (ModelState.IsValid) { var urlConvertor = new UrlConverter(); var titleConverter = new TitleConverter(); var category = new Category() { Name = titleConverter.TitleToPascalCase(model.Name), Url = urlConvertor.StringReplace(model.Name.ToLower()) }; if (_context.Categories.Any(x => x.Name == model.Name)) { ViewBag.CategoryExsit = titleConverter.TitleToPascalCase(model.Name); return(View(model)); } _categoryService.Create(category); return(RedirectToAction("Index", "Category", new { area = "Member" })); } return(View(model)); }
public async Task <IActionResult> AddArticle(ArticleAddViewModel model, IFormFile pic) { if (ModelState.IsValid) { var titleConv = new TitleConverter(); var urlConv = new UrlConverter(); if (pic != null) { var extension = Path.GetExtension(pic.FileName); var name = urlConv.StringReplace(model.Title) + extension; var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/img/article-cover/" + name); using var stream = new FileStream(path, FileMode.Create); await pic.CopyToAsync(stream); model.Picture = name; } var article = new Article() { Title = titleConv.TitleToPascalCase(model.Title), Content = model.Content.Replace(" ", " "), CategoryId = model.CategoryId, Url = urlConv.StringReplace(model.Title), Picture = model.Picture }; if (_context.Articles.Any(x => x.Title == model.Title)) { ViewBag.TitleExist = titleConv.TitleToPascalCase(model.Title); return(View(model)); } _articleService.Create(article); return(RedirectToAction("Index", "Article", new { area = "Admin" })); } return(View(model)); }
public void TitleConverter_Throws() { var src = new TitleConverter(); Assert.That(() => src.ConvertBack(null, null, null, null), Throws.TypeOf <NotSupportedException>()); }
public void ProvideValue() { var dest = new TitleConverter(); Assert.That(dest.ProvideValue(null), Is.EqualTo(dest)); }