public UserCode GetUserCode(string code, UserCodeType userCodeType) { return(Repository.Where(x => x.Code == code && x.CodeType == userCodeType) .Join <User>("UserId", "Id", joinType: JoinType.LeftOuter) .Relate(RelationTypes.OneToOne <UserCode, User>()) .SelectNested() .FirstOrDefault()); }
public UserCode GetUserCodeByEmail(string email, UserCodeType userCodeType) { var userCode = Repository.Where(x => x.Email == email && x.CodeType == userCodeType) .Select() .FirstOrDefault() ?? new UserCode(); userCode.Code = Guid.NewGuid().ToString("D"); userCode.CodeType = userCodeType; userCode.CreatedOn = DateTime.UtcNow; userCode.Email = email; InsertOrUpdate(userCode); return(userCode); }
public UserCode GetUserCode(int userId, UserCodeType userCodeType) { var userCode = Repository.Where(x => x.UserId == userId && x.CodeType == userCodeType) .Join <User>("UserId", "Id", joinType: JoinType.LeftOuter) .Relate(RelationTypes.OneToOne <UserCode, User>()) .SelectNested() .FirstOrDefault() ?? new UserCode(); userCode.UserId = userId; userCode.Code = userCodeType == UserCodeType.EmailOtp ? _cryptographyService.GetNumericCode(6) : Guid.NewGuid().ToString("D"); userCode.CodeType = userCodeType; userCode.CreatedOn = DateTime.UtcNow; InsertOrUpdate(userCode); return(userCode); }
/// <summary>验证数据,通过抛出异常的方式提示验证失败。</summary> /// <param name="isNew">是否插入</param> public override void Valid(Boolean isNew) { // 如果没有脏数据,则不需要进行任何处理 if (!HasDirty) { return; } // 这里验证参数范围,建议抛出参数异常,指定参数名,前端用户界面可以捕获参数异常并聚焦到对应的参数输入框 if (ClientId.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(ClientId), "ClientId不能为空!"); } if (ProtocolType.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(ProtocolType), "ProtocolType不能为空!"); } if (ClientName.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(ClientName), "ClientName不能为空!"); } if (Description.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(Description), "Description不能为空!"); } if (ClientUri.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(ClientUri), "ClientUri不能为空!"); } if (LogoUri.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(LogoUri), "LogoUri不能为空!"); } if (FrontChannelLogoutUri.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(FrontChannelLogoutUri), "FrontChannelLogoutUri不能为空!"); } if (BackChannelLogoutUri.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(BackChannelLogoutUri), "BackChannelLogoutUri不能为空!"); } if (ClientClaimsPrefix.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(ClientClaimsPrefix), "ClientClaimsPrefix不能为空!"); } if (PairWiseSubjectSalt.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(PairWiseSubjectSalt), "PairWiseSubjectSalt不能为空!"); } if (Created.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(Created), "Created不能为空!"); } if (Updated.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(Updated), "Updated不能为空!"); } if (LastAccessed.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(LastAccessed), "LastAccessed不能为空!"); } if (UserCodeType.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(UserCodeType), "UserCodeType不能为空!"); } // 在新插入数据或者修改了指定字段时进行修正 // 检查唯一索引 // CheckExist(isNew, __.ClientId); }