public void AddDoubanConfig(string groupId, string cityName)
        {
            if (string.IsNullOrEmpty(groupId) || string.IsNullOrEmpty(cityName))
            {
                throw new Exception("请输入豆瓣小组Group和城市名称。");
            }
            var topics = DoubanService.GetHouseData(groupId, cityName, 1);

            if (topics == null)
            {
                throw new Exception("保存失败!请检查豆瓣小组ID(如:XMhouse)/城市名称(如:厦门)是否正确...");
            }
            var json = $"{{ 'groupid':'{groupId}','cityname':'{cityName}','pagecount':5}}";

            if (_dataContext.Configs.Any(c => c.City == cityName && c.Source == ConstConfigName.Douban && c.Json == json))
            {
                return;
            }
            var config = new DBConfig()
            {
                Id         = Tools.GetUUId(),
                Json       = json,
                City       = cityName,
                Source     = ConstConfigName.Douban,
                CreateTime = DateTime.Now,
                PageCount  = 10
            };

            _dataContext.Configs.Add(config);
            _dataContext.SaveChanges();
            return;
        }
예제 #2
0
        public UserHouse AddOne(UserHouse newOne)
        {
            if (newOne == null)
            {
                throw new UnProcessableException("object can not empty.");
            }
            // todo check newOne field:title,text,price latitude,throw UnProcessableException

            if (CheckLastHousePubtime(newOne))
            {
                throw new UnProcessableException("7天只允许发布一条房源信息.");
            }
            newOne.Id = Tools.GetUUId();
            _context.UserHouses.Add(newOne);
            _context.SaveChanges();
            return(newOne);
        }
예제 #3
0
        public UserHouse AddOne(UserHouse newOne)
        {
            if (newOne == null)
            {
                throw new UnProcessableException("object can not empty.");
            }

            _context.UserHouses.Add(newOne);
            _context.SaveChanges();
            return(newOne);
        }
예제 #4
0
        public DBUserCollection AddOne(long userId, string houseId)
        {
            var house = _houseService.FindById(houseId);

            if (house == null)
            {
                throw new NotFoundException("房源信息不存在,请刷新页面后重试");
            }
            if (_context.UserCollections.Any(c => c.HouseID == houseId && c.UserID == userId))
            {
                throw new UnProcessableException("房源信息已收藏.");
            }
            var collection = new DBUserCollection();

            collection.Source     = house.Source;
            collection.Title      = house.Title;
            collection.OnlineURL  = house.OnlineURL;
            collection.City       = house.City;
            collection.Id         = Tools.GetUUId();
            collection.CreateTime = DateTime.Now;
            _context.UserCollections.Add(collection);
            _context.SaveChanges();
            return(collection);
        }