TypeLogic.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * 命名空间: CZFW.Framework.Modules.Logic
  3. *
  4. * 功 能: N/A
  5. * 类 名: TypeLogic
  6. *
  7. * Ver 变更日期 负责人 变更内容
  8. * ───────────────────────────────────
  9. * V0.01 2016/12/1 9:10:08 吴争辉 初稿
  10. *
  11. * Copyright (c) 2016 CHUANGZHIKEJI Corporation. All rights reserved.
  12. *┌──────────────────────────────────┐
  13. *│ 此技术信息为本公司机密信息,未经本公司书面同意禁止向第三方披露. │
  14. *│ 版权所有:创执科技(北京)有限公司                │
  15. *└──────────────────────────────────┘
  16. */
  17. using System.Linq;
  18. using CZFW.Framework.Interface;
  19. using CZFW.Framework.Model.Entity;
  20. using CZFW.Framework.Model.ViewModel;
  21. namespace CZFW.Framework.Logic
  22. {
  23. /// <summary>
  24. /// 分类
  25. /// </summary>
  26. public class TypeLogic : LogicBase<TypeEntity>, IType
  27. {
  28. /// <summary>
  29. /// 根据父Id获取类型列表
  30. /// </summary>
  31. /// <param name="parentId">父Id</param>
  32. /// <returns></returns>
  33. public TableModel<TypeEntity> GetListByParentId(int parentId, int pageIndex, int pageSize)
  34. {
  35. var queryable = Queryable.Where(x => x.ParentId == parentId);
  36. int rowsCount = queryable.Count();
  37. var model = new TableModel<TypeEntity>();
  38. var data = queryable.OrderByDescending(x =>x.SortOrder).Skip((pageIndex-1)*pageSize).Take(pageSize).ToList();
  39. model.SetData(data);
  40. model.Pager = new PagerModel(rowsCount, pageIndex, pageSize);
  41. model.TableHeads = PropertyHelper.Get(typeof(TypeEntity));
  42. return model;
  43. }
  44. public ResultModel RemoveType(int id)
  45. {
  46. var typeList = DbContext.Set<TypeEntity>().Where(x => x.ParentId == id).ToList();
  47. if (typeList.Count > 0)
  48. {
  49. RemoveEntities(x => x.ParentId == id);
  50. }
  51. return RemoveEntity(id);
  52. }
  53. }
  54. }