public virtual async Task <long> AddAsync(Entity entity) { entity.CreatedDate = DateTime.UtcNow; entity.UpdatedDate = entity.CreatedDate; CreatePropertyIgnore(entity); await Db.AddAsync(entity); await Db.SaveChangesAsync(); return(entity.Id); }
public async Task <List <User> > BulkImportEmails(List <User> newUsers) { var foundUsers = await _userManager.Users.Where(x => newUsers.Select(u => u.Email.ToUpper()).Contains(x.NormalizedEmail)).Select(x => x.NormalizedEmail).ToListAsync(); var usersToInsert = newUsers.Where(x => !foundUsers.Contains(x.Email.ToUpper())).ToList(); foreach (var user in usersToInsert) { user.CreatedDate = DateTime.UtcNow; user.UserName = user.Email; user.NormalizedEmail = _userManager.NormalizeEmail(user.Email); user.NormalizedUserName = _userManager.NormalizeName(user.Email); user.EmailConfirmed = false; user.AccessFailedCount = 0; user.PhoneNumberConfirmed = false; await _db.AddAsync(user); } await _db.SaveChangesAsync(); return(newUsers); }