/// <summary> /// 删除分类 /// </summary> /// <param name="dto"></param> /// <returns></returns> public MdmGoodsClassDto SaveGoodsClass(MdmGoodsClassDto dto) { if (dto.Id == 0 || string.IsNullOrEmpty(dto.Id + "")) { var classList = _mdmGoodsClassRepository.GetAllList(m => m.CLASS_NO == dto.CLASS_NO || m.CLASS_NAME == dto.CLASS_NAME && m.BG_NO == AbpSession.BG_NO); if (classList == null || classList.Count == 0) { _initHelper.InitAdd(dto, AbpSession.USR_ID, AbpSession.ORG_NO, AbpSession.BG_NO); return(_mdmGoodsClassRepository.Insert(dto.ToEntity()).ToDto()); } else { throw new Exception("分类编码或名称已存在"); } } else { var classInfo = _mdmGoodsClassRepository.Get(dto.Id); classInfo.CLASS_STATUS = dto.CLASS_STATUS; IList <string> goodsClassIdList = new List <string>(); if (dto.CLASS_STATUS == 0) { goodsClassIdList.Add(dto.Id + ""); if (!CheckBind(ref goodsClassIdList)) { throw new Exception("无法删除已绑定商品的商品分类"); } } dto.UPDATE_PSN = Convert.ToDecimal(AbpSession.USR_ID); dto.UPDATE_DATE = DateTime.Now; var classDto = _mdmGoodsClassRepository.Update(dto.ToEntity()).ToDto(); if (classDto.CLASS_STATUS == 0 && classDto != null) { //删除所有子类 string sqlStr = ""; foreach (string classIds in goodsClassIdList) { sqlStr = string.IsNullOrEmpty(sqlStr) ? classIds : sqlStr + "," + classIds; } sqlStr = " CLASS_ID in (" + sqlStr + ")"; bool flag = _mdmGoodsClassRepository.DelGoodsClass(sqlStr); if (!flag) { throw new Exception("保存失败"); } } } return(dto); }
public ActionResult GetGoodClassByParentId(int parentId) { try { var result = _mdmGoodsClassRepository.GetAllList(m => m.PARENT_ID == parentId && m.BG_NO == AbpSession.BG_NO); return(Success("获取成功", result)); } catch (Exception ex) { return(Fail("获取失败:" + ex.Message)); } }