public void Process(DataCollectorRegistered @event)
        {
            var dataCollector = new Read.DataCollectors.DataCollector(
                @event.DataCollectorId, @event.FullName, @event.DisplayName, @event.YearOfBirth, @event.Sex,
                @event.PreferredLanguage, @event.LocationLongitude, @event.LocationLatitude, @event.RegisteredAt, @event.Region, @event.District);

            _dataCollectorsEventHandler.Handle(dataCollector);
        }
        public void Process(DataCollectorRegistered @event, EventSourceId dataCollectorId)
        {
            var dataCollector = _repositoryForDataCollector.GetById(dataCollectorId.Value); //why do we do this?

            dataCollector = new DataCollector()
            {
                Id          = dataCollectorId.Value,
                DisplayName = @event.DisplayName,
                Location    = new Concepts.Location(@event.LocationLatitude, @event.LocationLongitude),
                Region      = @event.Region,
                District    = @event.District,
                Village     = null //Event currently not supporting Village
            };
            _repositoryForDataCollector.Insert(dataCollector);
        }
Exemple #3
0
        public IActionResult Register([FromBody] Read.DataCollectors.DataCollector dataCollector)
        {
            var command = new RegisterDataCollector
            {
                DataCollectorId   = Guid.NewGuid(),
                IsNewRegistration = true,
                RegisteredAt      = DateTimeOffset.UtcNow,
                PhoneNumbers      = dataCollector.PhoneNumbers.Select(pn => pn.Value),
                DisplayName       = dataCollector.DisplayName,
                FullName          = dataCollector.FullName,
                GpsLocation       = dataCollector.Location,
                NationalSociety   = dataCollector.NationalSociety,
                PreferredLanguage = dataCollector.PreferredLanguage,
                Sex         = dataCollector.Sex,
                YearOfBirth = dataCollector.YearOfBirth
            };

            _dataCollectorCommandHandler.Handle(command);
            return(Ok());
        }
Exemple #4
0
        public IActionResult Update([FromBody] Read.DataCollectors.DataCollector dataCollector)
        {
            // TODO: Woksin (10/04/18): Hmm, I'm thinking here, maybe send the original DataCollector with command
            // to compare fields, and from there the AggregateRoot can decide which fields to update? @einari
            var command = new RegisterDataCollector
            {
                DataCollectorId   = dataCollector.DataCollectorId,
                IsNewRegistration = false,
                RegisteredAt      = dataCollector.RegisteredAt,
                PhoneNumbers      = dataCollector.PhoneNumbers.Select(pn => pn.Value),
                DisplayName       = dataCollector.DisplayName,
                FullName          = dataCollector.FullName,
                GpsLocation       = dataCollector.Location,
                NationalSociety   = dataCollector.NationalSociety,
                PreferredLanguage = dataCollector.PreferredLanguage,
                Sex         = dataCollector.Sex,
                YearOfBirth = dataCollector.YearOfBirth
            };

            _dataCollectorCommandHandler.Handle(command);
            return(Ok());
        }
Exemple #5
0
        public void Process(DataCollectorRegistered @event, EventSourceId dataCollectorId)
        {
            // insert data collector
            var dataCollector = new DataCollector(
                dataCollectorId.Value,
                @event.RegisteredAt,
                @event.Region,
                @event.District,
                new Location(@event.LocationLatitude, @event.LocationLongitude),
                (Sex)@event.Sex);

            _dataCollectors.Insert(dataCollector);

            var region   = _repositoryForRegion.Query.FirstOrDefault(_ => _.Name == @event.Region);
            var district = _repositoryForDistrict.Query.FirstOrDefault(_ => _.Name == @event.District);

            if (region == null)
            {
                // if region doesn't exist, create it
                region = new Region()
                {
                    Id   = Guid.NewGuid(),
                    Name = @event.Region
                };
                _repositoryForRegion.Insert(region);
            }

            if (district == null)
            {
                // create if doesn't exist
                district = new District()
                {
                    Id       = Guid.NewGuid(),
                    Name     = @event.District,
                    RegionId = region.Id
                };
                _repositoryForDistrict.Insert(district);
            }
        }
Exemple #6
0
 public async Task SaveAsync(DataCollector dataCollector)
 {
     await _collection.ReplaceOneAsync(d => d.DataCollectorId == dataCollector.DataCollectorId, dataCollector, new UpdateOptions { IsUpsert = true });
 }
Exemple #7
0
 public void Save(DataCollector dataCollector)
 {
     _collection.ReplaceOne(d => d.DataCollectorId == dataCollector.DataCollectorId, dataCollector, new UpdateOptions {
         IsUpsert = true
     });
 }
Exemple #8
0
        public async Task Save(DataCollector dataCollector)
        {
            var filter = Builders <DataCollector> .Filter.Eq(c => c.Id, dataCollector.Id);

            await _collection.ReplaceOneAsync(filter, dataCollector, new UpdateOptions { IsUpsert = true });
        }