public ActionResult CreateEdit(long Id = 0) { NccPost post = new NccPost(); post.PublishDate = DateTime.Now; post.PostStatus = NccPost.NccPostStatus.Draft; NccPostDetails nccPostDetails = new NccPostDetails(); nccPostDetails.Language = GlobalConfig.WebSite.Language; post.PostDetails.Add(nccPostDetails); if (Id > 0) { post = _nccPostService.Get(Id); } if (GlobalConfig.WebSite.IsMultiLangual) { foreach (var item in SupportedCultures.Cultures) { var count = post.PostDetails.Where(x => x.Language == item.TwoLetterISOLanguageName).Count(); if (count <= 0) { NccPostDetails _nccPostDetails = new NccPostDetails(); _nccPostDetails.Language = item.TwoLetterISOLanguageName; post.PostDetails.Add(_nccPostDetails); } } } SetPostViewData(post); return(View(post)); }
private void SetPostViewData(NccPost post) { ViewBag.Layouts = new SelectList(GlobalConfig.ActiveTheme.Layouts, "Name", "Name", post.Layout); ViewBag.CategoryList = _nccCategoryService.LoadAll(); ViewBag.Categories = new SelectList(_nccCategoryService.LoadAll(), "Id", "Name", post.Categories); ViewBag.AllPosts = new SelectList(_nccPostService.LoadAll().Where(p => p.PostStatus == NccPost.NccPostStatus.Published && p.Id != post.Id), "Id", "Name", post.Parent != null ? post.Parent.Id : 0); var PostStatus = Enum.GetValues(typeof(NccPost.NccPostStatus)).Cast <NccPost.NccPostStatus>().Select(v => new SelectListItem { Text = v.ToString(), Value = ((int)v).ToString() }).ToList(); ViewBag.PostStatus = new SelectList(PostStatus, "Value", "Text", (int)post.PostStatus); var PostType = Enum.GetValues(typeof(NccPost.NccPostType)).Cast <NccPost.NccPostType>().Select(v => new SelectListItem { Text = v.ToString(), Value = ((int)v).ToString() }).ToList(); ViewBag.PostType = new SelectList(PostType, "Value", "Text", (int)post.PostType); ViewBag.DomainName = (Request.IsHttps == true ? "https://" : "http://") + Request.Host + "/Post/"; }
private void SetShortCodeContent(NccPost post) { foreach (var item in post.PostDetails) { item.Content = _nccShortCodeProvider.ReplaceShortContent(item.Content); } }
public static NccPostDetails GetCurrentLanguagePostDetails(NccPost post, string language, bool isRequireContentSummary = false) { if (post != null) { var postDetails = post.PostDetails.Where(x => x.Language == language).FirstOrDefault(); if (postDetails != null && isRequireContentSummary) { if (postDetails.Content?.Length > 0) { postDetails.Content = Regex.Replace(postDetails.Content, "<[^>]*>", string.Empty); } if (postDetails.Content?.Length > 0) { postDetails.Content = Regex.Replace(postDetails.Content, @"^\s*$\n", string.Empty, RegexOptions.Multiline); } if (postDetails.Content?.Length > 300) { postDetails.Content = postDetails.Content.Substring(0, 300); } } return(postDetails); } return(null); }
public static NccPost FirePostEvent(this IMediator _mediator, NccPost post, PostEvent postEvent, NccPost newPost = null, ILogger logger = null) { try { var posts = new NccPost[] { }; if (postEvent == PostEvent.Create) { posts = _mediator.SendAll(new OnPostCreated(post)).Result; } else if (postEvent == PostEvent.Edit) { posts = _mediator.SendAll(new OnPostEdited(post, newPost)).Result; } else if (postEvent == PostEvent.Show) { posts = _mediator.SendAll(new OnPostShow(post)).Result; } return(post = posts?.LastOrDefault()); } catch (Exception ex) { logger?.LogError(ex.Message, ex); } return(null); }
public ActionResult CreateEdit(NccPost post) { if (ModelState.IsValid) { var author = _nccUserService.Get(User.GetUserId()); post.Author = author; post.Status = EntityStatus.Active; _nccPostService.Save(post); TempData["SuccessMessage"] = "Post save successful"; } PreparePostCreateEditView(); return(View(post)); }
public ActionResult CreateEdit(long id = 0) { PreparePostCreateEditView(); NccPost post = new NccPost(); if (id > 0) { post = _nccPostService.Get(id); } else { post.Content = ""; post.PublishDate = DateTime.Now; post.PostStatus = NccPost.NccPostStatus.Draft; } return(View(post)); }
public bool CreatePost(int totalCount, DateTime dateFrom, DateTime dateTo) { int currentCount = _postService.LoadAll().Count(); string itemName = "Test-Post-"; string enDemoTitle = "Test Post "; string enDemoSlug = "Test-Post-"; string bnDemoTitle = "টেস্ট পোস্ট "; string bnDemoSlug = "টেস্ট-পোস্ট-"; var categoryList = _categoryService.LoadAll(); var tagList = _tagService.LoadAll(); for (int i = 1; i <= totalCount; i++) { //Declare new post NccPost post = new NccPost(); post.Metadata = "DEMODATA"; post.PublishDate = GetRandomDate(dateFrom, dateTo); post.PostStatus = NccPostStatus.Published; post.PostType = NccPostType.Public; post.Layout = "SiteLayout"; post.CreateBy = post.ModifyBy = GetRandomUserId(); post.Name = itemName + (currentCount + i).ToString(); post.AllowComment = true; //Create other languost details foreach (var item in SupportedCultures.Cultures) { var count = post.PostDetails.Where(x => x.Language == item.TwoLetterISOLanguageName).Count(); if (count <= 0) { NccPostDetails _nccPostDetails = new NccPostDetails(); _nccPostDetails.Language = item.TwoLetterISOLanguageName; if (item.TwoLetterISOLanguageName == "en") { _nccPostDetails.Title = enDemoTitle + (currentCount + i).ToString(); _nccPostDetails.Slug = enDemoSlug + (currentCount + i).ToString(); _nccPostDetails.Name = enDemoSlug + (currentCount + i).ToString(); _nccPostDetails.Content = "<h1 style=\"text-align:center\">" + enDemoTitle + (currentCount + i).ToString() + "</h1><hr />" + enDemoContent; _nccPostDetails.MetaDescription = enDemoTitle + (currentCount + i).ToString() + " " + enDemoContent; _nccPostDetails.MetaDescription = _nccPostDetails.MetaDescription.Substring(0, 160); } else if (item.TwoLetterISOLanguageName == "bn") { _nccPostDetails.Title = bnDemoTitle + (currentCount + i).ToString(); _nccPostDetails.Slug = bnDemoSlug + (currentCount + i).ToString(); _nccPostDetails.Name = bnDemoSlug + (currentCount + i).ToString(); _nccPostDetails.Content = "<h1 style=\"text-align:center\">" + bnDemoTitle + (currentCount + i).ToString() + "</h1><hr />" + bnDemoContent; _nccPostDetails.MetaDescription = bnDemoTitle + (currentCount + i).ToString() + " " + bnDemoContent; _nccPostDetails.MetaDescription = _nccPostDetails.MetaDescription.Substring(0, 160); } post.PostDetails.Add(_nccPostDetails); } } _postService.Save(post); try { post = _postService.Get(post.Id, true); //assign random number of category int catLen = (categoryList.Count - 1) > 3 ? 3 : (categoryList.Count - 1); int rndCatNumber = rnd.Next(1, catLen); post.Categories = new List <NccPostCategory>(); for (int j = 0; j < rndCatNumber; j++) { var temp = GetRandomCategory(categoryList); if (post.Categories.Where(x => x.CategoryId == temp.Id).Count() <= 0) { post.Categories.Add(new NccPostCategory() { Post = post, CategoryId = temp.Id }); } } _postService.Update(post); } catch (Exception ex) { } try { post = _postService.Get(post.Id, true); //assign random number of tag int catLen = (tagList.Count - 1) > 4 ? 4 : (tagList.Count - 1); int rndTagNumber = rnd.Next(1, catLen); post.Tags = new List <NccPostTag>(); for (int j = 0; j < rndTagNumber; j++) { var temp = GetRandomTag(tagList); if (post.Tags.Where(x => x.TagId == temp.Id).Count() <= 0) { post.Tags.Add(new NccPostTag() { Post = post, TagId = temp.Id }); } } _postService.Update(post); } catch (Exception ex) { } //ShowMessage(totalCount + " Post created successfully", Framework.Core.Mvc.Views.MessageType.Success); } return(true); }
public ActionResult CreateEdit(NccPost model, long ParentId, long[] SelecetdCategories, string SelectedTags, string SubmitType) { ViewBag.MessageType = "ErrorMessage"; ViewBag.Message = "Error occoured. Please fill up all field correctly."; if (ModelState.IsValid) { bool isSuccess = true; #region For default language var defaultPostDetails = model.PostDetails.Where(x => x.Language == GlobalConfig.WebSite.Language).FirstOrDefault(); if (defaultPostDetails == null) { isSuccess = false; ViewBag.Message = "Default language Post can't be null"; } else { //title empty validation if (string.IsNullOrEmpty(defaultPostDetails.Title)) { isSuccess = false; ViewBag.Message = "Default language Title can't be null"; } //slug empty validation if (isSuccess && string.IsNullOrEmpty(defaultPostDetails.Slug)) { isSuccess = false; ViewBag.Message = "Default language Slug can't be null"; } //slug duplicate validation if (isSuccess) { defaultPostDetails.Title = defaultPostDetails.Title.Trim(); defaultPostDetails.Slug = defaultPostDetails.Slug.Trim(); model.Name = defaultPostDetails.Slug; var temp = _nccPostDetailsService.Get(defaultPostDetails.Slug, defaultPostDetails.Language); if (temp != null && temp.Id != defaultPostDetails.Id) { isSuccess = false; ViewBag.Message = "Duplicate Slug found for language " + defaultPostDetails.Language; } } } #endregion #region Check validation for other languages List <NccPostDetails> deletedList = new List <NccPostDetails>(); foreach (var item in model.PostDetails.Where(x => x.Language != GlobalConfig.WebSite.Language).ToList()) { if (item.Id == 0 && string.IsNullOrEmpty(item.Title) && string.IsNullOrEmpty(item.Slug) && string.IsNullOrEmpty(item.Content) && string.IsNullOrEmpty(item.MetaKeyword) && string.IsNullOrEmpty(item.MetaDescription)) { deletedList.Add(item); } else { if (string.IsNullOrEmpty(item.Title)) { isSuccess = false; ViewBag.Message = "Title can't be null for language " + item.Language; } //slug empty validation if (isSuccess && string.IsNullOrEmpty(item.Slug)) { isSuccess = false; ViewBag.Message = "Slug can't be null for language " + item.Language; } //slug duplicate validation if (isSuccess) { item.Title = item.Title.Trim(); item.Slug = item.Slug.Trim(); var temp = _nccPostDetailsService.Get(item.Slug, item.Language); if (temp != null && temp.Id != item.Id) { isSuccess = false; ViewBag.Message = "Duplicate Slug found for language " + item.Language; } } } } //Remove empty if (isSuccess) { foreach (var item in deletedList) { model.PostDetails.Remove(item); } } #endregion #region Operation if (isSuccess) { //Parent assign try { var parrent = _nccPostService.Get(ParentId); model.Parent = parrent; } catch (Exception) { } //Categories Assign try { if (SelecetdCategories.Count() > 0) { model.Categories = new List <NccPostCategory>(); foreach (var item in SelecetdCategories) { model.Categories.Add(new NccPostCategory() { Post = model, CategoryId = item }); } } } catch (Exception) { } //Tags Assign try { if (!string.IsNullOrEmpty(SelectedTags)) { model.Tags = new List <NccPostTag>(); string[] tagList = SelectedTags.Trim().Split(','); foreach (var item in tagList) { if (!string.IsNullOrEmpty(item)) { NccPostTag postTag = new NccPostTag(); NccTag nccTag = _nccTagService.LoadAll(false, -1, item.Trim()).FirstOrDefault(); if (nccTag == null) { nccTag = new NccTag(); nccTag.Name = item.Trim(); _nccTagService.Save(nccTag); } model.Tags.Add(new NccPostTag() { Post = model, Tag = nccTag }); } } } } catch (Exception) { } if (model.Id > 0) { try { _nccPostService.Update(model); ViewBag.MessageType = "SuccessMessage"; ViewBag.Message = "Page updated successful"; } catch (Exception ex) { _logger.LogError("Page create error.", ex.ToString()); } } else { try { _nccPostService.Save(model); _mediator.Send(new OnPostCreated(model)); ViewBag.MessageType = "SuccessMessage"; ViewBag.Message = "Page save successful"; } catch (Exception ex) { _logger.LogError("Page create error.", ex.ToString()); } } } #endregion } else { ViewBag.Message = string.Join("; ", ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage)); } if (ViewBag.MessageType == "SuccessMessage" && SubmitType.ToLower() == "publish") { return(RedirectToAction("Manage")); } if (ViewBag.MessageType == "SuccessMessage") { return(RedirectToAction("CreateEdit", new { Id = model.Id })); } SetPostViewData(model); return(View(model)); }
public static async Task SaveBasicData(NccUser nccUser, NccDbContext nccDbConetxt, UserManager <NccUser> userManager, RoleManager <NccRole> roleManager, NccSignInManager <NccUser> signInManager, WebSiteInfo setupInfo) { string enDemoTitle = ""; string enDemoSlug = ""; string enDemoContent = ""; string bnDemoTitle = ""; string bnDemoSlug = ""; string bnDemoContent = ""; //var webSiteRepository = new NccWebSiteRepository(nccDbConetxt); //var webSiteInfoRepository = new NccWebSiteInfoRepository(nccDbConetxt); //var webSiteService = new NccWebSiteService(webSiteRepository, webSiteInfoRepository); #region Create a sample page var nccPageRepository = new NccPageRepository(nccDbConetxt); var nccPageDetailsRepository = new NccPageDetailsRepository(nccDbConetxt); var nccPageService = new NccPageService(nccPageRepository, nccPageDetailsRepository); try { enDemoTitle = "Sample Page "; enDemoSlug = "Sample-Page"; enDemoContent = "This is a sample page."; bnDemoTitle = "নমুনা পৃষ্ঠা "; bnDemoSlug = "নমুনা-পৃষ্ঠা"; bnDemoContent = "এটি একটি নমুনা পাতা।"; NccPage page = new NccPage(); page.Metadata = "DEMODATA"; page.PublishDate = DateTime.Now; page.PageStatus = NccPageStatus.Published; page.PageType = NccPageType.Public; page.Layout = "SiteLayout"; page.CreateBy = page.ModifyBy = 1; page.Name = enDemoTitle; foreach (var item in SupportedCultures.Cultures) { NccPageDetails _nccPageDetails = new NccPageDetails(); _nccPageDetails.Language = item.TwoLetterISOLanguageName; if (item.TwoLetterISOLanguageName == "en") { _nccPageDetails.Title = enDemoTitle; _nccPageDetails.Slug = enDemoSlug; _nccPageDetails.Name = enDemoSlug; _nccPageDetails.Content = "<h1 style=\"text-align:center\">" + enDemoTitle + "</h1><p>" + enDemoContent + "</p>"; _nccPageDetails.MetaDescription = enDemoTitle + " " + enDemoContent; } else if (item.TwoLetterISOLanguageName == "bn") { _nccPageDetails.Title = bnDemoTitle; _nccPageDetails.Slug = bnDemoSlug; _nccPageDetails.Name = bnDemoSlug; _nccPageDetails.Content = "<h1 style=\"text-align:center\">" + bnDemoTitle + "</h1><p>" + bnDemoContent + "</p>"; _nccPageDetails.MetaDescription = bnDemoTitle + " " + bnDemoContent; } page.PageDetails.Add(_nccPageDetails); } nccPageService.Save(page); } catch (Exception ex) { } #endregion #region Create a sample category var categoryRepository = new NccCategoryRepository(nccDbConetxt); var categoryService = new NccCategoryService(categoryRepository); try { enDemoTitle = "Sample Category "; enDemoSlug = "Sample-Category"; bnDemoTitle = "নমুনা ক্যাটাগরি "; bnDemoSlug = "নমুনা-ক্যাটাগরি"; NccCategory item = new NccCategory(); item.Metadata = "DEMODATA"; item.Name = enDemoTitle; item.CategoryImage = "/media/Images/2017/06/image-slider-0.jpg"; foreach (var lang in SupportedCultures.Cultures) { NccCategoryDetails _nccDetails = new NccCategoryDetails(); _nccDetails.Language = lang.TwoLetterISOLanguageName; if (lang.TwoLetterISOLanguageName == "en") { _nccDetails.Title = enDemoTitle; _nccDetails.Slug = enDemoSlug; _nccDetails.Name = enDemoSlug; } else if (lang.TwoLetterISOLanguageName == "bn") { _nccDetails.Title = bnDemoTitle; _nccDetails.Slug = bnDemoSlug; _nccDetails.Name = bnDemoSlug; } item.CategoryDetails.Add(_nccDetails); } categoryService.Save(item); } catch (Exception ex) { } #endregion //var tagRepository = new NccTagRepository(nccDbConetxt); //var tagService = new NccTagService(tagRepository); #region Create a sample post var postRepository = new NccPostRepository(nccDbConetxt); var postDetailsRepository = new NccPostDetailsRepository(nccDbConetxt); var postService = new NccPostService(postRepository, postDetailsRepository); try { enDemoTitle = "Sample Post "; enDemoSlug = "Sample-Post"; enDemoContent = "This is a sample post."; bnDemoTitle = "নমুনা পোস্ট "; bnDemoSlug = "নমুনা-পোস্ট"; bnDemoContent = "এটি একটি নমুনা পোস্ট।"; var categoryList = categoryService.LoadAll(); NccPost post = new NccPost(); post.Metadata = "DEMODATA"; post.PublishDate = DateTime.Now; post.PostStatus = NccPostStatus.Published; post.PostType = NccPostType.Public; post.Layout = "SiteLayout"; post.CreateBy = post.ModifyBy = 1; post.Name = enDemoTitle; post.AllowComment = true; post.ThumImage = "/media/Images/2017/06/image-slider-2.jpg"; foreach (var postItem in SupportedCultures.Cultures) { NccPostDetails _nccPostDetails = new NccPostDetails(); _nccPostDetails.Language = postItem.TwoLetterISOLanguageName; if (postItem.TwoLetterISOLanguageName == "en") { _nccPostDetails.Title = enDemoTitle; _nccPostDetails.Slug = enDemoSlug; _nccPostDetails.Name = enDemoSlug; _nccPostDetails.Content = "<h1 style=\"text-align:center\">" + enDemoTitle + "</h1><hr />" + enDemoContent; _nccPostDetails.MetaDescription = enDemoTitle + " " + enDemoContent; } else if (postItem.TwoLetterISOLanguageName == "bn") { _nccPostDetails.Title = bnDemoTitle; _nccPostDetails.Slug = bnDemoSlug; _nccPostDetails.Name = bnDemoSlug; _nccPostDetails.Content = "<h1 style=\"text-align:center\">" + bnDemoTitle + "</h1><hr />" + bnDemoContent; _nccPostDetails.MetaDescription = bnDemoTitle + " " + bnDemoContent; } post.PostDetails.Add(_nccPostDetails); } postService.Save(post); try { post = postService.Get(post.Id, true); post.Categories = new List <NccPostCategory>(); var temp = categoryList.FirstOrDefault(); if (temp != null) { if (post.Categories.Where(x => x.CategoryId == temp.Id).Count() <= 0) { post.Categories.Add(new NccPostCategory() { Post = post, CategoryId = temp.Id }); } } postService.Update(post); } catch (Exception ex) { } } catch (Exception ex) { } #endregion #region Create a sample comment var commentsRepository = new NccCommentsRepository(nccDbConetxt); var commentsService = new NccCommentsService(commentsRepository); try { enDemoContent = "This is a sample comment."; bnDemoContent = "এটি একটি নমুনা মন্তব্য।"; NccComment commentItem = new NccComment(); commentItem.Metadata = "DEMODATA"; commentItem.Name = "Sample Comments"; commentItem.Content = enDemoContent; if (Language == "bn") { commentItem.Content = bnDemoContent; } commentItem.CommentStatus = NccComment.NccCommentStatus.Approved; commentItem.Post = postService.LoadAll().FirstOrDefault(); commentsService.Save(commentItem); } catch (Exception ex) { } #endregion #region Create sample menu var menuRepository = new NccMenuRepository(nccDbConetxt); var menuItemRepository = new NccMenuItemRepository(nccDbConetxt); var menuService = new NccMenuService(menuRepository, menuItemRepository); try { NccMenu nccMenu = new NccMenu() { Name = "Main Menu", Position = "Navigation", MenuOrder = 1, MenuLanguage = "" }; if (Language == "bn") { nccMenu.MenuItems.Add(new NccMenuItem() { Action = "", Controller = "", Data = "", //Id = item.Id, MenuActionType = NccMenuItem.ActionType.Url, MenuOrder = 1, Module = "", Name = "হোম", Target = "_self", Url = "/" }); nccMenu.MenuItems.Add(new NccMenuItem() { Action = "", Controller = "", Data = "", //Id = item.Id, MenuActionType = NccMenuItem.ActionType.Url, MenuOrder = 2, Module = "", Name = "নমুনা পৃষ্ঠা", Target = "_self", Url = "/নমুনা-পৃষ্ঠা" }); nccMenu.MenuItems.Add(new NccMenuItem() { Action = "", Controller = "", Data = "", //Id = item.Id, MenuActionType = NccMenuItem.ActionType.Url, MenuOrder = 3, Module = "", Name = "ব্লগ পোস্ট", Target = "_self", Url = "/Post" }); nccMenu.MenuItems.Add(new NccMenuItem() { Action = "", Controller = "", Data = "", //Id = item.Id, MenuActionType = NccMenuItem.ActionType.Url, MenuOrder = 4, Module = "", Name = "ব্লগ বিভাগ", Target = "_self", Url = "/Category" }); } else { nccMenu.MenuItems.Add(new NccMenuItem() { Action = "", Controller = "", Data = "", //Id = item.Id, MenuActionType = NccMenuItem.ActionType.Url, MenuOrder = 1, Module = "", Name = "Home", Target = "_self", Url = "/" }); nccMenu.MenuItems.Add(new NccMenuItem() { Action = "", Controller = "", Data = "", //Id = item.Id, MenuActionType = NccMenuItem.ActionType.Url, MenuOrder = 2, Module = "", Name = "Sample Page", Target = "_self", Url = "/Sample-Page" }); nccMenu.MenuItems.Add(new NccMenuItem() { Action = "", Controller = "", Data = "", //Id = item.Id, MenuActionType = NccMenuItem.ActionType.Url, MenuOrder = 3, Module = "", Name = "Blog Posts", Target = "_self", Url = "/Post" }); nccMenu.MenuItems.Add(new NccMenuItem() { Action = "", Controller = "", Data = "", //Id = item.Id, MenuActionType = NccMenuItem.ActionType.Url, MenuOrder = 4, Module = "", Name = "Blog Categories", Target = "_self", Url = "/Category" }); } menuService.Save(nccMenu); } catch (Exception ex) { } #endregion #region Create sample widget //var currentWebsite = nccWebSiteService.LoadAll().FirstOrDefault(); //var nccWebSiteWidget = new NccWebSiteWidget() //{ // WebSite = currentWebsite, // WidgetConfigJson = "", // ModuleId = "NetCoreCMS.Core.Modules.Cms", // WidgetId = "NetCoreCms.Modules.Cms.CmsSearch", // ThemeId = "com.NetCoreCMS.themes.NccSeventeen", // LayoutName = "SiteLayout", // Zone = "RightSidebar", // WidgetOrder = 1, // WidgetData = "", //}; //nccWebSiteWidgetService.Save(nccWebSiteWidget); #endregion }