public static Customer CheckNewWeAccount(UserInfo userInfo) { var existCustomer = GetByopenId(userInfo.OpenId); //如果用户不存在,则在第一次检查的时候保存用户信息 if (existCustomer == null) { var customer = new Customer { OpenId = userInfo.OpenId, NickName = userInfo.NickName, HeadImgUrl = userInfo.HeadImgUrl, Sex = int.Parse(userInfo.Sex), CreatorTime = DateTime.Now, Country = userInfo.Country, City = userInfo.City, Province = userInfo.Province }; using (var db = new DanfossDbEntities()) { db.Customer.Add(customer); db.SaveChanges(); } return(customer); } return(null); }
/// <summary> /// 添加用户信息 /// </summary> /// <param name="model"></param> public static void AddCustomer(Customer model) { using (var db = new DanfossDbEntities()) { db.Customer.Add(model); db.SaveChanges(); } }
/// <summary> /// 增加分享次数 /// </summary> /// <param name="log"></param> public static void AddSharesLog(SharesLog log) { using (var db = new DanfossDbEntities()) { var model = db.SharesLog.FirstOrDefault(o => o.OpenId == log.OpenId); if (model != null) { model.Shares += 1; db.SharesLog.Attach(model); db.Entry(model).State = EntityState.Modified; } else { db.SharesLog.Add(log); } db.SaveChanges(); } }
/// <summary> /// 增加邮件发送记录 /// </summary> /// <param name="log"></param> public static void AddSendEmailLog(SendEmailLog log) { try { using (var db = new DanfossDbEntities()) { var model = db.Customer.FirstOrDefault(o => o.OpenId == log.OpenId); if (model != null) { model.Email = log.Email; db.Customer.Attach(model); db.Entry(model).State = EntityState.Modified; } db.SendEmailLog.Add(log); db.SaveChanges(); } } catch (Exception ex) { Lgr.Log.Error(ex.Message, ex); } }