/// <summary> /// 判断当前用户名称是否存在。 /// </summary> /// <param name="user">用户实例。</param> /// <returns>返回判断结果。</returns> public virtual IdentityResult IsDuplicated(TUser user) { if (user.UserName != null && UserContext.Any(x => x.UserId != user.UserId && x.UserName == user.UserName)) { return(IdentityResult.Failed(ErrorDescriber.DuplicateUserName(user.UserName))); } if (user.NormalizedUserName != null && UserContext.Any(x => x.UserId != user.UserId && x.NormalizedUserName == user.NormalizedUserName)) { return(IdentityResult.Failed(ErrorDescriber.DuplicateUserName(user.NormalizedUserName))); } return(IdentityResult.Success); }
public BookResult[] Books(UserContext context) { var user = context.ValidateUser(); var books = UserContext.GetAllShallow <Book>(); var searchQl = "query{dummy{user{id} book{id author title cover length} value lastPlayed id}}"; var progresses = new UserContext(searchQl).Search <Progress>(expr => expr.Filter(item => item.G("User") == user.Id.ToString())).ToList(); foreach (var book in books) { if (progresses.Any(d => d.Book.Id == book.Id)) { continue; } var progress = new Progress(book, user, 0, DateTime.Parse("1970-01-01")); UserContext.AddDefault(progress); progresses.Add(progress); } var ret = progresses.Select(d => new BookResult(d)).ToArray(); return(ret); }