/// <summary> /// 查询用户是否存在 /// username \ phone \ email 返回为true时,验证成功 /// </summary> /// <param name="username"></param> /// <returns></returns> private bool ExistUser(string username) { try { using (var db = new SQLServerDataContext()) { f_user user = null; user = (from x in db.f_user where x.username == username || x.phone == username || x.email == username select x).SingleOrDefault() ?? null; if (user == null) { return(false); } else { return(true); } } } catch (Exception ex) { LogHelper.Log.Error("用户不存在 " + ex.Message); return(false); } }
/// <summary> /// 用户注册 /// </summary> /// <param name="username"></param> /// <param name="pwd"></param> /// <param name="phone"></param> /// <param name="email"></param> /// <returns></returns> private bool Register(string username, string pwd, string phone, string email) { try { using (var db = new SQLServerDataContext()) { f_user option = null; option = (from x in db.f_user where x.username == username || x.phone == phone || x.email == email select x).SingleOrDefault() ?? null; if (null != option) { option.username = username; option.password = pwd; option.email = email; option.phone = phone; option.create_date = DateTime.Now; option.last_update_date = DateTime.Now; } else { option = new f_user() { username = username, password = pwd, phone = phone, email = email, create_date = DateTime.Now, last_update_date = DateTime.Now }; db.f_user.InsertOnSubmit(option); } db.SubmitChanges(); return(true); } } catch (Exception ex) { LogHelper.Log.Error("注册失败..." + ex.Message); return(false); } }