コード例 #1
0
        public SensorEvent AddOrUpdate(SensorEventPOST viewModel)
        {
            //try to get an existing meter, by looking in a local cache first
            var meteredSpace = _meteredSpacesService.Get(viewModel.MeteredSpace.MeterID);
            if (meteredSpace == null)
            {
                //record this meter in the db
                meteredSpace = _meteredSpacesService.AddOrUpdate(viewModel.MeteredSpace);
            }

            var posted = new SensorEvent() {
                ClientId = viewModel.ClientID,
                EventTime = DateTime.Parse(viewModel.EventTime),
                EventType = viewModel.EventType,
                MeteredSpace = meteredSpace,
                ReceivedTime = _clock.UtcNow,
                SessionId = long.Parse(viewModel.MeteredSpace.SessionID),
                TransmissionId = long.Parse(viewModel.TransmissionID),
                TransmissionTime = DateTime.Parse(viewModel.TransmissionDateTime)
            };

            var existing = _sensorEventsRepo.Get(x => x.TransmissionId == posted.TransmissionId);

            if (existing == null)
            {
                _sensorEventsRepo.Create(posted);
            }
            else
            {
                posted.Id = existing.Id;
                _sensorEventsRepo.Update(posted);
            }

            return posted;
        }
コード例 #2
0
 public SensorEventGET GetViewModel(SensorEvent entity)
 {
     return new SensorEventGET() {
         EventId = entity.TransmissionId,
         EventTime = entity.EventTime,
         EventType = entity.EventType,
         MeterId = entity.MeteredSpace.MeterId,
         SessionId = entity.SessionId,
         Ordinal = entity.Id,
     };
 }