public Customer ProcessWechatUserFetching(WxOauthAccessToken wxOauthAccessToken, WxUserInfo wxUserInfo) { if (wxOauthAccessToken == null || wxUserInfo == null || string.IsNullOrEmpty(wxOauthAccessToken.openid)) return null; var customer = FindByOpenId(wxOauthAccessToken.openid); if (customer != null && string.IsNullOrEmpty(customer.Nickname) == false) return customer; customer = new Customer { UpdateDate = DateTime.Now, UpdateBy = "Wechat API", Cellphone = "", City = wxUserInfo.city, Country = wxUserInfo.country, Province = wxUserInfo.province, CreateBy = "API", CreateDate = DateTime.Now, Email = "", Gender = wxUserInfo.sex, HeadImgUrl = wxUserInfo.headimgurl, Name = null, Nickname = wxUserInfo.nickname, OpenId = wxUserInfo.openid, UnionId = wxUserInfo.unionid }; return Save(customer); }
public Customer Save(Customer customer) { if (string.IsNullOrEmpty(customer.Nickname)) return null; if (customer.CustomerId == 0) Ctx.Insert("Customer", customer).AutoMap(x => x.CustomerId).Execute(); else Ctx.Update("Customer", customer).Execute(); return customer; }