public async Task <int> Handle(ImportObserversRequest message, CancellationToken token) { var counter = 0; var startId = GetMaxIdObserver(); using (var reader = new StreamReader(message.File.OpenReadStream())) { while (reader.Peek() >= 0) { var fileContent = reader.ReadLine(); var data = fileContent.Split('\t'); var hashed = _hashService.GetHash(data[1]); var observer = new Entities.Observer { Id = startId + counter, IdNgo = message.IdOng, Phone = data[0], Name = data[2], Pin = hashed }; _context.Observers.Add(observer); counter++; } await _context.SaveChangesAsync(); } return(counter); }
public async Task <int> Handle(NewObserverCommand message, CancellationToken token) { var id = GetMaxIdObserver(); var observer = new Entities.Observer { Id = id, IdNgo = message.IdNgo, Phone = message.Phone, Name = message.Name, Pin = _hashService.GetHash(message.Pin) }; _context.Observers.Add(observer); await _context.SaveChangesAsync(); return(observer.Id); }
private RandomObserverBuilder(IHashService hashService) { _hashService = hashService; _observer = new Entities.Observer(); }