Ejemplo n.º 1
0
        public bool CreatePage(int totalCount, DateTime dateFrom, DateTime dateTo)
        {
            int    currentCount = _pageService.LoadAll().Count();
            string itemName     = "Test-Page-";
            string enDemoTitle  = "Test Page ";
            string enDemoSlug   = "Test-Page-";
            string bnDemoTitle  = "টেস্ট পৃষ্ঠা ";
            string bnDemoSlug   = "টেস্ট-পৃষ্ঠা-";

            for (int i = 1; i <= totalCount; i++)
            {
                //Declare new page
                NccPage page = new NccPage();
                page.Metadata    = "DEMODATA";
                page.PublishDate = GetRandomDate(dateFrom, dateTo);
                page.PageStatus  = NccPageStatus.Published;
                page.PageType    = NccPageType.Public;
                page.Layout      = "SiteLayout";
                page.CreateBy    = page.ModifyBy = GetRandomUserId();
                page.Name        = itemName + (currentCount + i).ToString();

                //Create other language details
                foreach (var item in SupportedCultures.Cultures)
                {
                    var count = page.PageDetails.Where(x => x.Language == item.TwoLetterISOLanguageName).Count();
                    if (count <= 0)
                    {
                        NccPageDetails _nccPageDetails = new NccPageDetails();
                        _nccPageDetails.Language = item.TwoLetterISOLanguageName;
                        if (item.TwoLetterISOLanguageName == "en")
                        {
                            _nccPageDetails.Title           = enDemoTitle + (currentCount + i).ToString();
                            _nccPageDetails.Slug            = enDemoSlug + (currentCount + i).ToString();
                            _nccPageDetails.Name            = enDemoSlug + (currentCount + i).ToString();
                            _nccPageDetails.Content         = "<h1 style=\"text-align:center\">" + enDemoTitle + (currentCount + i).ToString() + "</h1><hr />" + enDemoContent;
                            _nccPageDetails.MetaDescription = enDemoTitle + (currentCount + i).ToString() + " " + enDemoContent;
                            _nccPageDetails.MetaDescription = _nccPageDetails.MetaDescription.Substring(0, 160);
                        }
                        else if (item.TwoLetterISOLanguageName == "bn")
                        {
                            _nccPageDetails.Title           = bnDemoTitle + (currentCount + i).ToString();
                            _nccPageDetails.Slug            = bnDemoSlug + (currentCount + i).ToString();
                            _nccPageDetails.Name            = bnDemoSlug + (currentCount + i).ToString();
                            _nccPageDetails.Content         = "<h1 style=\"text-align:center\">" + bnDemoTitle + (currentCount + i).ToString() + "</h1><hr />" + bnDemoContent;
                            _nccPageDetails.MetaDescription = bnDemoTitle + (currentCount + i).ToString() + " " + bnDemoContent;
                            _nccPageDetails.MetaDescription = _nccPageDetails.MetaDescription.Substring(0, 160);
                        }
                        page.PageDetails.Add(_nccPageDetails);
                    }
                }

                _pageService.Save(page);
            }

            return(true);
        }
Ejemplo n.º 2
0
        public ActionResult CreateEdit(NccPage model, string PageContent, long ParentId, string SubmitType)
        {
            ViewBag.MessageType = "ErrorMessage";
            ViewBag.Message     = "Error occoured. Please fill up all field correctly.";

            model.Content = PageContent;
            if (ModelState.IsValid)
            {
                if (model.Title.Trim() == "")
                {
                    ViewBag.Message = "Please enter page title.";
                }
                else if (model.Slug.Trim() == "")
                {
                    ViewBag.Message = "Please do not delete slug. Slug is required.";
                }
                else
                {
                    var slugPage = _pageService.GetBySlugs(model.Slug);
                    if (model.Id > 0)
                    {
                        try
                        {
                            var parrent = _pageService.Get(ParentId);
                            model.Parent = parrent;
                        }
                        catch (Exception) { }
                        if (slugPage != null && slugPage.Id != model.Id)
                        {
                            ViewBag.Message = "This slug is already used in another page.";
                        }
                        else
                        {
                            try
                            {
                                _pageService.Update(model);
                                ViewBag.MessageType = "SuccessMessage";
                                ViewBag.Message     = "Page updated successful";
                            }
                            catch (Exception ex)
                            {
                                _logger.LogError("Page create error.", ex.ToString());
                            }
                        }
                    }
                    else
                    {
                        if (slugPage != null)
                        {
                            ViewBag.Message = "Duplicate slug is found.";
                        }
                        else
                        {
                            try
                            {
                                _pageService.Save(model);
                                ViewBag.MessageType = "SuccessMessage";
                                ViewBag.Message     = "Page save successful";
                            }
                            catch (Exception ex)
                            {
                                _logger.LogError("Page create error.", ex.ToString());
                            }
                        }
                    }
                }
            }
            if (SubmitType.ToLower() == "publish")
            {
                return(RedirectToAction("Manage"));
            }
            ViewBag.Layouts  = GlobalConfig.ActiveTheme.Layouts;
            ViewBag.AllPages = _pageService.LoadAll().Where(p => p.Status == (int)NccPage.NccPageStatus.Published && p.Id != model.Id);
            return(View(model));
        }
Ejemplo n.º 3
0
        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
        }
Ejemplo n.º 4
0
        public ActionResult CreateEdit(NccPage model, long ParentId, 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 defaultPageDetails = model.PageDetails.Where(x => x.Language == GlobalContext.WebSite.Language).FirstOrDefault();
                if (defaultPageDetails == null)
                {
                    isSuccess       = false;
                    ViewBag.Message = "Default language Page can't be null";
                }
                else
                {
                    //title empty validation
                    if (string.IsNullOrEmpty(defaultPageDetails.Title))
                    {
                        isSuccess       = false;
                        ViewBag.Message = "Default language Title can't be null";
                    }
                    //slug empty validation
                    if (isSuccess && string.IsNullOrEmpty(defaultPageDetails.Slug))
                    {
                        isSuccess       = false;
                        ViewBag.Message = "Default language Slug can't be null";
                    }
                    //slug duplicate validation
                    if (isSuccess)
                    {
                        defaultPageDetails.Title = defaultPageDetails.Title.Trim();
                        defaultPageDetails.Slug  = defaultPageDetails.Slug.Trim();
                        if ((defaultPageDetails.MetaDescription == null || defaultPageDetails.MetaDescription.Trim() == "") && defaultPageDetails.Content != null && defaultPageDetails.Content.Length > 0)
                        {
                            defaultPageDetails.MetaDescription = Regex.Replace(defaultPageDetails.Content, "<.*?>", String.Empty);
                            if (defaultPageDetails.MetaDescription.Length > 161)
                            {
                                defaultPageDetails.MetaDescription = defaultPageDetails.MetaDescription.Substring(0, 160);
                            }
                        }
                        model.Name = defaultPageDetails.Slug;

                        var temp = _pageDetailsService.Get(defaultPageDetails.Slug, defaultPageDetails.Language);
                        if (temp != null && temp.Id != defaultPageDetails.Id)
                        {
                            isSuccess       = false;
                            ViewBag.Message = "Duplicate Slug found for language " + defaultPageDetails.Language;
                        }
                    }
                }
                #endregion

                #region Check validation for other languages
                List <NccPageDetails> deletedList = new List <NccPageDetails>();
                foreach (var item in model.PageDetails.Where(x => x.Language != GlobalContext.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();
                            if ((item.MetaDescription == null || item.MetaDescription.Trim() == "") && item.Content != null && item.Content.Length > 0)
                            {
                                item.MetaDescription = Regex.Replace(item.Content, "<.*?>", String.Empty);
                                if (item.MetaDescription.Length > 161)
                                {
                                    item.MetaDescription = item.MetaDescription.Substring(0, 160);
                                }
                            }

                            var temp = _pageDetailsService.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.PageDetails.Remove(item);
                    }
                }
                #endregion

                #region Operation
                if (isSuccess)
                {
                    try
                    {
                        var parrent = _pageService.Get(ParentId);
                        model.Parent = parrent;
                    }
                    catch (Exception) { }
                    if (model.Id > 0)
                    {
                        try
                        {
                            _pageService.Update(model);
                            ViewBag.MessageType = "SuccessMessage";
                            ViewBag.Message     = "Page updated successful";
                        }
                        catch (Exception ex)
                        {
                            _logger.LogError("Page create error.", ex.ToString());
                        }
                    }
                    else
                    {
                        try
                        {
                            _pageService.Save(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"));
            }

            SetPageViewData(model);
            return(View(model));
        }