Example #1
0
        private void RemoveAllChild(TCDMS_MasterDataEntities tcdmse, dict_RegionInfo dict, HashSet <int> idset)
        {
            var child = tcdmse.dict_RegionInfo.Where(p => p.RegionPID == dict.RegionID);

            foreach (var p in child)
            {
                if (idset.Contains(p.RegionID))
                {
                    throw new Exception("此条信息已使用不可删除!");
                }
                RemoveAllChild(tcdmse, p, idset);
            }
            tcdmse.dict_RegionInfo.RemoveRange(child);
        }
Example #2
0
        /// <summary>
        /// 新增行政区划
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public bool AddRegion(RegionOperateDTO dto)
        {
            var result = false;

            using (var tcdmse = new Entities.TCDMS_MasterDataEntities())
            {
                var dumplicated = tcdmse.dict_RegionInfo.AsNoTracking().Where(p => p.RegionPID == dto.RegionPID && p.RegionName == dto.RegionName).FirstOrDefault();
                if (dumplicated != null)
                {
                    throw new Exception("新增行政区域不可同名!");
                }
                var newregion = new dict_RegionInfo();
                newregion = Mapper.Map <RegionOperateDTO, dict_RegionInfo>(dto);
                tcdmse.dict_RegionInfo.Add(newregion);
                result = tcdmse.SaveChanges() > 0;
            }

            return(result);
        }