public ActionResult Index() { var nccTranslator = new NccTranslator(CurrentLanguage); ViewBag.TotalUser = _userManager.Users.Count(); ViewBag.TotalPublishedPage = _pageService.LoadAllByPageStatus(NccPage.NccPageStatus.Published).Count(); ViewBag.TotalPage = _pageService.LoadAll(true).Count(); ViewBag.TotalCategory = _categoryService.LoadAll(true).Count(); ViewBag.TotalTag = _tagService.LoadAll(true).Count(); ViewBag.TotalPublishedPost = _postService.Count(true, true, true, true); ViewBag.TotalPost = _postService.LoadAll(true).Count(); ViewBag.TotalComments = _commentsService.LoadAll(true).Count(); return(View()); }
public ActionResult Index(string name = "", int page = 0) { ViewBag.CurrentLanguage = CurrentLanguage; if (!string.IsNullOrEmpty(name)) { var item = _nccTagService.Get(name); if (item != null) { ViewBag.Name = name; ViewBag.Tag = item; var postPerPage = GlobalContext.WebSite.WebSitePageSize; var totalPost = _nccPostService.Count(true, true, true, true, null, null, 0, item.Id); var allPost = _nccPostService.Load(page, postPerPage, true, true, true, true, null, null, 0, item.Id); ViewBag.CurrentPage = page; ViewBag.PostPerPage = postPerPage; ViewBag.TotalPost = totalPost; return(View("Details", allPost)); } } var allPosts = _nccTagService.LoadAll(true).OrderByDescending(x => x.Posts.Count).ToList(); return(View(allPosts)); }
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 ActionResult Manage(long Id = 0) { var itemList = _nccTagService.LoadAll(false).OrderBy(x => x.Name).ToList(); return(View(itemList)); }