/// <summary> /// 分类文章|标签 /// </summary> /// <param name="category"></param> /// <param name="tag"></param> /// <param name="archive"></param> /// <returns></returns> public ActionResult Category(string category = "", string tag = "", string archive = "") { if (category.IsNullOrEmpty() && tag.IsNullOrEmpty() && archive.IsNullOrEmpty()) { throw new ArgumentNullException("参数不正确!"); } PageDto pag = new PageDto { Sort = "Id", Order = "desc", Limit = 10, Offset = 0 }; DataGrid dg = _articleRepository.GetCategoryTagGrid(pag, category, tag, archive); string typeName = ""; if (category.IsNotNullOrEmpty() || tag.IsNotNullOrEmpty()) { typeName = _itemsDetailRepository.Queryable(r => r.ItemCode == category || r.ItemCode == tag).Select(r => r.ItemName).FirstOrDefault(); } else { typeName = archive; } ViewBag.TypeName = typeName.IsNullOrEmpty() ? "亲,您迷路了啊!|、天上有木月" : typeName; ViewBag.ViewModel = dg.ToJson(); return(View()); }
/// <summary> /// 重写编辑方法,验证编码的唯一性 /// </summary> /// <param name="viewModel">实体</param> /// <param name="id">主键</param> /// <returns></returns> public override ActionResult Edit(ItemsDetailViewModel viewModel, int id = 0) { int codeCount = 0; if (id == 0) { codeCount = _itemsDetailRepository.Queryable(u => u.ItemCode == viewModel.ItemCode).Count(); } else { codeCount = _itemsDetailRepository.Queryable(u => u.ItemCode == viewModel.ItemCode && u.Id != id).Count(); } if (codeCount > 0) { return(Error("编码不唯一!")); } RedisHelper.KeyDeleteAsync(string.Format(ConstHelper.ItemsDetailAll, "GetCombobox-" + EnCode.FTypeCode.ToString())); RedisHelper.KeyDeleteAsync(string.Format(ConstHelper.ItemsDetailAll, "GetCombobox-" + EnCode.Tag.ToString())); RedisHelper.KeyDeleteAsync(string.Format(ConstHelper.Article, "category")); return(base.Edit(viewModel, id)); }
public List <ItemsDetailBaseEntity> GetList(string itemId = "", string keyword = "") { var expression = ExtLinq.True <ItemsDetailBaseEntity>(); if (!string.IsNullOrEmpty(itemId)) { expression = expression.And(t => t.F_ItemId == itemId); } if (!string.IsNullOrEmpty(keyword)) { expression = expression.And(t => t.F_ItemName.Contains(keyword)); expression = expression.Or(t => t.F_ItemCode.Contains(keyword)); } return(service.Queryable(expression).OrderBy(t => t.F_SortCode).ToList()); }
/// <summary> /// 文章新增,编辑,由于后期加了一个文章可以有多个标签,一个标签可对应多个文章,就是多对多的关系, /// 所以,这里就需要重新对数据进行处理后,提交数据库 /// </summary> /// <param name="viewModel"></param> /// <param name="id"></param> /// <returns></returns> public override ActionResult Edit(ArticleViewModel viewModel, int id = 0) { if (!ModelState.IsValid) { return(Error(ModelState.Values.FirstOrDefault(u => u.Errors.Count > 0)?.Errors[0].ErrorMessage)); } string tagIds = Request["Tag"].ToString(); List <TagArt> tagArtList = new List <TagArt> { }; if (tagIds.IsNotNullOrEmpty()) { foreach (var i in tagIds.Split(',').Select(u => Convert.ToInt32(u)).ToList()) { tagArtList.Add(new TagArt { TagId = i, AId = id }); } } Article entity; if (id == 0) { entity = Mapper.Map <ArticleViewModel, Article>(viewModel); entity.Create(); entity.TagArts = tagArtList; entity.Archive = DateTime.Now.ToString("yyy年MM月"); _articleRepository.Insert(entity); } else { var tEntityModel = _articleRepository.FindEntity(id); if (tEntityModel == null) { return(Error($"Id为{id}未找到任何类型为{viewModel.GetType().Name}的实体对象")); } entity = Mapper.Map(viewModel, tEntityModel); entity.Modify(id); using (var db = new RepositoryBase().BeginTrans()) { db.Update(entity); db.Delete <TagArt>(u => u.AId == id); db.Insert(tagArtList); db.Commit(); } } //要根据新增或修改的文章类型,来判断是否删除缓存中的数据 if (entity.FId != null) { string itemCode = _itemsDetailRepository.Queryable(u => u.Id == entity.FId).Select(r => r.ItemCode).FirstOrDefault(); if (itemCode != null) { if (itemCode.Equals(CategoryCode.Justfun.ToString())) { RedisHelper.KeyDeleteAsync(string.Format(ConstHelper.App, "JustFun")); } if (itemCode.Equals(CategoryCode.Feelinglife.ToString())) { RedisHelper.KeyDeleteAsync(string.Format(ConstHelper.App, "FellLife")); } } } RedisHelper.KeyDeleteAsync(string.Format(ConstHelper.Article, "GetRecentArticle")); RedisHelper.KeyDelete(string.Format(ConstHelper.Article, "archiveFile")); return(Success()); }