public BlogDetailViewModel Blog(long id) { var blogEntity = _dbContext.Blogs.FirstOrDefault(b => b.Id == id); if (blogEntity == null) { throw new BlogNotFoundException(id.ToString()); } var blog = new BlogDetailViewModel { Id = blogEntity.Id, Title = blogEntity.Title, Content = blogEntity.Content, Created = blogEntity.Created, }; blog.Comments = (from comment in _dbContext.Comments where comment.BlogId == id orderby comment.Created descending select new CommentListItemViewModel { Id = comment.Id, Content = comment.Content, Created = comment.Created, }).Take(20).ToList(); return(blog); }
public ActionResult GetBlogsByEditor(string groupId, int groupType, int currentPage) { groupType = groupType == 0?BlogGroupType.Editor.GetHashCode():groupType; var results = _blogApi.BlogByGroup(groupType, Sanitizer.GetSafeHtmlFragment(groupId), currentPage, Convert.ToInt32(ConfigKeys.PageSize)); if (results != null) { foreach (var res in results.Result.Results) { res.Days = ToDays(res.Created); } } var category = _blogApi.BlogGroups(); var result = new BlogDetailViewModel { Categories = category.Result.Categories.Where(x => x.GroupCount > 0).ToList(), BlogList = results.Result, BlogTypes = category.Result.BlogTypes }; if (results != null && results.Result.Results.Count > 0) { ViewBag.selectedGroup = results.Result.Results[0].Author.ToCamelCase(); } else { ViewBag.selectedGroup = ""; } result.PageSize = Convert.ToInt32(ConfigKeys.PageSize); SetDataLayerVariables(result, WebhookEventTypes.FacetSearch); return(View(CustomViews.BLOG_BY_EDITOR, result)); }
// GET: Comments/Details/5 public ActionResult Details(int?id) { //if (id == null) //{ // return new HttpStatusCodeResult(HttpStatusCode.BadRequest); //} //Comment comment = db.Comments.Find(id); //if (comment == null) //{ // return HttpNotFound(); //} //return View(comment); using (var uow = new UnitOfWork()) { var blog = uow.BlogRepository.Get(b => b.Id == id); var blogDetailViewModel = new BlogDetailViewModel() { AuthorName = blog.User.UserName, Body = blog.Body, CreationTime = blog.CreateTime, Id = blog.Id, Title = blog.Title, UpdateTime = blog.UpdateTime, CategoryName = blog.Category.CategoryName }; List <CommentViewModel> commentList = blog.Comments.Select(comment => new CommentViewModel { PosterName = comment.User.UserName, Message = comment.Body, CreationTime = comment.CreateTime }).ToList(); ViewData["Comments"] = commentList; return(View(blogDetailViewModel)); } }
public ActionResult GetAllBlogsByEditor(string slug, int currentpage = 1) { var results = _blogApi.BlogByGroup(BlogGroupType.Editor.GetHashCode(), slug, currentpage, Convert.ToInt32(ConfigKeys.PageSize)); if (results == null && results.StatusCode == HttpStatusCode.NotFound) { return(RedirectToAction("pagenotfound", "common")); } if (results != null) { foreach (var res in results.Result.Results) { res.Days = ToDays(res.Created); } } var category = _blogApi.BlogGroups(); var result = new BlogDetailViewModel { Categories = category.Result.Categories.Where(x => x.GroupCount > 0).ToList(), BlogList = results.Result, BlogTypes = category.Result.BlogTypes }; if (results != null && results.Result.Results.Count > 0) { ViewBag.selectedGroup = results.Result.Results[0].Author.ToCamelCase(); } else { ViewBag.selectedGroup = ""; } result.PageSize = Convert.ToInt32(ConfigKeys.PageSize); SetDataLayerVariables(result, WebhookEventTypes.FacetSearch); return(View(CustomViews.BLOG_BY_EDITOR, result)); }
public async Task <IActionResult> Detail(string slug) { var blog = await unitOfWork.Blogs.GetBlogAsync(slug); if (blog == null) { return(NotFound()); } ; var pageDescription = blog.Description.GetFirstParagraphTextFromHtml(); if (string.IsNullOrEmpty(pageDescription)) { pageDescription = "Bring your coffee and enjoy reading in-depth articles about programming."; } var blogDetailVM = new BlogDetailViewModel { Blog = blog, DisqusViewModel = new DisqusViewModel { PageTitle = blog.Title }, PageDescription = pageDescription }; return(View(blogDetailVM)); }
public ActionResult Details(string groupUrlParam, string blogUrlParam) { BlogGroup blogGroup = db.BlogGroups.Where(current => current.UrlParam == groupUrlParam && current.IsDeleted == false && current.IsActive == true).FirstOrDefault(); if (blogGroup == null) { return(HttpNotFound()); } Blog blog = db.Blogs.Where(current => current.UrlParam == blogUrlParam && current.IsActive == true && current.IsDeleted == false).FirstOrDefault(); if (blog == null) { return(HttpNotFound()); } BlogDetailViewModel blogDetailViewModel = new BlogDetailViewModel() { BlogGroup = blogGroup, Blog = blog, Categories = db.BlogGroups.Where(current => current.Id != blogGroup.Id && current.IsActive == true && current.IsDeleted == false).ToList(), RecentBlogs = db.Blogs.Where(current => current.Id != blog.Id && current.IsActive == true && current.IsDeleted == false).OrderByDescending(current => current.CreationDate).Take(5).ToList(), RelatedBlogs = db.Blogs.Where(current => current.BlogGroupId == blogGroup.Id && current.Id != blog.Id && current.IsActive == true && current.IsDeleted == false).Take(2).ToList(), BlogComments = db.BlogComments.Where(current => current.BlogId == blog.Id && current.IsActive == true && current.IsDeleted == false).ToList() }; return(View(blogDetailViewModel)); }
public ActionResult GetBlogsbyCategory(string id, int currentPage) { var resp = _blogApi.BlogByGroup(BlogGroupType.Category.GetHashCode(), Sanitizer.GetSafeHtmlFragment(id), currentPage, Convert.ToInt32(ConfigKeys.PageSize)); if (resp != null) { foreach (var res in resp.Result.Results) { res.Days = ToDays(res.Created); } } var category = _blogApi.BlogGroups(); var result = new BlogDetailViewModel { Categories = category.Result.Categories.Where(x => x.GroupCount > 0).ToList(), BlogList = resp.Result, BlogTypes = category.Result.BlogTypes }; if (resp != null && resp.Result.Results.Count > 0) { ViewBag.selectedGroup = resp.Result.Results[0].Category.ToCamelCase(); } else { ViewBag.selectedGroup = ""; } result.PageSize = Convert.ToInt32(ConfigKeys.PageSize); SetDataLayerVariables(result, WebhookEventTypes.BlogViewed); return(View(CustomViews.BLOG_CATEGORY, result)); }
// GET: Blog/Details/5 public ActionResult Details(int id) { using (var uow = new UnitOfWork()) { var blog = uow.BlogRepository.Get(b => b.Id == id); var blogDetailViewModel = new BlogDetailViewModel { AuthorName = blog.User.UserName, Body = blog.Body, CreationTime = blog.CreationTime, Id = blog.Id, Title = blog.Title, UpdateTime = blog.UpdateTime, CategoryName = blog.Category.CategoryName }; List <CommentViewModel> commentList = blog.Comments.Select(comment => new CommentViewModel { PosterName = comment.User.UserName, Message = comment.Body, CreationTime = comment.CreationTime, Id = comment.Id }).ToList(); ViewData["Comments"] = commentList; return(View(blogDetailViewModel)); } }
public IActionResult Details(Guid id) { var model = new BlogDetailViewModel(); model.Blog = _blogService.GetById(id); model.MostBlogs = _blogService.GetLastest(6); return View(model); }
/// <summary> /// 在此页将要在 Frame 中显示时进行调用。 /// </summary> /// <param name="e">描述如何访问此页的事件数据。 /// 此参数通常用于配置页。</param> protected override void OnNavigatedTo(NavigationEventArgs e) { var param = e.Parameter; ViewModel = new BlogDetailViewModel(param.ToString()); Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed; }
public BlogDetailViewModel GetBlogDetail(int?id) { var blogId = id.Value; var blog = _blogService.GetBlogById(blogId); var model = new BlogDetailViewModel { Blog = blog }; return(model); }
public IActionResult Detail(int id) { var posts = JsonConvert.DeserializeObject <List <Blog> >(PostsString); var post = posts.SingleOrDefault(x => x.Id == id); if (post == null) { return(RedirectToAction("Error")); } var model = new BlogDetailViewModel(post); return(View(model)); }
public ActionResult Details(string groupUrlParam, string urlParam) { Blog blog = db.Blogs.FirstOrDefault(current => current.UrlParam == urlParam && current.IsDeleted == false && current.IsActive); if (blog == null) { Response.StatusCode = 404; return(RedirectToAction("AccessDenied", "Home")); } if (blog.BlogGroup.UrlParam == groupUrlParam) { blog.Visit = blog.Visit + 1; db.SaveChanges(); BlogDetailViewModel blogDetail = new BlogDetailViewModel() { MenuProductGroups = baseViewModel.GetMenu(), MenuServiceGroups = baseViewModel.GetMenuServices() }; blogDetail.Blog = blog; blogDetail.BlogComments = db.BlogComments .Where(current => current.BlogId == blog.Id && current.IsActive && !current.IsDeleted).ToList(); blogDetail.BlogGroups = db.BlogGroups.Where(current => current.IsActive && !current.IsDeleted).ToList(); blogDetail.RecentBlogs = db.Blogs .Where(current => current.Id != blog.Id && current.IsActive && !current.IsDeleted) .OrderByDescending(current => current.CreationDate).Take(6).ToList(); blogDetail.RelatedBlogs = db.Blogs .Where(current => current.Id != blog.Id && current.IsActive && !current.IsDeleted && current.BlogGroupId == blog.BlogGroupId) .OrderByDescending(current => current.CreationDate).Take(3).ToList(); blogDetail.FooterRecentBlog = baseViewModel.GetFooterRecentBlog(); ViewBag.Title = blog.Title; ViewBag.Description = blog.Summery; ViewBag.Canonical = "https://kamransehat.ir/blog/" + blog.BlogGroup.UrlParam + "/" + blog.UrlParam; return(View(blogDetail)); } return(RedirectPermanent("/blog/" + blog.BlogGroup.UrlParam + "/" + urlParam)); }
public ActionResult BlogDetail(int postID) { var blogDetailVM = new BlogDetailViewModel(); var ops = new FITlosophiOperations(); blogDetailVM.UserSelectedPost = ops.GetPostByID(postID); blogDetailVM.Categories = ops.GetAllCategories(); var readMorePosts = ops.GetPostsByAmount(10); blogDetailVM.Posts = readMorePosts.Where(p => p.PostID != postID).ToList(); return(View(blogDetailVM)); }
public ActionResult Details(int id) { Blog blog = db.Blogs.FirstOrDefault(c => c.Code == id); if (blog == null) { return(HttpNotFound()); } BlogDetailViewModel blogDetail = new BlogDetailViewModel() { Blog = blog }; return(View(blogDetail)); }
public ActionResult Details(string param) { Blog blog = db.Blogs.Include(current => current.BlogGroup).Where(current => current.UrlParam == param).FirstOrDefault(); BlogDetailViewModel viewModel = new BlogDetailViewModel(); viewModel.BaseInfo = menu.ReturnMenu(); viewModel.blog = blog; viewModel.Categories = ReturnCategories(); viewModel.Recent = db.Blogs.Include(current => current.BlogComments).Where(current => current.IsDeleted == false && current.IsActive == true && current.Id != blog.Id).OrderByDescending(current => current.CreationDate).Take(3).ToList(); viewModel.Related = db.Blogs.Where(current => current.IsDeleted == false && current.IsActive == true && current.BlogGroupId == blog.BlogGroupId && current.Id != blog.Id).OrderByDescending(current => current.CreationDate).Take(3).ToList(); viewModel.Comments = db.BlogComments.Where(current => current.IsDeleted == false && current.IsActive == true && current.BlogId == blog.Id).ToList(); ViewBag.PageId = "blog-detail"; return(View(viewModel)); }
public void AddBlog(BlogDetailViewModel blogDetailViewModel) { try { var blogDetail = _mapper.Map <BlogDetail>(blogDetailViewModel); using (BlogDBContext blogDbContext = new BlogDBContext()) { blogDbContext.Add(blogDetail); blogDbContext.SaveChanges(); } } catch (Exception e) { Console.WriteLine(e); throw; } }
public ActionResult Detail(string keyUrl) { var blogModel = _blogService.GetBlogPostDetail(keyUrl); if (!blogModel.IsSuccess) { return(RedirectToAction("Index")); } var model = new BlogDetailViewModel { Blog = blogModel.Value, Products = _productService.GetRecomendProducts(4), Blogs = _blogService.GetRecentBlogs(blogModel.Value.Id) }; SetSitePageSettings(blogModel.Value.Title, blogModel.Value.SeoKeywords, blogModel.Value.SeoDescription); return(View(model)); }
public ActionResult BlogDetails() { BlogDetailViewModel blogDetailViewModel = null; try { IBlog blog = _renderingRepository.GetPageContextItem <IBlog>(); if (blog != null) { blogDetailViewModel = _blogDetailViewModelConverter.ConvertTo(blog); } } catch (Exception ex) { Sitecore.Diagnostics.Log.Error(ex.Message, ex, this); } return(View(Constants.BlogDetailsViewName, blogDetailViewModel)); }
public ActionResult Index() { ViewBag.BlogCount = BlogCount(); ViewBag.ActiveBlog = IsActiveCount(); ViewBag.ActiveHome = ActiveHomepageCount(); ViewBag.PasiveBlog = DeActiveHomepageCount(); BlogDetailViewModel blogDetailView = new BlogDetailViewModel(); List <Blog> blogs = db.Blogs.ToList(); List <Category> categories = db.Categories.ToList(); blogDetailView.Blogs = blogs; blogDetailView.Categories = categories; return(View(blogDetailView)); }
public ActionResult Details(string categoryUrlParam, string urlParam) { Blog blog = db.Blogs.Include(c => c.BlogGroup).FirstOrDefault(current => current.UrlParam == urlParam); if (blog == null) { return(RedirectPermanent("/blog")); } if (blog.BlogGroup.UrlParam != categoryUrlParam) { return(RedirectPermanent("/blog/" + blog.BlogGroup.UrlParam + "/" + urlParam)); } blog.VisitNumber = blog.VisitNumber + 1; db.SaveChanges(); BlogDetailViewModel blogDetail = new BlogDetailViewModel(); blogDetail.Menu = menu.ReturnMenuTours(); blogDetail.Footer = menu.ReturnFooter(); blogDetail.MenuBlogGroups = menu.ReturnBlogGroups(); blogDetail.Blog = blog; blogDetail.RecentBlogs = db.Blogs.Where(current => current.IsDelete == false && current.Id != blog.Id) .OrderByDescending(c => c.SubmitDate).Take(3).ToList(); blogDetail.BlogGroups = db.BlogGroups.Where(current => current.IsDelete == false).ToList(); blogDetail.Comments = ReturnComments(blog.Id); ViewBag.Title = blog.PageTitle; ViewBag.Description = blog.PageDescription; if (string.IsNullOrEmpty(blog.HeaderImageUrl)) { ViewBag.headerImg = "/Images/header1.jpg"; } else { ViewBag.headerImg = blog.HeaderImageUrl; } return(View(blogDetail)); }
public ActionResult Details(string urlParam) { Blog blog = db.Blogs.FirstOrDefault(c => c.UrlParam == urlParam && c.IsDeleted == false); if (blog == null) { return(RedirectToAction("List")); } BlogDetailViewModel result = new BlogDetailViewModel() { Blog = blog, SidebarServices = db.Services.Where(c => c.IsDeleted == false && c.IsActive).OrderBy(c => c.Order).ToList(), SidebarBlog = db.Blogs.Where(c => c.IsDeleted == false && c.Id != blog.Id && c.IsActive).OrderByDescending(c => c.CreationDate).Take(4).ToList(), BlogComments = db.BlogComments.Where(c => c.BlogId == blog.Id && c.IsActive && c.IsDeleted == false).ToList() }; return(View(result)); }
public IActionResult BlogDetail(int id) { var blog = _blogService.GetBlogDetails(id); ViewData["BodyClass"] = "single_post_page"; var blogVms = _blogService.GetAll().Where(x => x.Status == Status.Active); BlogDetailViewModel blogDetail = new BlogDetailViewModel() { Blog = blog, blogImageViewModels = _blogService.GetGalleryImage(id), LatestBlogs = blogVms.OrderByDescending(x => x.CreatedDate).Take(5).ToList(), PopularBlogs = blogVms.OrderByDescending(x => x.ViewCount).Take(5).ToList(), RelatedBlogs = blogVms.Take(5).ToList(), blogTagViewModels = _blogService.GetTagsByBlogId(id), AllTags = _blogService.GetAllTags(), }; return(View(blogDetail)); }
// GET: Blog public ActionResult Blogs() { var results = _blogApi.BlogGroups(); int pageSize = Convert.ToInt32(ConfigKeys.PageSize); var blogs = _blogApi.BlogByGroup(0, "0", 1, pageSize); foreach (var res in blogs.Result.Results) { res.Days = ToDays(res.Created); } var result = new BlogDetailViewModel { Categories = results.Result.Categories.Where(x => x.GroupCount > 0).ToList(), Editors = results.Result.Editors, BlogList = blogs.Result, BlogTypes = results.Result.BlogTypes }; return(View(CustomViews.BLOGS, result)); }
public ActionResult Details(string urlParam) { if (urlParam == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Blog blog = db.Blogs.FirstOrDefault(current => current.UrlParam == urlParam); if (blog == null) { return(HttpNotFound()); } BlogDetailViewModel viewModel = new BlogDetailViewModel(); viewModel.Blog = blog; viewModel.RecentBlogs = db.Blogs.Where(current => current.IsDeleted == false && current.IsActive == true).OrderByDescending(current => current.CreationDate).ToList(); viewModel.PopularBlogs = db.Blogs.Where(current => current.IsDeleted == false && current.IsActive == true).OrderByDescending(current => current.Visit).ToList(); viewModel.Comments = db.BlogComments.Where(current => current.IsActive == true && current.IsDeleted == false && current.BlogId == blog.Id).ToList(); return(View(viewModel)); }
public ActionResult Details(string urlParam) { if (string.IsNullOrEmpty(urlParam)) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Blog blog = db.Blogs.Where(x => x.UrlParam == urlParam && x.IsActive && !x.IsDeleted).FirstOrDefault(); if (blog == null) { return(HttpNotFound()); } BlogDetailViewModel blogDetailViewModel = new BlogDetailViewModel() { Blog = blog, BlogCategory = db.BlogCategories.Where(x => x.Id == blog.BlogCategoryId).FirstOrDefault(), BlogDetailContent = ReturnBlogDetailContent(blog) }; return(View(blogDetailViewModel)); }
public ActionResult Detail(int id) { BlogRepository blogRepository = new BlogRepository(); BlogPhotoRepository blogPhotoRepository = new BlogPhotoRepository(); BlogCommentRepository blogCommentRepository = new BlogCommentRepository(); BlogDetailViewModel blogView = new BlogDetailViewModel(); var blogresult = blogRepository.GetById(id); var blogphotoresult = blogPhotoRepository.GetByFilter(X => X.BlogId == id); var blogcommentresult = blogCommentRepository.GetByFilter(x => x.BlogId == id); blogView.Content = blogresult.Content; blogView.Star = blogresult.Star; blogView.Title = blogresult.Title; blogView.RegisterDate = blogresult.RegisterDate; blogView.UserId = blogresult.UserId; blogView.Users = blogresult.Users; blogView.blogComment = blogcommentresult; blogView.blogPhoto = blogphotoresult; return(View(blogView)); }
public ActionResult BlogDetail(string url) { var blog = _blogApi.BlogDetail(Sanitizer.GetSafeHtmlFragment(url)); if (blog.Result == null && blog.StatusCode == System.Net.HttpStatusCode.NotFound) { return(RedirectToAction("pagenotfound", "common")); } var category = _blogApi.BlogGroups(); var result = new BlogDetailViewModel { Detail = blog.Result, Categories = category.Result.Categories.Where(x => x.GroupCount > 0).ToList(), BlogTypes = category.Result.BlogTypes }; ViewBag.selectedGroup = string.IsNullOrEmpty(blog.Result.Category)?"": blog.Result.Category.ToCamelCase(); result.PageSize = Convert.ToInt32(ConfigKeys.PageSize); SetDataLayerVariables(result, WebhookEventTypes.BlogViewed); return(View(CustomViews.BLOGS_DETAIL, result)); }
public ActionResult GetAllBlogsbyCategory(string slug, int currentpage = 1) { // var slug = SiteUtils.GetSlugFromUrl(); var resp = _blogApi.BlogByGroup(BlogGroupType.Category.GetHashCode(), slug, currentpage, Convert.ToInt32(ConfigKeys.PageSize)); if (resp == null && resp.StatusCode == HttpStatusCode.NotFound) { return(RedirectToPageNotFound()); } if (resp != null) { foreach (var res in resp.Result.Results) { res.Days = ToDays(res.Created); } } var category = _blogApi.BlogGroups(); var result = new BlogDetailViewModel { Categories = category.Result.Categories.Where(x => x.GroupCount > 0).ToList(), BlogList = resp.Result, BlogTypes = category.Result.BlogTypes }; result.Slug = slug; if (resp != null && resp.Result.Results.Count > 0) { ViewBag.selectedGroup = resp.Result.Results[0].Category.ToCamelCase(); } else { ViewBag.selectedGroup = ""; } result.PageSize = Convert.ToInt32(ConfigKeys.PageSize); SetDataLayerVariables(result, WebhookEventTypes.FacetSearch); return(View(CustomViews.BLOG_CATEGORY, result)); }
public async Task <IActionResult> Index(int id) { var model = new BlogDetailViewModel(); model.Blog = await _blogService.GetById(id); model.Blog.CountComment = (await _blogComment.FindAll()).Count(x => x.BlogId == id); model.Categories = await _blogCategoryService.GetAll(); model.PopularPosts = (from k in (await _blogService.GetAll()).OrderByDescending(x => x.DateModified).ToList() select new BlogViewModel { Image = k.Image, Id = k.Id, CountComment = 4, DateModified = k.DateModified, Description = k.Description, SeoAlias = k.SeoAlias }).Take(5); model.ReLateBlogs = (from b in (await _blogService.GetAll()).Where(x => x.BlogCategoryId == model.Blog.BlogCategoryId && x.Id != id).ToList() select new BlogViewModel { Image = b.Image, Id = b.Id, CountComment = 0, // CountComment =(await _blogComment.FindAll(y => y.BlogId == b.Id)).Count(), DateModified = b.DateModified, Description = b.Description, SeoAlias = b.SeoAlias }).Take(5); model.BlogTags = (await _blogTagRepository.FindAll()).Take(10); HttpContext.Session.Set(CommonConstants.BlogId, id); model.Tags = (await _blogTagRepository.FindAll(x => x.BlogId == id)).Select(x => x.TagId).ToList(); return(View(model)); }