示例#1
0
        private ObservationRoot GetSavedObservation(ObservationRoot observationRoot)
        {
            var observationEventDTO = observationRoot.ObservationEvent;
            var observationsDTO     = observationRoot.Observations;
            var eventId             = observationEventDTO.Observationevent_Id;
            var correlationId       = observationEventDTO.Eventcorrelationid;

            var newObservationEventInStore = _coreObservationEventRepo.ItemsAsReadOnly.Where(ev => ev.ObservationeventId == eventId && ev.Eventcorrelationid == correlationId).FirstOrDefault();

            var newObservationsInStore = _coreObservationRepo.ItemsAsReadOnly.Where(ev => ev.ObservationeventId == eventId && ev.Eventcorrelationid == correlationId).ToList();

            if (newObservationEventInStore == null || !newObservationsInStore.IsCollectionValid())
            {
                return(null);
            }

            var newObservationEvent = this._mapper.Map <ObservationEventDTO>(newObservationEventInStore);

            var newObservations = this._mapper.Map <List <ObservationDTO> >(newObservationsInStore);

            observationRoot.ObservationEvent = newObservationEvent;
            observationRoot.Observations     = newObservations;

            return(observationRoot);
        }
示例#2
0
        private void HandleAmendedObservation(ObservationRoot observationRoot)
        {
            var observationEventDTO = observationRoot.ObservationEvent;
            var observationsDTO     = observationRoot.Observations;
            var eventId             = observationEventDTO.Observationevent_Id; //.IsNotEmpty() ?  = Guid.NewGuid().ToString();
            var correlationId       = observationEventDTO.Eventcorrelationid = Guid.NewGuid().ToString();

            var eventModel = this._mapper.Map <entitystore_CoreObservationevent1>(observationEventDTO);

            this._coreObservationEventRepo.Add(eventModel);

            if (observationsDTO.IsCollectionValid())
            {
                var observationsModel = this._mapper.Map <List <entitystore_CoreObservation1> >(observationsDTO);

                observationsModel.Each(obs =>
                {
                    obs.ObservationId      = obs.Hasbeenammended.HasValue && obs.Hasbeenammended.Value ? obs.ObservationId : Guid.NewGuid().ToString();
                    obs.ObservationeventId = eventId;
                    obs.Eventcorrelationid = correlationId;

                    //var observtaionModel = this._mapper.Map<entitystore_CoreObservation1>(obs);

                    this._coreObservationRepo.Add(obs);
                });
            }

            RemoveMaterialisedObservation(eventId);

            //AddNewMaterialisedObservation(observationRoot);
        }
        public async Task <ActionResult <ObservationRoot> > CreateObservation([FromBody] ObservationRoot observation)
        {
            //if (observation.IsNull() || observation.ObservationEvent.IsNull())
            //{
            //    throw new InterneuronBusinessException(StatusCodes.Status400BadRequest, "Observation should have event.");
            //}

            var commandHandlerFactory = this._provider.GetService(typeof(CommandHandlerFactory)) as CommandHandlerFactory;

            var handler = commandHandlerFactory.GetHandler(nameof(CreateObservation));

            var key         = Key.Create("observation");
            var handlerTask = new TaskFactory().StartNew(() =>
            {
                return((ObservationRoot)handler.Handle(key, observation));
            });

            return(await handlerTask);
        }
示例#4
0
        private void AddNewMaterialisedObservation(ObservationRoot observationRoot)
        {
            var observationEventDTO = observationRoot.ObservationEvent;
            var observationsDTO     = observationRoot.Observations;

            var eventModel = this._mapper.Map <entitystorematerialised_CoreObservationevent>(observationEventDTO);

            this._matCoreObservationEventRepo.Add(eventModel);

            if (observationsDTO.IsCollectionValid())
            {
                var observationsModel = this._mapper.Map <List <entitystorematerialised_CoreObservation> >(observationsDTO);

                observationsModel.Each(obs =>
                {
                    this._matCoreObservationRepo.Add(obs);
                });
            }
        }
示例#5
0
 private static bool IsAmended(ObservationRoot observationRoot)
 {
     return(observationRoot.ObservationEvent.Isamended.HasValue ? observationRoot.ObservationEvent.Isamended.Value : false);
 }