public async Task <int> Handle(UpdatePollingSectionCommand message, CancellationToken cancellationToken) { try { var pollingStationInfo = await _context.PollingStationInfos .FirstOrDefaultAsync(a => a.IdObserver == message.IdObserver && a.IdPollingStation == message.IdPollingStation); if (pollingStationInfo == null) { throw new ArgumentException("PollingStationInfo nu exista"); } _mapper.Map(message, pollingStationInfo); _context.Update(pollingStationInfo); return(await _context.SaveChangesAsync()); } catch (Exception ex) { _logger.LogError(new EventId(), ex.Message); } return(-1); }
public async Task <Unit> Handle(UpdatePollingStationInfo request, CancellationToken cancellationToken) { try { var pollingStationInfo = _context.PollingStationInfos.FirstOrDefault( p => p.IdObserver == request.IdObserver && p.IdPollingStation == request.IdPollingStation); if (pollingStationInfo == null) { return(Unit.Value); } pollingStationInfo.ObserverLeaveTime = request.ObserverLeaveTime; pollingStationInfo.LastModified = DateTime.Now; _context.Update(pollingStationInfo); await _context.SaveChangesAsync(cancellationToken); return(Unit.Value); } catch (Exception ex) { _logger.LogError("Error updating polling station info: ", ex); throw; } }
public Task <int> Handle(ResetDeviceCommand request, CancellationToken cancellationToken) { try { var observerQuery = _voteMonitorContext.Observers .Where(o => o.Phone == request.PhoneNumber); if (!request.Organizer) { observerQuery = observerQuery.Where(o => o.IdNgo == request.IdNgo); } var observer = observerQuery.FirstOrDefault(); if (observer == null) { return(Task.FromResult(-1)); } observer.DeviceRegisterDate = null; observer.MobileDeviceId = null; _voteMonitorContext.Update(observer); return(_voteMonitorContext.SaveChangesAsync(cancellationToken)); } catch (Exception exception) { _logger.LogError("Exception caught during resetting of Observer device for id " + request.PhoneNumber, exception); } return(Task.FromResult(-1)); }
protected override Task <string> HandleCore(ResetPasswordCommand request) { try { Observer observer = _voteMonitorContext.Observers .Where(o => o.Phone == request.PhoneNumber && o.IdNgo == request.IdNgo) .First(); if (observer == null) { return(Task.FromResult(String.Empty)); } observer.Pin = RandomNumberGenerator.Generate(6); _voteMonitorContext.Update(observer); _voteMonitorContext.SaveChangesAsync(); return(Task.FromResult(observer.Pin)); } catch (Exception exception) { _logger.LogError("Exception caught during resetting of Observer password for id " + request.PhoneNumber, exception); } return(Task.FromResult(String.Empty)); }
protected override Task <int> HandleCore(ResetDeviceCommand request) { try { Observer observer = _voteMonitorContext.Observers .Where(o => o.Phone == request.PhoneNumber && o.IdNgo == request.IdNgo) .First(); if (observer == null) { return(Task.FromResult(-1)); } observer.DeviceRegisterDate = null; observer.MobileDeviceId = null; //observer.Pin = RandomNumberGenerator.Generate(6); _voteMonitorContext.Update(observer); return(_voteMonitorContext.SaveChangesAsync()); } catch (Exception exception) { _logger.LogError("Exception caught during resetting of Observer device for id " + request.PhoneNumber, exception); } return(Task.FromResult(-1)); }
public async Task <bool> Handle(ResetPasswordCommand request, CancellationToken cancellationToken) { try { var observerQuery = _voteMonitorContext.Observers .Where(o => o.Phone == request.PhoneNumber); if (!request.Organizer) { observerQuery = observerQuery.Where(o => o.IdNgo == request.IdNgo); } var observer = observerQuery.FirstOrDefault(); if (observer == null) { return(false); } observer.Pin = _hash.GetHash(request.Pin); _voteMonitorContext.Update(observer); await _voteMonitorContext.SaveChangesAsync(cancellationToken); return(true); } catch (Exception exception) { _logger.LogError("Exception caught during resetting of Observer password for id " + request.PhoneNumber, exception); } return(false); }
public async Task <int> Handle(UpdateOptionCommand request, CancellationToken cancellationToken) { try { var option = await _context.Options .FirstOrDefaultAsync(a => a.Id == request.Option.Id, cancellationToken); if (option == null) { throw new ArgumentException($"Can't find this option by id = {request.Option.Id}"); } _mapper.Map(request.Option, option); _context.Update(option); return(await _context.SaveChangesAsync(cancellationToken)); } catch (Exception ex) { _logger.LogError(new EventId(), ex.Message); } return(-1); }