Beispiel #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);
        }
        public ENodeb UpdateTownInfo(int eNodebId, int townId)
        {
            var eNodeb = _eNodebRepository.FirstOrDefault(x => x.ENodebId == eNodebId);

            if (eNodeb == null)
            {
                return(null);
            }
            eNodeb.TownId = townId;
            _eNodebRepository.SaveChanges();
            return(eNodeb);
        }