Ejemplo n.º 1
0
        public bool SaveSettings(string SN, SettingsView setting)
        {
            var result = false;

            #region  GeneralSettings

            if (setting.AdvancedSettings != null &&
                setting.DeviceInfo != null &&
                setting.GeneralSetting != null)
            {
                var gSetting = new GeneralSettings()
                {
                    IsMetric         = setting.AdvancedSettings.IsMetric,
                    LandTypeID       = (byte)setting.AdvancedSettings.LandType,
                    Name             = setting.DeviceInfo.Name,
                    Status           = (byte)setting.GeneralSetting.Status,
                    CustomTimeZoneID = setting.GeneralSetting.TimeZoneID
                };
                result = _AdminRepository.GeneralSettings_Update(SN, gSetting);

                if (!result)
                {
                    return(result);
                }
            }
            #endregion

            #region MainPipe

            if (setting.RainSensor != null &&
                setting.IrrgationSetting != null &&
                setting.GeneralSetting != null)
            {
                var mainpSetting = new MainPipeSettings()
                {
                    RainDetectorEnabled   = setting.RainSensor.Active,
                    RainyDaysStopper      = setting.RainSensor.SuspendDays,
                    RainDetectorNC        = setting.RainSensor.NC,
                    IsLocalSequenceActive = setting.IrrgationSetting.IsLocalSequenceActive,
                    ProgramsAsQueue       = setting.IrrgationSetting.ProgramsAsQueue,
                    UseMaster             = setting.GeneralSetting.UseMaster
                };

                var days = setting.GeneralSetting.ValidDays;
                if (days != null && days.Days != null)
                {
                    mainpSetting.DSundayState    = days.Days[0].IsEnabled;
                    mainpSetting.DMondayState    = days.Days[1].IsEnabled;
                    mainpSetting.DTuesdayState   = days.Days[2].IsEnabled;
                    mainpSetting.DWednesdayState = days.Days[3].IsEnabled;
                    mainpSetting.DThursdayState  = days.Days[4].IsEnabled;
                    mainpSetting.DFridayState    = days.Days[5].IsEnabled;
                    mainpSetting.DSaturdayState  = days.Days[6].IsEnabled;
                }

                result = _AdminRepository.MainPipeSettings_Update(SN, mainpSetting);

                if (!result)
                {
                    return(result);
                }
            }


            #endregion

            #region Fertilizer

            if (setting.Fertilizer != null)
            {
                var fertSetting = new FertilizerSetting()
                {
                    OutputNumber         = setting.Fertilizer.OutputNumber,
                    TypeID               = (byte)setting.Fertilizer.FertilizerType,
                    ContinuousFert       = setting.Fertilizer.ContinuousFert,
                    PulseSize            = setting.Fertilizer.PulseSize,
                    PulseTime            = setting.Fertilizer.PulseTime,
                    FerlizerFaillureTime = setting.Fertilizer.FerlizerFaillureTime,
                    Leakage              = setting.Fertilizer.Leakage,
                    PulseTypeID          = (byte)setting.Fertilizer.PulseTypeID,
                    FlowTypeID           = (byte)setting.Fertilizer.FlowTypeID,
                    IsEnabled            = setting.Fertilizer.IsEnabled,
                    NominalFlow          = setting.Fertilizer.NominalFlow
                };
                result = _AdminRepository.FertilizerSetting_Update(SN, fertSetting);

                if (!result)
                {
                    return(result);
                }
            }
            #endregion

            #region WaterMeter

            if (setting.WaterMeter != null)
            {
                var wMeterSetting = new WaterMeterSetting()
                {
                    MeterTypeID       = (byte)setting.WaterMeter.MeterType,
                    PulseSize         = setting.WaterMeter.PulseSize,
                    IsEnabled         = setting.WaterMeter.IsEnabled,
                    PulseTypeID       = (byte)setting.WaterMeter.PulseTypeID,
                    FlowTypeID        = (byte)setting.WaterMeter.FlowTypeID,
                    NoWaterPulseDelay = setting.WaterMeter.NoWaterPulseDelay,
                    LeakageLimit      = setting.WaterMeter.LeakageLimit
                };

                result = _AdminRepository.WaterMeterSetting_Update(SN, wMeterSetting);

                if (!result)
                {
                    return(result);
                }
            }
            #endregion

            #region IrrExceptionDates

            if (setting.IrrgationSetting.RestrictedDates != null)
            {
                RestrictedDates[] IrrExceptionDates = setting.IrrgationSetting.RestrictedDates.Select(d => new RestrictedDates()
                {
                    ExceptionDate = d
                }).ToArray();
                result = _AdminRepository.IrrExceptionDates_Update(SN, IrrExceptionDates);

                if (!result)
                {
                    return(result);
                }
            }

            #endregion

            return(result);
        }