public bool UpdateUser() { try { var data = DbSession.AppUserRepository.Get(u => u.auto_id == 1238059796469518336); var datas = DbSession.AppUserRepository.Get(u => u.auto_id == 1238060022513143808); DbSession.Transaction(dt => { data.nick_name = "123"; DbSession.AppUserRepository.Update(data, dt); datas.nick_name = "432"; DbSession.AppUserRepository.Update(datas, dt); throw new NotImplementedException(); }); } catch (Exception) { throw; } return(false); }
/// <summary> /// 用户登录 /// </summary> /// <param name="loginRequest"></param> /// <returns></returns> public BaseResponse <LoginResponse> Login(LoginRequest loginRequest) { //通过微信id登录 if (loginRequest.LoginType == LoginTypeEnum.WechatOpenID) { var result = DbSession.WebUserRepository.Get(u => u.user_wid == loginRequest.WechatOpenID); //准备一个登录凭证 WebUserTokenRequest tokenAdd = new WebUserTokenRequest(); tokenAdd.guids = Guid.NewGuid().ToString(); tokenAdd.login_date = DateTime.Now; tokenAdd.expirydate = tokenAdd.login_date.AddDays(10); if (result != null) { //找到登录凭证需要创建登录凭证 var tokeninfo = _webUserTokenSvervice.GetWebUserToken(result.user_id); //未找到登录凭证 if (tokeninfo == null) { tokenAdd.web_userid = result.user_id; tokenAdd.web_usertoken = EncryptionFactory.Md5Encrypt(result.user_id); var tokenInfo = _webUserTokenSvervice.CreateToken(tokenAdd); return(Response(new LoginResponse() { Token = tokenInfo.web_usertoken }, true)); } else { tokenAdd.web_userid = result.user_id; tokenAdd.web_usertoken = EncryptionFactory.Md5Encrypt(result.user_id); DbSession.Transaction(dt => { DbSession.WebUserTokenRepository.Delete(u => u.web_userid == result.user_id, false, transaction: dt); DbSession.WebUserTokenRepository.Add(tokenAdd.MapTo <WebUserToken>(), transaction: dt); }); return(Response(new LoginResponse() { Token = tokenAdd.web_usertoken }, true)); } } else { WebUserRequest webUserAdd = new WebUserRequest(); webUserAdd.user_id = Guid.NewGuid().ToString(); webUserAdd.user_wid = loginRequest.WechatOpenID; webUserAdd.user_regdate = DateTime.Now; webUserAdd.user_state = 0; //创建一个登录账号 var webUserAddResult = DbSession.WebUserRepository.Add(webUserAdd.MapTo <WebUser>()); if (!webUserAddResult) { AppException(AppErrorEnum.LoginError); } //创建登录凭证 tokenAdd.web_userid = webUserAdd.user_id; tokenAdd.web_usertoken = EncryptionFactory.Md5Encrypt(webUserAdd.user_id); var tokenInfo = _webUserTokenSvervice.CreateToken(tokenAdd); return(Response(new LoginResponse() { Token = tokenAdd.web_usertoken }, true)); } } //通过账号密码登录 else if (loginRequest.LoginType == LoginTypeEnum.Account) { } return(null); }