public ActionResult Edit(IFormCollection collection)
 {
     try
     {
         var forc = _site.Settings;
         forc.Name           = collection[nameof(Settings.Name)];
         forc.TimeZoneInfoId = collection[nameof(Settings.TimeZoneInfoId)];
         forc.ApiKey         = collection[nameof(Settings.ApiKey)];
         forc.City           = collection[nameof(Settings.City)];
         var b = collection[nameof(Settings.FullAutomationMode)].ToArray()[0];
         forc.FullAutomationMode = bool.Parse(b);
         forc.Language           = (Language)Enum.Parse(typeof(Language), collection[nameof(Settings.Language)]);
         forc.Latitude           = float.Parse(collection[nameof(Settings.Latitude)]);
         forc.Longitude          = float.Parse(collection[nameof(Settings.Longitude)]);
         forc.TimeToCheck        = TimeSpan.Parse(collection[nameof(Settings.TimeToCheck)]);
         forc.Unit = (Unit)Enum.Parse(typeof(Unit), collection[nameof(Settings.Unit)]);
         forc.PrecipitationPercentForecast   = int.Parse(collection[nameof(Settings.PrecipitationPercentForecast)]);
         forc.PrecipitationThresholdActuals  = float.Parse(collection[nameof(Settings.PrecipitationThresholdActuals)]);
         forc.PrecipitationThresholdForecast = float.Parse(collection[nameof(Settings.PrecipitationThresholdForecast)]);
         _site.SaveConfiguration();
         CultureInfo.DefaultThreadCurrentCulture   = new CultureInfo(Culture.FromLanguageToCulture(_site.Settings.Language));
         CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo(Culture.FromLanguageToCulture(_site.Settings.Language));
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         PrepareViewData();
         var timeZone = new SelectList(TimeZoneInfo.GetSystemTimeZones(), nameof(TimeZoneInfo.Id), nameof(TimeZoneInfo.Id));
         ViewBag.timeZone = timeZone;
         return(View(_site.Settings));
     }
 }
        // GET: Sprinkler/Typical/5
        public ActionResult Typical(int id)
        {
            try
            {
                var spr   = _site.Sprinklers.Where(m => m.Number == id).FirstOrDefault();
                var typic = spr.TypicalProgram;
                SprinklerProgram sprProg = new SprinklerProgram()
                {
                    Duration      = typic.Duration,
                    DateTimeStart = (DateTimeOffset.Now.TimeOfDay > typic.StartTime) ? DateTimeOffset.Now.Date.AddDays(1).Add(typic.StartTime) : DateTimeOffset.Now.Date.Add(typic.StartTime),
                    Number        = id
                };
                _site.SprinklerPrograms.Add(sprProg);
                _site.SaveConfiguration();
            }
            catch (Exception)
            { }

            return(RedirectToAction(nameof(Index)));
        }
Example #3
0
        public ActionResult Create(IFormCollection collection)
        {
            try
            {
                FuzzySprinkler fuzzy = new FuzzySprinkler();
                fuzzy.TempMin       = float.Parse(collection[nameof(FuzzySprinkler.TempMin)], NumberStyles.Any);
                fuzzy.TempMax       = float.Parse(collection[nameof(FuzzySprinkler.TempMax)], NumberStyles.Any);
                fuzzy.RainMax       = float.Parse(collection[nameof(FuzzySprinkler.RainMax)], NumberStyles.Any);
                fuzzy.SprinklingMax = float.Parse(collection[nameof(FuzzySprinkler.SprinklingMax)], NumberStyles.Any);
                _site.FuzzySprinklers.Add(fuzzy);
                _site.SaveConfiguration();

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                PrepareViewData();
                ViewData["msg"] = $"Error: {ex.Message}";
                return(View());
            }
        }
 public ActionResult Create(IFormCollection collection)
 {
     try
     {
         SprinklerProgram sprProg = new SprinklerProgram();
         sprProg.DateTimeStart = DateTimeOffset.Parse(collection[nameof(SprinklerProgram.DateTimeStart)]);
         sprProg.Duration      = TimeSpan.Parse(collection[nameof(SprinklerProgram.Duration)]);
         sprProg.Number        = Convert.ToInt32(collection[nameof(SprinklerProgram.Number)]);
         _site.SprinklerPrograms.Add(sprProg);
         _site.SaveConfiguration();
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         ViewData["DateTimeMin"] = DateTimeOffset.Now.ToString("yyyy-MM-ddTHH:mm"); //"2019-02-28T16:00"
         var sprinklers = new SelectList(_site.Sprinklers, nameof(Sprinkler.Number), nameof(Sprinkler.Name));
         ViewBag.sprinklers = sprinklers;
         PrepareViewData();
         return(View());
     }
 }