Exemplo n.º 1
0
        public void Subscribe(string openId)
        {
            Entities entity = new Entities();
            var      model  = entity.OpenIdsInfo.FirstOrDefault(p => p.OpenId == openId);

            if (model == null)
            {
                model               = new Model.OpenIdsInfo();
                model.OpenId        = openId;
                model.SubscribeTime = DateTime.Now;
                model.IsSubscribe   = true;
                entity.OpenIdsInfo.Add(model);
                entity.Configuration.ValidateOnSaveEnabled = false;
                entity.SaveChanges();
                entity.Configuration.ValidateOnSaveEnabled = true;
            }
            else
            {
                if (!model.IsSubscribe)
                {
                    model.IsSubscribe = true;
                    entity.Configuration.ValidateOnSaveEnabled = false;
                    entity.SaveChanges();
                    entity.Configuration.ValidateOnSaveEnabled = true;
                }
            }
        }
Exemplo n.º 2
0
        public void UnSubscribe(string openId)
        {
            Entities entity = new Entities();
            var      model  = entity.OpenIdsInfo.FirstOrDefault(p => p.OpenId == openId);

            if (model != null)
            {
                model.IsSubscribe = false;
                entity.SaveChanges();
            }
            else
            {
                model               = new Model.OpenIdsInfo();
                model.OpenId        = openId;
                model.SubscribeTime = DateTime.Now;
                model.IsSubscribe   = false;
                entity.OpenIdsInfo.Add(model);
                entity.SaveChanges();
            }
        }