private void BuildPropertyValues(CalibrationComponent componentIn, CalibrationComponentDataAdapter adapter)
        {
            foreach (CalibrationPropertyDto dto in adapter.PropertyValues)
            {

                CalibrationProperty property = (from x in mExistingProperties where x.Name.ToLower() == dto.PropertyName.ToLower() select x).FirstOrDefault();

                if (property == null)
                {
                    if (CanCreateProperties)
                    {
                        property = new CalibrationProperty { Name = dto.PropertyName, Type = "not used", Description = "(created by importer.)" };
                        mExistingProperties.Add(property);

                        //JOIN TABLE - joins the Property with the Type
                        CalibrationComponentTypeProperty typePropertyJoin = new CalibrationComponentTypeProperty();
                        typePropertyJoin.CalibrationComponentType = componentIn.CalibrationComponentType;

                        //EngineeringUnit
                        if (dto.NewUnit != null)
                        {
                            CalibrationEngineeringUnit unit = (from x in mExistingUnits where x.Name == dto.NewUnit.Name select x).FirstOrDefault();
                            if (unit == null)
                            {
                                typePropertyJoin.CalibrationEngineeringUnit = dto.NewUnit;
                            }
                            else
                            {
                                typePropertyJoin.CalibrationEngineeringUnit = unit;
                            }
                        }

                        property.CalibrationComponentTypeProperties.Add(typePropertyJoin);

                        mExistingProperties.Add(property);

                    }
                    else
                    {
                        RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Line '{1} Tag {2} Component Name {3}' : The property does not exist.",
                            WorkSheetName, adapter.RowNumber, adapter.Tag, adapter.CalibrationName));
                        continue;
                    }
                }
                else
                {

                    //do we have a record in the join table for this property and comp type?
                    CalibrationComponentTypeProperty equipmentComponentTypeProperty =
                        (from x in Cee.CalibrationComponentTypeProperties
                         where x.CalibrationComponentType.Name.ToLower() == componentIn.CalibrationComponentType.Name.ToLower()
                         && x.CalibrationProperty.Name.ToLower() == property.Name.ToLower()
                         select x).FirstOrDefault();

                    if (equipmentComponentTypeProperty == null)
                    {
                        ////no row in join table - so create one.
                        CalibrationComponentTypeProperty typePropertyJoin = new CalibrationComponentTypeProperty();

                        if (dto.NewUnit != null)
                        {
                            CalibrationEngineeringUnit unit = (from x in mExistingUnits where x.Name == dto.NewUnit.Name select x).FirstOrDefault();

                            if (unit == null)
                            {
                                typePropertyJoin.CalibrationEngineeringUnit = dto.NewUnit;
                            }
                            else
                            {
                                typePropertyJoin.CalibrationEngineeringUnit = unit;
                            }
                        }

                        typePropertyJoin.CalibrationComponentType = componentIn.CalibrationComponentType;
                        property.CalibrationComponentTypeProperties.Add(typePropertyJoin);
                    }

                }

                CalibrationComponentPropertyValue propertyValue = (from x in Cee.CalibrationComponentPropertyValues
                                                                   where x.CalibrationComponentId == componentIn.Id
                                                                   && x.CalibrationPropertyId == property.Id
                                                                   select x).FirstOrDefault();
                if (propertyValue == null)
                {
                    propertyValue = new CalibrationComponentPropertyValue {CalibrationComponent = componentIn, CalibrationProperty = property};
                    property.Type = "Text";//not used but not nullable
                    property.EnableAsFound = false; //not used but not nullable
                }

                //Set AsFoundValue
                if (!string.IsNullOrEmpty(dto.AsFoundValue))
                {
                    propertyValue.Value = dto.AsFoundValue;
                }

                //Set AsLeftValue
                if (!string.IsNullOrEmpty(dto.AsLeftValue))
                {
                    propertyValue.Value2 = dto.AsLeftValue;
                }

                componentIn.CalibrationComponentPropertyValues.Add(propertyValue);

            }
        }
 public CalibrationComponentPropertyWrapViewModel(CalibrationComponentPropertyValue calibrationComponentPropertyValue, string type)
 {
     mType = type;
     mCalibrationComponentPropertyValue = calibrationComponentPropertyValue;
 }
        private CalibrationComponentPropertyValue GetCalibrationComponentPropertyValue(CalibrationComponent calibrationComponent, CalibrationComponentTypeProperty calibrationComponentProperty)
        {
            var propertyValue = (from x in calibrationComponent.CalibrationComponentPropertyValues
                                 where x.CalibrationPropertyId == calibrationComponentProperty.CalibrationPropertyId &&
                                 x.CalibrationComponentId == calibrationComponent.Id
                                 select x).FirstOrDefault();

            if (propertyValue == null)
            {
                propertyValue = new CalibrationComponentPropertyValue
                    {
                        CalibrationComponentId = calibrationComponent.Id,
                        CalibrationPropertyId = calibrationComponentProperty.CalibrationPropertyId,
                        Value = calibrationComponentProperty.CalibrationProperty.DefaultValue, //As Found
                        Value2 = calibrationComponentProperty.CalibrationProperty.DefaultValue //As Left
                    };
                calibrationComponent.CalibrationComponentPropertyValues.Add(propertyValue);
            }

            return propertyValue;
        }