コード例 #1
0
 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));
     }
 }
コード例 #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            if (Environment.GetEnvironmentVariable("DB_CONNECTION") == "SQL")
            {
                services.AddDbContext <ApplicationDbContext>(options =>
                                                             options.UseSqlServer(
                                                                 Configuration.GetConnectionString("DefaultConnection")));
            }
            else
            {
                services.AddDbContext <ApplicationDbContext>(options =>
                                                             options.UseSqlite(
                                                                 Configuration.GetConnectionString("LocalConnection")));
            }

            services.AddIdentity <IdentityUser, IdentityRole>()
            .AddDefaultUI(UIFramework.Bootstrap4)
            .AddEntityFrameworkStores <ApplicationDbContext>()
            .AddDefaultTokenProviders();

            var site = new SiteInformation(
                new AzureBlobSetings(Configuration.GetSection("AzureBlobSetings")["AccountName"],
                                     Configuration.GetSection("AzureBlobSetings")["AccountKey"],
                                     Configuration.GetSection("AzureBlobSetings")["ContainerName"]));

            services.AddSingleton <ISiteInformation>(site);
            services.AddSingleton <IAzureIoT>(new AzureIoT(site));

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);


            services.AddLocalization(options => options.ResourcesPath = nameof(Resources));
            services.AddMvc()
            .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
            .AddDataAnnotationsLocalization();

            services.Configure <RequestLocalizationOptions>(options =>
            {
                var supportedCultures = new List <CultureInfo>
                {
                    new CultureInfo("en-US"),
                    new CultureInfo("fr")
                };

                options.DefaultRequestCulture = new RequestCulture("en-US");
                options.SupportedCultures     = supportedCultures;
                options.SupportedUICultures   = supportedCultures;
            });

            CultureInfo.DefaultThreadCurrentCulture   = new CultureInfo(Culture.FromLanguageToCulture(site.Settings.Language));
            CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo(Culture.FromLanguageToCulture(site.Settings.Language));
        }