Exemple #1
0
        /// <summary>
        /// 删除用户已获取的主机列表中的数据
        /// </summary>
        /// <param name="cachePageId">当前用户获取的主机列表缓存页主键</param>
        /// <param name="Ids">准备被删除的主键集合</param>
        /// <returns></returns>
        public OperationResult DeleteHosts(Guid[] cachePageId, params Guid[] Ids)
        {
            int count = 0;

            HostRepository.UnitOfWork.BeginTransaction();
            foreach (var i in Ids)
            {
                if (!cachePageId.Contains(i))
                {
                    throw new Exception($"id:主机{i}不存在或你未获取过该数据!");
                }

                count += HostRepository.DeleteDirect(i);

                // 删除关联该主机的分组信息
                var ditem1 = DataItemDetailRepository.Entities.FirstOrDefault(m => m.QueryCoding == "GroupType" && m.Index == 0);
                var grous  = GroupControlRepository.TrackEntities.Where(m => m.DataItemDetail_Id == ditem1.Id && m.ObjectId == i).ToList();
                GroupControlRepository.Delete(grous);

                // 删除主机关联的能耗信息
                var ditem2 = DataItemDetailRepository.Entities.FirstOrDefault(m => m.QueryCoding == "ECType" && m.Index == 0);
                var ect    = AnnualElectricityRepository.TrackEntities.Where(m => m.DataItemDetail_Id == ditem2.Id && m.ObjectId == i).ToList();
                AnnualElectricityRepository.Delete(ect);
            }
            HostRepository.UnitOfWork.Commit();
            if (count > 0)
            {
                return(new OperationResult(OperationResultType.Success, $"{count}条数据被删除"));
            }
            else
            {
                return(new OperationResult(OperationResultType.NoChanged, "请求被取消"));
            }
        }