Пример #1
0
 /// <summary>
 /// 编辑分控信息
 /// </summary>
 /// <param name="cache">当前操作用户的缓存</param>
 /// <param name="datas">待编辑的数据集合</param>
 /// <returns></returns>
 public OperationResult EditSubControls(CacheUser cache, params SubControlInputDto[] datas) => SubControlRepository.Update(datas,
                                                                                                                           checkAction: (dto, entity) =>
 {
     if (dto.SubNum != entity.SubNum)
     {
         if (SubControlRepository.CheckExists(m => m.SubNum == dto.SubNum && m.LigthPoleOne_Id == dto.LigthPoleOne_Id))
         {
             throw new Exception($"id:分控编号{dto.SubNum}已经存在!不能在同一台主机上添加相同的分控编号");
         }
     }
 },
                                                                                                                           updateFunc: (dto, entity) =>
 {
     var aggregation = SubAggregationRepository.Entities.FirstOrDefault(m => m.SubControl_Id == entity.Id);
     if (aggregation.LightPole_Id != entity.LigthPoleOne_Id)
     {
         var poleone = LightPoleRepository.Entities.FirstOrDefault(m => m.Id == entity.LigthPoleOne_Id);
         if (poleone == null)
         {
             throw new Exception("id:分控关联的灯杆不存在");
         }
         aggregation.LightPole_Id = entity.LigthPoleOne_Id;
         aggregation.Host_Id      = poleone.Host_Id;
         aggregation.Organzie_Id  = poleone.HostOne.Organize_Id;
         SubAggregationRepository.Update(aggregation);
     }
     return(entity);
 });
Пример #2
0
        /// <summary>
        /// 添加分控信息
        /// </summary>
        /// <param name="cache">当前操作用户的缓存</param>
        /// <param name="datas">待添加的数据集合</param>
        /// <returns></returns>
        public OperationResult AddSubControls(CacheUser cache, params SubControlInputDto[] datas)
        {
            int count = 0;

            SubAggregationRepository.UnitOfWork.BeginTransaction();
            foreach (var data in datas)
            {
                SubControl sub = data.MapTo <SubControl>();
                sub.CreatedTime = DateTime.Now;
                var poleone = LightPoleRepository.Entities.FirstOrDefault(m => m.Id == sub.LigthPoleOne_Id);
                if (poleone == null)
                {
                    throw new Exception("id:指定灯杆信息不存在");
                }
                if (SubControlRepository.CheckExists(m => m.SubNum == data.SubNum && m.LigthPoleOne.Host_Id == poleone.Host_Id))
                {
                    throw new Exception($"id:分控编号{data.SubNum}已经存在!不能在同一台主机上添加相同的分控编号");
                }
                if (poleone == null)
                {
                    throw new Exception("id:分控关联的灯杆不存在");
                }
                SubAggregation aggregation = new SubAggregation
                {
                    CreatedTime   = DateTime.Now,
                    SubControlOne = sub,
                    LightPole_Id  = sub.LigthPoleOne_Id,
                    Host_Id       = poleone.Host_Id,
                    Organzie_Id   = poleone.HostOne.Organize_Id
                };
                count += SubAggregationRepository.Insert(aggregation);
            }
            ;
            SubAggregationRepository.UnitOfWork.Commit();
            return(count > 0 ? new OperationResult(OperationResultType.Success, $"成功添加{count/2}条数据") :
                   new OperationResult());
        }