public async Task <Response <bool> > ForgetPassword(AccountInput input) { ValidateHelper.Begin() .IsEmail(input.Email); _memberSerevice = new MemberSerevice(); return(await _memberSerevice.ForgetPassword(input.Email)); }
public async Task <Response <bool> > UpdatePassword(UpdatePasswordInput input) { //確保資訊安全傳輸有幾種方式 // 1. 以網路層擋,僅限定特定IP讀取 // 2. 透過token協定 ValidateHelper.Begin() .IsPasswordFomat(input.Password) .NotNull(input.Token); _memberSerevice = new MemberSerevice(); return(await _memberSerevice.UpdatePassword(input)); }
/// <summary> /// 根据角色代码删除角色 /// </summary> /// <param name="roleCodes">角色代码,eg:1,2,3</param> /// <returns>操作是否成功</returns> /// 时间:2016-04-29 10:22 /// 备注: public bool DeleteRoleByCode(string roleCodes) { ValidateHelper.Begin().NotNullOrEmpty(roleCodes, "角色代码,eg:1,2,3"); string _sql = "exec('delete from Roles where R_Code in ('+@code+')')"; SqlParameter[] _paramter = new SqlParameter[1]; _paramter[0] = new SqlParameter("@code", SqlDbType.VarChar, -1) { Value = roleCodes }; return(sqlHelper.ExecuteNonQuery(_sql, _paramter) > 0); }
public void Register(string name, string email, int age) { name = "mm"; email = "*****@*****.**"; age = 20; var v = ValidateHelper.Begin() .NotNull(name) .NotNull(email) .InRange(age, 18, 120) .IsEmail(email); bool a = v.IsValid; }
/// <summary> /// 获取指定区域的缓存执行者实例 /// </summary> public static ICache GetCacher(string region) { ValidateHelper.Begin().NotNullOrEmpty(region, "缓存区域名称"); ICache cache; if (Cachers.TryGetValue(region, out cache)) { return(cache); } cache = new InternalCacher(region); Cachers[region] = cache; return(cache); }
/// <summary> /// 设置缓存提供者 /// </summary> /// <param name="provider">缓存提供者</param> /// <param name="level">缓存级别</param> public static void SetProvider(ICacheProvider provider, CacheLevel level) { ValidateHelper.Begin().NotNull(provider, "缓存提供者"); switch (level) { case CacheLevel.First: Providers[0] = provider; break; case CacheLevel.Second: Providers[1] = provider; break; } }
/// <summary> /// 保存角色权限设置 /// </summary> /// <param name="roleName">角色名称</param> /// <param name="roleCode">角色代码</param> /// <param name="modulePermissionId">模块操作标识ID数组</param> /// <returns> /// 保存是否成功 /// </returns> /// 时间:2016-04-29 10:25 /// 备注: public bool UpdateRole(string roleName, string roleCode, string[] modulePermissionId) { ValidateHelper.Begin().NotNullOrEmpty(roleName, "角色名称").NotNullOrEmpty(roleCode, "角色代码").NotNull(modulePermissionId, "角色对应模块操作标识ID数组"); bool _result = false; using (SqlServerTransaction sqlTran = sqlHelper.BeginTranscation()) { try { SqlParameter[] _paramter = new SqlParameter[1]; _paramter[0] = new SqlParameter("@roleCode", roleCode); sqlHelper.ExecuteNonQuery(sqlTran, "delete from RolePermissions where R_Code=@roleCode;", _paramter); _paramter = new SqlParameter[3]; _paramter[0] = new SqlParameter("@roleCode", roleCode); _paramter[1] = new SqlParameter("@roleName", roleName); _paramter[2] = new SqlParameter("@roleCodeWhere", roleCode); sqlHelper.ExecuteNonQuery(sqlTran, "update Roles set R_Code=@roleCode,R_Name=@roleName where R_Code=@roleCodeWhere", _paramter); foreach (string s in modulePermissionId) { if (!string.IsNullOrEmpty(s)) { _paramter = new SqlParameter[2]; _paramter[0] = new SqlParameter("@roleCode", roleCode); _paramter[1] = new SqlParameter("@mpId", s); sqlHelper.ExecuteNonQuery(sqlTran, "insert into dbo.RolePermissions values(@roleCode,@mpId)", _paramter); } } sqlTran.CommitTransaction(); _result = true; } catch (Exception) { sqlTran.RollbackTransaction(); _result = false; } return(_result); } }
public async Task <Response <string> > Login(LoginInput input) { try { ValidateHelper.Begin() .IsPasswordFomat(input.Password) .IsEmail(input.Email); _memberSerevice = new MemberSerevice(); var result = await _memberSerevice.Login(input); return(result); } catch (Exception e) { return(new Response <string>() { Success = false, Message = e.Message, }); } }
/// <summary> /// 获取所有角色对应的模块操作权限列表 /// </summary> /// <typeparam name="T">泛型</typeparam> /// <param name="roleCode">角色代码</param> /// <returns> /// 集合 /// </returns> /// 时间:2016-04-29 10:24 /// 备注: public List <T> GetRolePermission <T>(string roleCode) where T : RolePermission, new() { ValidateHelper.Begin().NotNullOrEmpty(roleCode, "角色代码"); string _sql = "select [Id],[R_Code],[MP_Id] from RolePermissions where R_Code=@code"; DbParameter[] _paramter = new DbParameter[1]; _paramter[0] = new SqlParameter("@code", roleCode); using (IDataReader reader = sqlHelper.ExecuteReader(_sql, _paramter)) { List <T> _roles = new List <T>(); while (reader.Read()) { T _singleRP = new T(); _singleRP.Id = reader.GetValue <int>("Id", 0); _singleRP.RoleCode = reader.GetValue <string>("R_Code", string.Empty); _singleRP.ModulePermissionId = reader.GetValue <int>("MP_Id", 0); _roles.Add(_singleRP); } return(_roles); }; }
/// <summary> /// 设置缓存配置 /// </summary> /// <param name="cacheConfig">CacheConfig</param> /// 时间:2016-03-21 11:09 /// 备注: public static void SetCacheConfig(CacheConfig cacheConfig) { ValidateHelper.Begin().NotNull(cacheConfig, "CacheConfig缓存配置项"); CacheConfig = cacheConfig; }
/// <summary> /// 获取指定类型的缓存执行者实例 /// </summary> /// <param name="type">类型实例</param> public static ICache GetCacher(Type type) { ValidateHelper.Begin().NotNull(type, "类型实例"); return(GetCacher(type.FullName)); }
/// <summary> /// 构造函数 /// </summary> /// <param name="connectString">连接字符串</param> /// 时间:2016-01-19 16:21 /// 备注: public DapperHelper(string connectString) { ValidateHelper.Begin().NotNullOrEmpty(connectString, "连接字符串不能为空!"); ConnectString = connectString; }
private void CheckedParamter(string key) { ValidateHelper.Begin().NotNullOrEmpty(key, "缓存键"); }
private void CheckedParamter(string key, object value) { ValidateHelper.Begin().NotNullOrEmpty(key, "缓存键").NotNull(value, "缓存数据"); }
/// <summary> /// 构造函数,用于初始化sql Server数据连接 /// </summary> /// <param name="connectString">Sql Server连接字符串</param> /// 时间:2016-04-29 10:18 /// 备注: public SqlServerProvider(string connectString) { ValidateHelper.Begin().NotNullOrEmpty(connectString, "Sql Server连接字符串"); ConnectString = connectString; sqlHelper = new SqlServerHelper(connectString); }