public async Task <ActionResult> InsertArticleCategoryAsync(ArticleCategoryModel articleCategoryModel) { ArticleCategory category = new ArticleCategory { Description = articleCategoryModel.Description }; using (var orderDbContext = Provider.CreateDbContext()) { try { await orderDbContext.ArticleCategories.AddAsync(category); await orderDbContext.SaveChangesAsync(); Log.Info("新增类型 " + articleCategoryModel.Description + "成功!"); return(new ActionResult() { Status = ActionStatus.OK, Msg = "新增类型 " + articleCategoryModel.Description + "成功!" }); } catch (Exception ex) { Log.Error(ex.ToString()); return(new ActionResult() { Status = ActionStatus.Failed, Msg = "新增类型 " + articleCategoryModel.Description + "失败!" }); } } }
public ActionResult Create(ArticleCategoryModel viewModel) { var strMessage = string.Empty; try { if (ModelState.IsValid) { #region Current User var userName = HttpContext.User.Identity.Name; viewModel.IUser = userName; viewModel.IDate = DateTime.Now; viewModel.EDate = DateTime.Now; #endregion var entity = viewModel.ToEntity(); _sdArtCategoryService.INVUnit.ArticleCategoryRepository.Add(entity); _sdArtCategoryService.INVUnit.ArticleCategoryRepository.SaveChanges(); return(Content(Boolean.TrueString)); //return Content("Information has been saved successfully"); } strMessage = Common.GetModelStateErrorMessage(ModelState); } catch (Exception ex) { strMessage = CommonExceptionMessage.GetExceptionMessage(ex, CommonAction.Save); } return(Content(strMessage)); }
protected void PrepareTemplatesModel(ArticleCategoryModel model) { if (model == null) { throw new ArgumentNullException("model"); } var channel = _channelService.GetChannelById(model.ChannelId); var templates = _modelTemplateService.GetAllModelTemplates(); var listTemplate = templates.Where(p => p.TemplageTypeId == (int)TemplateTypeFormat.List).ToList(); foreach (var template in listTemplate) { model.AvailableModelTemplates.Add(new SelectListItem() { Text = template.Name, Value = template.Id.ToString(), }); } var detailTemplate = templates.Where(p => p.TemplageTypeId == (int)TemplateTypeFormat.Detail).ToList(); foreach (var template in detailTemplate) { model.AvailableDetailModelTemplates.Add(new SelectListItem() { Text = template.Name, Value = template.Id.ToString(), }); } if (channel != null && channel.ModelTemplateId == 0) { model.ModelTemplateId = channel.ModelTemplateId; model.DetailModelTemplateId = channel.DetailModelTemplateId; } }
public ActionResult AjaxHomeArticleBlock(int categoryId, int?articleThumbPictureSize, ArticleCatalogPagingFilteringModel command) { var model = new ArticleCategoryModel(); model = CategoryFilter(categoryId, articleThumbPictureSize, command); return(Json(model)); }
public ActionResult HomeRecentlyArticleViewed(int categoryId, int?articleThumbPictureSize, string partialView, ArticleCatalogPagingFilteringModel command) { var model = new ArticleCategoryModel(); model = CategoryFilter(categoryId, articleThumbPictureSize, command, partialView); return(PartialView(partialView, model)); }
protected void UpdateCategoryAcl(ArticleCategory category, ArticleCategoryModel model) { var existingAclRecords = _aclService.GetAclRecords(category); var allUserRoles = _userService.GetAllUserRoles(true); foreach (var userRole in allUserRoles) { if (model.SelectedUserRoleIds != null && model.SelectedUserRoleIds.Contains(userRole.Id)) { //new role if (existingAclRecords.Where(acl => acl.UserRoleId == userRole.Id).Count() == 0) { _aclService.InsertAclRecord(category, userRole.Id); } } else { //removed role var aclRecordToDelete = existingAclRecords.Where(acl => acl.UserRoleId == userRole.Id).FirstOrDefault(); if (aclRecordToDelete != null) { _aclService.DeleteAclRecord(aclRecordToDelete); } } } }
public async Task <ActionResult> UpdateArticleCategoryAsync(ArticleCategoryModel categoryModel) { using (var orderDbContext = Provider.CreateDbContext()) { try { ArticleCategory updateArticleCategory = await orderDbContext.ArticleCategories.Where(a => a.Id == categoryModel.Id).FirstOrDefaultAsync(); if (updateArticleCategory != null) { updateArticleCategory.Description = categoryModel.Description; } await orderDbContext.SaveChangesAsync(); Log.Info("修改 id:" + updateArticleCategory.Id + "成功!"); return(new ActionResult() { Status = ActionStatus.OK, Msg = "修改 id:" + updateArticleCategory.Id + "成功!" }); } catch (Exception ex) { Log.Error(ex.ToString()); return(new ActionResult() { Status = ActionStatus.Failed, Msg = "修改 " + categoryModel.Description + "失败!" }); } } }
// GET: /ArticleCategory/Details/By ID public ActionResult Details(long id) { var errorViewModel = new ErrorViewModel(); try { var model = _sdArtCategoryService.INVUnit.ArticleCategoryRepository.GetByID(id); if (model != null) { ArticleCategoryModel viewModel = new ArticleCategoryModel { Id = model.Id, CategoryName = model.CategoryName, Description = model.Description }; return(PartialView("_Details", viewModel)); } else { errorViewModel.ErrorMessage = CommonMessage.ErrorOccurred; return(PartialView("_ErrorPopUp", errorViewModel)); } } catch (Exception ex) { errorViewModel.ErrorMessage = CommonExceptionMessage.GetExceptionMessage(ex); return(PartialView("_ErrorPopUp", errorViewModel)); } }
public ActionResult Create(int?channelId) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)) { return(AccessDeniedView()); } var model = new ArticleCategoryModel(); if (channelId.HasValue) { model.ChannelId = channelId.Value; } //locales AddLocales(_languageService, model.Locales); //templates PrepareTemplatesModel(model); //channel PrepareChannelsModel(model); PrepareCategoryModel(model, null); //ACL PrepareAclModel(model, null, false); //Sites PrepareSitesMappingModel(model, null, false); //default values //default values model.PageSize = 12; model.Published = true; model.DisplayOrder = 1; model.AllowUsersToSelectPageSize = true; return(View(model)); }
public async Task <IActionResult> Update(ArticleCategoryModel model) { if (model.Id <= 0) { return(RedirectToErrorPage()); } var exist = await _articleCategoryService.FindAsync(new IdRequestFilter <int> { CanGetInactived = true, Id = model.Id }); if (exist == null) { return(RedirectToErrorPage()); } var category = new ArticleCategoryModifyRequest { Description = model.Description, ParentId = model.ParentId, Name = model.Name, UpdatedById = LoggedUserId, Id = model.Id }; await _articleCategoryService.UpdateAsync(category); return(RedirectToAction(nameof(Detail), new { id = category.Id })); }
public ActionResult PublicInfo(string widgetZone, object model) { //if (LicenseChecker.CheckState("SmartSite.CustomBanner", null) == null) //{ // return new EmptyResult(); //} int pictureId = 0; if (model != null) { int pageId = 0; string entity = ""; if (model.GetType() == typeof(ArticlePostModel)) { ArticlePostModel articleModel = (ArticlePostModel)model; pageId = articleModel.Id; entity = "article"; } else { if (model.GetType() == typeof(ArticleCategoryModel)) { ArticleCategoryModel categoryModel = (ArticleCategoryModel)model; pageId = categoryModel.Id; entity = "category"; } else { if (model.GetType() == typeof(TopicModel)) { TopicModel topicModel = (TopicModel)model; pageId = topicModel.Id; entity = "topic"; } } } CustomBannerRecord bannerRecord = this._customBannerService.GetCustomBannerRecord(pageId, entity); if (bannerRecord != null) { pictureId = bannerRecord.PictureId; } } if (pictureId != 0) { CustomBannerSettings customBannerSettings = this._settingService.LoadSetting <CustomBannerSettings>(this._siteContext.CurrentSite.Id); Picture pic = this._pictureService.GetPictureById(pictureId); return(base.View(new PublicInfoModel { PicturePath = this._pictureService.GetPictureUrl(pic, 0, true, null), MaxBannerHeight = customBannerSettings.MaxBannerHeight, StretchPicture = customBannerSettings.StretchPicture, ShowBorderBottom = customBannerSettings.ShowBorderBottom, ShowBorderTop = customBannerSettings.ShowBorderTop, BorderTopColor = customBannerSettings.BorderTopColor, BorderBottomColor = customBannerSettings.BorderBottomColor })); } return(base.Content("")); }
public void Update(int articleCategoryId, ArticleCategoryModel articleCategory) { var result = _context.ArticleCategories.SingleOrDefault(x => x.ArticleCategoryId == articleCategoryId); if (result != null) { result.Name = articleCategory.Name; _context.SaveChanges(); } }
// GET: /ArticleCategory/Create public ActionResult Create() { var errorViewModel = new ErrorViewModel(); try { var model = new ArticleCategoryModel(); return(PartialView("_Create", model)); } catch (Exception ex) { errorViewModel.ErrorMessage = CommonExceptionMessage.GetExceptionMessage(ex); return(PartialView("_ErrorPopUp", errorViewModel)); } }
public IActionResult EditCategory(int id, [FromBody] ArticleCategoryModel modelToEdit) { AssignModelState(); modelToEdit.Id = id; var response = _categoryService.Edit(modelToEdit); if (response.Success) { return(Ok(response.Item)); } else { return(BadRequest(response.Message)); } }
/// <summary> /// 通过分类名称获取分类模型 /// </summary> /// <param name="name">分类名称</param> /// <returns></returns> public ArticleCategoryModel GetArticleCategoryModelByCategoryName(string name) { IRepository <ArticleCategory> articleRep = Factory.Factory <IRepository <ArticleCategory> > .GetConcrete <ArticleCategory>(); ArticleCategory ac = articleRep.Find(new Specification <ArticleCategory>(a => a.Name == name)); ArticleCategoryModel model = new ArticleCategoryModel(); if (ac != null) { model = new ArticleCategoryModel() { CategoryID = ac.Id, CategoryName = ac.Name, Deepth = ac.Deepth, Description = ac.Description, ParentID = ac.ParentID, IconName = ac.Icon, Priority = ac.Priority }; } return(model); }
protected void UpdateSiteMappings(ArticleCategory category, ArticleCategoryModel model) { //网站限制 if (this._siteSettings.SiteContentShare) { category.LimitedToSites = model.LimitedToSites; } else { category.LimitedToSites = true; var siteIds = new List <int>(); siteIds.Add(this._siteContext.CurrentSite.Id); model.SelectedSiteIds = siteIds.ToArray(); } _siteMappingService.SaveSiteMappings <ArticleCategory>(category, model.SelectedSiteIds); }
public IActionResult PostCategory([FromBody] ArticleCategoryModel modelToCreate) { if (String.IsNullOrWhiteSpace(modelToCreate.Slug)) { modelToCreate.Slug = modelToCreate.Name.Replace(" ", "-").ToLower(); } AssignModelState(); var response = _categoryService.Create(modelToCreate); if (response.Success) { return(Ok(response.Item)); } else { return(BadRequest(response.Message)); } }
protected void PrepareChannelsModel(ArticleCategoryModel model) { if (model == null) { throw new ArgumentNullException("model"); } var channels = _channelService.GetAllChannels(); foreach (var channel in channels) { model.AvailableChannels.Add(new SelectListItem() { Text = channel.Title, Value = channel.Id.ToString() }); } }
public async Task <IActionResult> Detail(int id) { if (id <= 0) { return(RedirectToNotFoundPage()); } try { var category = await _articleCategoryService.FindAsync(new IdRequestFilter <int> { CanGetInactived = true, Id = id }); if (category == null) { return(RedirectToNotFoundPage()); } var model = new ArticleCategoryModel { Description = category.Description, Id = category.Id, ParentId = category.ParentId, Name = category.Name, UpdatedDate = category.UpdatedDate, UpdateById = category.UpdatedById, CreatedById = category.CreatedById, CreatedDate = category.CreatedDate, CreatedBy = category.CreatedBy, UpdatedBy = category.UpdatedBy, ParentCategoryName = category.ParentCategoryName, StatusId = (ArticleCategoryStatus)category.StatusId }; return(View(model)); } catch (Exception) { return(RedirectToErrorPage()); } }
//category public static ArticleCategoryModel ToModel(this ArticleCategory entity) { if (entity == null) { return(null); } var model = new ArticleCategoryModel { Id = entity.Id, Name = entity.GetLocalized(x => x.Name), FullName = entity.GetLocalized(x => x.FullName), Description = entity.GetLocalized(x => x.Description), BottomDescription = entity.GetLocalized(x => x.BottomDescription), MetaKeywords = entity.GetLocalized(x => x.MetaKeywords), MetaDescription = entity.GetLocalized(x => x.MetaDescription), MetaTitle = entity.GetLocalized(x => x.MetaTitle), SeName = entity.GetSeName(), }; return(model); }
public ActionResult Edit(ArticleCategoryModel viewModel) { var strMessage = string.Empty; try { if (ModelState.IsValid) { var model = _sdArtCategoryService.INVUnit.ArticleCategoryRepository.GetByID(viewModel.Id); #region Current User viewModel.IUser = model.IUser; viewModel.IDate = model.IDate; var userName = HttpContext.User.Identity.Name; viewModel.EUser = userName; viewModel.EDate = DateTime.Now; #endregion var entity = viewModel.ToEntity(); _sdArtCategoryService.INVUnit.ArticleCategoryRepository.Update(entity); _sdArtCategoryService.INVUnit.ArticleCategoryRepository.SaveChanges(); return(Content(Boolean.TrueString)); } strMessage = Common.GetModelStateErrorMessage(ModelState); } catch (Exception ex) { strMessage = CommonExceptionMessage.GetExceptionMessage(ex, CommonAction.Update); } return(Content(strMessage)); }
public ActionResult Management() { IArticleCategoryService articleCategoryService = ServiceHelper.Create <IArticleCategoryService>(); IQueryable <ArticleCategoryInfo> articleCategoriesByParentId = articleCategoryService.GetArticleCategoriesByParentId(0, false); ArticleCategoryModel[] array = ( from item in articleCategoriesByParentId.ToArray() select new ArticleCategoryModel() { ParentId = item.ParentCategoryId, Name = item.Name, DisplaySequence = item.DisplaySequence, Id = item.Id, IsDefault = item.IsDefault }).ToArray(); ArticleCategoryModel[] articleCategoryModelArray = array; for (int i = 0; i < articleCategoryModelArray.Length; i++) { ArticleCategoryModel articleCategoryModel = articleCategoryModelArray[i]; articleCategoryModel.HasChild = articleCategoryService.GetArticleCategoriesByParentId(articleCategoryModel.Id, false).Count() > 0; } return(View(array)); }
public ActionResult List() { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)) { return(AccessDeniedView()); } var model = new ArticleCategoryModel(); #region categories //categories var allChannels = _channelService.GetAllChannels(); foreach (var c in allChannels) { model.AvailableChannels.Add(new SelectListItem { Text = c.Title, Value = c.Id.ToString() }); } #endregion return(View(model)); }
/// <summary> /// 获取新闻分类 /// </summary> /// <returns> 新闻分类列表</returns> public IList <ArticleCategoryModel> FetchArticleCategory() { IRepository <ArticleCategory> articleRep = Factory.Factory <IRepository <ArticleCategory> > .GetConcrete <ArticleCategory>(); IList <ArticleCategory> alist = articleRep.FindAll(); IList <ArticleCategoryModel> target = new List <ArticleCategoryModel>(); foreach (ArticleCategory story in alist) { ArticleCategoryModel temp = new ArticleCategoryModel() { CategoryID = story.Id, CategoryName = story.Name, IconName = story.Icon, Deepth = story.Deepth, Description = story.Description, ParentID = story.ParentID, Priority = story.Priority }; target.Add(temp); } return(target); }
private void PrepareAclModel(ArticleCategoryModel model, ArticleCategory category, bool excludeProperties) { if (model == null) { throw new ArgumentNullException("model"); } model.AvailableUserRoles = _userService .GetAllUserRoles(true) .Select(cr => cr.ToModel()) .ToList(); if (!excludeProperties) { if (category != null) { model.SelectedUserRoleIds = _aclService.GetUserRoleIdsWithAccess(category); } else { model.SelectedUserRoleIds = new int[0]; } } }
public async Task <IActionResult> Create(ArticleCategoryModel model) { var category = new ArticleCategoryModifyRequest { Description = model.Description, ParentId = model.ParentId, Name = model.Name, UpdatedById = LoggedUserId, CreatedById = LoggedUserId }; var exist = await _articleCategoryService.FindByNameAsync(model.Name); if (exist != null) { return(RedirectToErrorPage()); } category.UpdatedById = LoggedUserId; category.CreatedById = LoggedUserId; var id = await _articleCategoryService.CreateAsync(category); return(RedirectToAction(nameof(Detail), new { id })); }
protected void UpdateLocales(ArticleCategory category, ArticleCategoryModel model) { foreach (var localized in model.Locales) { _localizedEntityService.SaveLocalizedValue(category, x => x.Name, localized.Name, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(category, x => x.FullName, localized.FullName, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(category, x => x.Description, localized.Description, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(category, x => x.BottomDescription, localized.BottomDescription, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(category, x => x.MetaKeywords, localized.MetaKeywords, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(category, x => x.MetaDescription, localized.MetaDescription, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(category, x => x.MetaTitle, localized.MetaTitle, localized.LanguageId); //search engine name var seName = category.ValidateSeName(localized.SeName, localized.Name, false, localized.LanguageId); _urlRecordService.SaveSlug(category, seName, localized.LanguageId); } }
public ActionResult Center(int?channelId) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)) { return(AccessDeniedView()); } var model = new ArticleCategoryModel(); #region templates //var templates = _modelTemplateService.GetAllModelTemplates(); //foreach (var template in templates) //{ // model.AvailableModelTemplates.Add(new SelectListItem() // { // Text = template.Name, // Value = template.Id.ToString() // }); //} #endregion #region Channels if (channelId.HasValue) { var channel = _channelService.GetChannelById(channelId.Value); model.ChannelId = channel.Id; model.ModelTemplateId = channel.ModelTemplateId; model.DetailModelTemplateId = channel.DetailModelTemplateId; } #endregion return(View(model)); }
public JsonResult GetArticleCategories(long parentId) { IQueryable <ArticleCategoryInfo> articleCategoriesByParentId = ServiceHelper.Create <IArticleCategoryService>().GetArticleCategoriesByParentId(parentId, false); ArticleCategoryModel[] array = ( from item in articleCategoriesByParentId select new ArticleCategoryModel() { Id = item.Id, Name = item.Name, DisplaySequence = item.DisplaySequence, HasChild = false, Depth = 2 }).ToArray(); IArticleCategoryService articleCategoryService = ServiceHelper.Create <IArticleCategoryService>(); ArticleCategoryModel[] articleCategoryModelArray = array; for (int i = 0; i < articleCategoryModelArray.Length; i++) { ArticleCategoryModel articleCategoryModel = articleCategoryModelArray[i]; articleCategoryModel.HasChild = articleCategoryService.GetArticleCategoriesByParentId(articleCategoryModel.Id, false).Count() > 0; } return(Json(array)); }
public async Task <IActionResult> Update(int id) { var category = await _articleCategoryService.FindAsync(new IdRequestFilter <int> { CanGetInactived = true, Id = id }); var model = new ArticleCategoryModel { Description = category.Description, Id = category.Id, ParentId = category.ParentId, Name = category.Name, UpdatedDate = category.UpdatedDate, UpdateById = category.UpdatedById, CreatedById = category.CreatedById, CreatedDate = category.CreatedDate, ParentCategoryName = category.ParentCategoryName, StatusId = (ArticleCategoryStatus)category.StatusId }; return(View(model)); }