Example #1
0
 public void UpsertCustomer(AccessTokenResponse response)
 {
     using (var uow = GetUnitOfWork())
     {
         var customer =
             uow.Repository <ZY_Customer>()
             .Query()
             .Filter(x => x.OpenId == response.openid)
             .Get()
             .FirstOrDefault();
         if (customer == null)
         {
             customer = new ZY_Customer
             {
                 OpenId   = response.openid,
                 UserName = "",
                 TokenId  = response.access_token
             };
             uow.Repository <ZY_Customer>().Insert(customer);
         }
         else
         {
             customer.TokenId = response.access_token;
             uow.Repository <ZY_Customer>().Update(customer);
         }
         uow.Save();
         //todo load name
     }
 }
Example #2
0
        public void UpsertCustomer(AccessTokenResponse response)
        {
            using (var uow = GetUnitOfWork())
            {
                var customer =
                    uow.Repository <ZY_Customer>()
                    .Query()
                    .Filter(x => x.OpenId == response.openid)
                    .Get()
                    .FirstOrDefault();
                var userName     = "";
                var fname        = string.Format("{0}.jpg", Utility.Signature(response.openid));
                var headimg      = Path.Combine("upload", "wxhead", fname);
                var localheadimg = Path.Combine(HttpContext.Current.Server.MapPath("~"), "upload", "wxhead", fname);

                if (customer == null || string.IsNullOrEmpty(customer.UserName) || string.IsNullOrEmpty(customer.Avatar))
                {
                    var wxuser = WxApiHelper.Instance.GetWxUserInfo(response.openid, response.access_token);
                    if (wxuser != null)
                    {
                        userName = wxuser.nickname;
                        try
                        {
                            Utility.DownloadFile(wxuser.headimgurl, localheadimg);
                        }
                        catch
                        {
                            //

                            Debug.WriteLine(wxuser.headimgurl);
                            Debug.WriteLine(localheadimg);
                        }
                    }
                }
                else
                {
                    userName = customer.UserName;
                }
                if (customer == null)
                {
                    customer = new ZY_Customer
                    {
                        OpenId   = response.openid,
                        UserName = userName,
                        TokenId  = response.access_token,
                        Avatar   = headimg
                    };
                    uow.Repository <ZY_Customer>().Insert(customer);
                }
                else
                {
                    customer.TokenId  = response.access_token;
                    customer.UserName = userName;
                    customer.Avatar   = headimg;
                    uow.Repository <ZY_Customer>().Update(customer);
                }
                uow.Save();
            }
        }