/// <summary> /// 批量添加 /// </summary> /// <param name="PositionRequest"></param> /// <returns></returns> public BasicResponse AddPositions(PositionsRequest PositionRequest) { BasicResponse Result = new BasicResponse(); List <Jc_WzInfo> items = PositionRequest.PositionsInfo; List <Jc_WzInfo> PositionCaches = new List <Jc_WzInfo>(); Jc_WzInfo olditem = null; PositionCacheGetAllRequest positionCacheRequest = new PositionCacheGetAllRequest(); var result = _PositionCacheService.GetAllPositongCache(positionCacheRequest); PositionCaches = result.Data; foreach (Jc_WzInfo item in items) { olditem = PositionCaches.Find(a => a.WzID == item.WzID); //增加重复判断 if (result.Data != null) { //缓存中存在此测点 Result.Code = 1; Result.Message = "当前添加的安装位置已存在!"; return(Result); } } TransactionsManager.BeginTransaction(() => { foreach (Jc_WzInfo item in items) { //保存数据库 var _jc_Wz = ObjectConverter.Copy <Jc_WzInfo, Jc_WzModel>(item); var resultjc_Wz = _Repository.AddPosition(_jc_Wz); } //保存缓存 PositionCacheBatchAddRequest BatchAddPositionCacheRequest = new PositionCacheBatchAddRequest(); BatchAddPositionCacheRequest.PositionInfos = items; _PositionCacheService.BatchAddPositionCache(BatchAddPositionCacheRequest); }); return(Result); }
public BasicResponse BatchAddPositionCache(PositionCacheBatchAddRequest positionCacheRequest) { PositionCache.PositionCahceInstance.AddItems(positionCacheRequest.PositionInfos); return(new BasicResponse()); }