/// <summary> /// Create a property object. /// </summary> public static Property CreateProperty(PropertyType propertyType, string value, Registration registration) { return new Property { PropertyTypeId = propertyType.Id, PropertyType = propertyType, Value = value, Registrations = new Collection<Registration> { registration } }; }
/// <summary> /// Add a property to a registration. /// </summary> public void AddProperty(PropertyType propertyType, KeyValuePair<string, string> property, Registration registration) { var registrationProperty = this.CheckIfPropertyIsRegistered(propertyType, property.Value); if (registrationProperty.Id == 0) { this.AddPropertyToDbSet(propertyType, property.Value, registration); } else { this.AddRegistrationToProperty(registrationProperty, registration); } }
/// <summary> /// Add property to db set. /// </summary> public Property AddPropertyToDbSet(PropertyType type, string value, Registration registration) { try { var property = Property.CreateProperty(type, value, registration); this.readContext.Properties.Add(property); registration.Properties.Add(property); return property; } catch (Exception ex) { this.logger.Error(ex); throw; } }
/// <summary> /// Check if a property is already registered and return the id. /// </summary> public Property CheckIfPropertyIsRegistered(PropertyType type, string value) { try { if (this.readContext.Properties == null) { return new Property(); } foreach (var property in this.readContext.Properties) { if (property.PropertyTypeId != type.Id) { continue; } if (string.Equals(property.Value, value, StringComparison.CurrentCultureIgnoreCase)) { return property; } } return new Property(); } catch (Exception ex) { this.logger.Error(ex); throw; } }