public DbOperationResult<ElectricalEquipmentProperty> SaveElectricalEquipmentProperty(ElectricalEquipmentProperty controlSystemProperty)
        {
            DbOperationResult<ElectricalEquipmentProperty> dbOperationResult = new DbOperationResult<ElectricalEquipmentProperty>();

            try
            {
                using (CmsEntities cee = new CmsEntities())
                {
                    ElectricalEquipmentProperty original = (from x in cee.ElectricalEquipmentProperties where x.Id == controlSystemProperty.Id select x).FirstOrDefault();

                    if (original == null)
                    {
                        cee.ElectricalEquipmentProperties.Add(controlSystemProperty);
                    }
                    else
                    {
                        cee.Entry(original).CurrentValues.SetValues(controlSystemProperty);
                    }

                    cee.SaveChanges();
                    dbOperationResult.EntityResult = controlSystemProperty;
                }

            }
            catch (Exception ex)
            {
                log.Error("", ex, ex.ToString());
                dbOperationResult.ServerErrorMessages = BuildOperationalErrorResults(ex).ServerErrorMessages;
                return dbOperationResult;
            }
            return dbOperationResult;
        }
        private void BuildPropertyValues(ElectricalEquipmentComponent componentIn, ElectricalComponentDataAdapter adapter)
        {
            foreach (KeyValuePair<string, string> pair in adapter.PropertyValues)
            {
                //DOES PROPERTY EXIST?
                ElectricalEquipmentProperty property = (from x in mExistingEquipmentProperties where x.Name.ToLower() == pair.Key.ToLower() select x).FirstOrDefault();
                if (property == null)
                {
                    if (CanCreateProperties)
                    {
                        property = new ElectricalEquipmentProperty { Name = pair.Key, DefaultValue = pair.Value, Description = " (created by importer)." };
                        mExistingEquipmentProperties.Add(property);//update cache
                    }
                    else
                    {
                        //ERROR!
                        RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Row '{1} Tag {2} Component Name {3}' : The property does not exist.",
                            WorkSheetName, adapter.RowNumber, adapter.Tag, adapter.ComponentName));
                        continue;
                    }
                }

                //CHECK ElectricalEquipmentComponentTypeProperty Exists
                ElectricalEquipmentComponentTypeProperty equipmentComponentTypeProperty = null;
                if (mExistingEquipmentComponentTypeProperty.Any())
                {
                    equipmentComponentTypeProperty =
                        (from x in mExistingEquipmentComponentTypeProperty
                         where x.ElectricalEquipmentComponentType.Name.ToLower() == componentIn.ElectricalEquipmentComponentType.Name.ToLower()
                         && x.ElectricalEquipmentProperty.Name.ToLower() == property.Name.ToLower()
                         select x).FirstOrDefault();
                }

                if (equipmentComponentTypeProperty == null)
                {
                    if (CanCreateProperties)
                    {
                        //CREATE JOIN ROW
                        equipmentComponentTypeProperty = new ElectricalEquipmentComponentTypeProperty();
                        equipmentComponentTypeProperty.ElectricalEquipmentComponentType = componentIn.ElectricalEquipmentComponentType; //note: set the object!
                        equipmentComponentTypeProperty.ElectricalEquipmentProperty = property; //not set the object!
                        mExistingEquipmentComponentTypeProperty.Add(equipmentComponentTypeProperty); //update cache
                    }
                    else
                    {
                        //ERROR!
                        RaiseMessage(CommonUtils.MessageType.Warning, string.Format("WorkSheet '{0}' Row '{1} Tag {2} Component Type {3}' : The property {4} does not belong to the Component Type.",
                            WorkSheetName, adapter.RowNumber, adapter.Tag, componentIn.ElectricalEquipmentComponentType.Name, property.Name));
                        continue;
                    }
                }
                property.ElectricalEquipmentComponentTypeProperties.Add(equipmentComponentTypeProperty);

                //CHECK PROPERTYVALUE EXISTS
                ElectricalPropertyValue propertyValue = null;
                if (mExistingPropertyValues.Any())
                {

                    propertyValue = (from x in mExistingPropertyValues
                                     where x.ElectricalEquipmentComponent.Name.ToLower() == componentIn.Name.ToLower()
                                           && x.ElectricalEquipmentProperty.Name.ToLower() == property.Name.ToLower()
                                     select x).FirstOrDefault();
                }

                if (propertyValue == null)
                {
                    propertyValue = new ElectricalPropertyValue();
                    propertyValue.ElectricalEquipmentComponent = componentIn;
                    propertyValue.ElectricalEquipmentProperty = property;
                    mExistingPropertyValues.Add(propertyValue);//update cache
                }

                //set value
                if (!string.IsNullOrEmpty(pair.Value))
                {
                    propertyValue.Value = pair.Value.ChangeNullToEmptyString();
                }

                componentIn.ElectricalPropertyValues.Add(propertyValue);
            }
        }