Пример #1
0
        public async static Task SaveLivingIndexData(string html, XmlNode xmlRoot, BizDataContext db)
        {
            var rootNode = CommonHelper.GetRootNode(html);

            //获取对实体解析的配置节点
            var infoConfig = xmlRoot.SelectSingleNode("LivingIndexConfig");

            var date = DateTime.Now;


            var entity = new T_HTZ_LivingIndex();


            //解析应该包含多个子节点,每个子节点表示一个属性,这里进行循环赋值
            foreach (XmlNode property in infoConfig.ChildNodes)
            {
                entity = CommonHelper.GetProperty(entity, rootNode, property);
            }

            //查询天气数据
            var dbentity = (from a in db.Set<T_HTZ_LivingIndex>()

                            where a.CreateTime == DateTime.Now.Date

                            select a).FirstOrDefault();

            if (dbentity != null)
            {
                entity.HTZ_LivingIndex_Id = dbentity.HTZ_LivingIndex_Id;
                entity.CreateTime = dbentity.CreateTime;
                entity.UpdateTime = DateTime.Now;

                await db.UpdateAsync(entity);
            }
            else
            {
                entity.HTZ_LivingIndex_Id = db.GetNextIdentity_Int();
                entity.CreateTime = DateTime.Now.Date;

                await db.InsertAsync(entity);
            }

        }