/// <summary> /// /// </summary> /// <param name="openID"></param> /// <returns></returns> public OpenIDBinding GetBindingByOpenID(string openID) { ExceptionHelper.CheckStringIsNullOrEmpty(openID, "openID"); ORMappingItemCollection mappings = ORMapping.GetMappingInfo(typeof(OpenIDBinding)); string sql = string.Format("SELECT * FROM {0} WHERE OPEN_ID = {1}", mappings.TableName, TSqlBuilder.Instance.CheckUnicodeQuotationMark(openID)); DataTable table; using (DbContext context = DbContext.GetContext(DataAdapter.DBConnectionName)) { Database db = DatabaseFactory.Create(DataAdapter.DBConnectionName); table = db.ExecuteDataSet(CommandType.Text, sql).Tables[0]; } OpenIDBinding binding = null; if (table.Rows.Count > 0) { binding = new OpenIDBinding(); ORMapping.DataRowToObject(table.Rows[0], binding); } return(binding); }
/// <summary> /// 保存OpenIDBinding /// </summary> /// <param name="binding"></param> public void SaveOpenIDBinding(OpenIDBinding binding) { binding.NullCheck("binding"); string sql = ORMapping.GetInsertSql(binding, TSqlBuilder.Instance); using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { using (DbContext context = DbContext.GetContext(DataAdapter.DBConnectionName)) { Database db = DatabaseFactory.Create(DataAdapter.DBConnectionName); try { db.ExecuteNonQuery(CommandType.Text, sql); } catch (SqlException ex) { if (ex.Number == 2627) { throw new OpenIDBindingException(Translator.Translate(Define.DefaultCategory, "OpenID已经绑定到某用户了,不能重复绑定")); } throw; } } scope.Complete(); } }