コード例 #1
0
        public int DumpNewEnodebExcels(IEnumerable <ENodebExcel> infos)
        {
            var containers = (from info in infos
                              join town in _townRepository.GetAllList()
                              on new { info.CityName, info.DistrictName, info.TownName } equals
                              new { town.CityName, town.DistrictName, town.TownName }
                              select new ENodebExcelWithTownIdContainer
            {
                ENodebExcel = info,
                TownId = town.Id
            }).ToArray();

            if (!containers.Any())
            {
                return(0);
            }
            var items =
                Mapper.Map <IEnumerable <ENodebExcelWithTownIdContainer>, List <ENodebWithTownIdContainer> >(containers);

            items.ForEach(x => { x.ENodeb.TownId = x.TownId; });

            var count = 0;

            foreach (var eNodeb in items.Select(x => x.ENodeb).ToList())
            {
                var item = _eNodebRepository.FirstOrDefault(x => x.ENodebId == eNodeb.ENodebId);
                if (item == null)
                {
                    var result = _eNodebRepository.Insert(eNodeb);
                    if (result != null)
                    {
                        count++;
                    }
                }
                else
                {
                    item.IsInUse = true;
                    item.Name    = eNodeb.Name;
                    item.Address = eNodeb.Address;
                    item.Factory = eNodeb.Factory;
                    _eNodebRepository.SaveChanges();
                }
            }
            _eNodebRepository.SaveChanges();
            return(count);
        }
コード例 #2
0
        public void Save(IEnumerable <ENodebExcel> eNodebInfoList, bool update)
        {
            IEnumerable <ENodebExcel> validInfos =
                eNodebInfoList.Where(x => infoFilter(x))
                .Distinct(new ENodebExcelComparer())
                .Distinct(new ENodebExcelNameComparer());

            foreach (ENodebExcel info in validInfos)
            {
                int        townId = _townList.QueryId(info);
                ENodebBase existedENodebWithSameName = _baseRepository.QueryENodeb(townId, info.Name);
                ENodebBase existedENodebWithSameId   = _baseRepository.QueryENodeb(info.ENodebId);
                if (existedENodebWithSameName == null && existedENodebWithSameId == null)
                {
                    ENodeb eNodeb = new ENodeb();
                    eNodeb.Import(info, townId);
                    _repository.Insert(eNodeb);
                    _infrastructure.ENodebInserted++;
                }
                if (!update)
                {
                    continue;
                }
                if (existedENodebWithSameId != null)
                {
                    ENodeb byIdENodeb = _repository.GetAll().FirstOrDefault(x => x.ENodebId == info.ENodebId);
                    if (byIdENodeb != null)
                    {
                        byIdENodeb.Import(info, townId, false);
                        _repository.Update(byIdENodeb);
                        _infrastructure.ENodebsUpdated++;
                    }
                }
                else if (existedENodebWithSameName != null)
                {
                    ENodeb byNameENodeb =
                        _repository.GetAll().FirstOrDefault(x => x.TownId == townId && x.Name == info.Name);
                    if (byNameENodeb != null)
                    {
                        byNameENodeb.Import(info, townId);
                        _repository.Update(byNameENodeb);
                        _infrastructure.ENodebsUpdated++;
                    }
                }
            }
        }
コード例 #3
0
 public void Put(ENodeb eNodeb)
 {
     _repository.Insert(eNodeb);
 }