Example #1
0
        /// <summary>
        /// Insert a Gdto into the event store.
        /// Return an int with the regitered rvents id.
        /// </summary>
        public int Insert(Gdto dto)
        {
            try
            {
                var eventStore = this.createStoreObject.CreateWriteEvent(dto, CommandType.Insert);

                return this.writeToStore.InsertIntoEventStore(eventStore).Id;
            }
            catch (Exception ex)
            {
                this.logger.Error(ex);
                throw new InsertException(ex.Message, ex);
            }
        }
Example #2
0
        private void UpdateRegistration(DateTime timestamp, Gdto gdto, string namePropertyValue)
        {
            int originalWriteEventId = this.writeEventService.GetOriginalWriteEventId(gdto.Properties);

            var registration = this.writeToReadRepository.GetRegistration(originalWriteEventId);
            var registrationType = this.writeToReadRepository.GetRegistrationType(gdto);

            registration = this.writeToReadRepository.UpdateRegistration(
                registration, registrationType, timestamp, namePropertyValue);

            this.writeToReadRepository.UpdateProperties(registration, gdto);
        }
Example #3
0
        /// <summary>
        /// Insert a new Registration into the database.
        /// </summary>
        private void InsertRegistration(DateTime timestamp, Gdto gdto, string namePropertyValue, int originalWriteEventId)
        {
            var registrationType = this.writeToReadRepository.GetRegistrationType(gdto);

            var registration = this.writeToReadRepository.AddRegistrationToDbSet(
                registrationType, timestamp, namePropertyValue, originalWriteEventId);

            this.writeToReadRepository.AddRegistrationProperties(gdto, registration);
        }
Example #4
0
        /// <summary>
        /// Add new properties to a registration.
        /// </summary>
        private Registration AddNewProperties(Registration registration, Gdto gdto)
        {
            if (registration.Properties == null || gdto.Properties == null)
            {
                return registration;
            }

            foreach (var keyValuePair in gdto.Properties)
            {
                bool exists = CheckIfPropertyExistInRegistration(registration, keyValuePair);

                if (!exists)
                {
                    this.AddPropertyTypeAndProperty(registration, keyValuePair);
                }
            }

            return registration;
        }
Example #5
0
 /// <summary>
 /// Update the value of one existing property with new value from the Gdto.
 /// </summary>
 private static void UpdateProperty(Gdto gdto, Property registrationProperty)
 {
     foreach (var gdtoProperty in gdto.Properties)
     {
         if (string.Equals(registrationProperty.PropertyType.Name, gdtoProperty.Key, StringComparison.CurrentCultureIgnoreCase))
         {
             registrationProperty.Value = gdtoProperty.Value;
         }
     }
 }
Example #6
0
        /// <summary>
        /// Update the values of existing properties with new values from the Gdto.
        /// </summary>
        private static Registration UpdateExistingProperties(Registration registration, Gdto gdto)
        {
            if (registration.Properties == null || gdto.Properties == null)
            {
                return registration;
            }

            foreach (var property in registration.Properties)
            {
                UpdateProperty(gdto, property);
            }

            return registration;
        }
Example #7
0
        /// <summary>
        /// Get the properties that should be deleted.
        /// </summary>
        private static IList<Property> GetPropertiesToDelete(Registration registration, Gdto gdto)
        {
            var toDelete = new List<Property>();

            foreach (var property in registration.Properties)
            {
                bool exists = CheckIfPropertyExistInGdto(gdto.Properties, property);

                if (!exists)
                {
                    toDelete.Add(property);
                }
            }

            return toDelete;
        }
Example #8
0
        /// <summary>
        /// Delete properties that does not exist in the GDTO.
        /// </summary>
        private static Registration DeleteNonExistingProperties(Registration registration, Gdto gdto)
        {
            if (registration.Properties == null || gdto.Properties == null)
            {
                return registration;
            }

            var toDelete = GetPropertiesToDelete(registration, gdto);

            foreach (var property in toDelete)
            {
                registration.Properties.Remove(property);
            }

            return registration;
        }
Example #9
0
        /// <summary>
        /// Update all properties for a registration. Also inserting new and removing old properties.
        /// </summary>
        public Registration UpdateProperties(Registration registration, Gdto gdto)
        {
            try
            {
                if (registration == null || gdto == null)
                {
                    return registration;
                }

                registration = UpdateExistingProperties(registration, gdto);

                registration = this.AddNewProperties(registration, gdto);

                registration = DeleteNonExistingProperties(registration, gdto);
            }
            catch (Exception ex)
            {
                this.logger.Error(ex);
                throw;
            }

            return registration;
        }
Example #10
0
        /// <summary>
        /// Get RegistrationType from a Gdto.
        /// </summary>
        public RegistrationType GetRegistrationType(Gdto gdto)
        {
            var registrationType = this.GetRegistrationType(gdto.EntityType);

            if (registrationType.Id == 0)
            {
                registrationType = this.AddRegistrationTypeToDbSet(gdto.EntityType);
            }

            return registrationType;
        }
Example #11
0
 /// <summary>
 /// Add properties to a registration.
 /// </summary>
 public void AddRegistrationProperties(Gdto gdto, Registration registration)
 {
     foreach (var property in gdto.Properties)
     {
         this.AddPropertyTypeAndProperty(registration, property);
     }
 }