public async Task <IActionResult> Create([Bind("ID,UserMID,SchemeType,ColorSearched,ColorSearchedHex,ColorReceived,ColorReceivedHex,ColorReceivedTwo,ColorReceivedHexTwo")] ColorSchemeM colorScheme) { if (ModelState.IsValid) { _context.Add(colorScheme); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(colorScheme)); }
public async Task <IActionResult> Results(string SchemeType, string color) { if (color != null) { try { using (var client = new HttpClient()) { //call made to the api client.BaseAddress = new Uri("https://colorwheelapi20190205024526.azurewebsites.net"); var response = await client.GetAsync($"/api/Get{SchemeType}/{color}"); response.EnsureSuccessStatusCode(); //Reades JSON file received from API string result = await response.Content.ReadAsStringAsync(); dynamic colors = JsonConvert.DeserializeObject(result); //Build object ColorSchemeM schemeM = new ColorSchemeM(); schemeM.SchemeType = SchemeType; schemeM.ColorSearched = colors.palette[0].colorName; schemeM.ColorSearchedHex = colors.palette[0].hexCode; schemeM.ColorReceived = colors.palette[1].colorName; schemeM.ColorReceivedHex = colors.palette[1].hexCode; if (colors.palette.Count > 2) { schemeM.ColorReceivedTwo = colors.palette[2].colorName; schemeM.ColorReceivedHexTwo = colors.palette[2].hexCode; } else { schemeM.ColorReceivedTwo = "NA"; schemeM.ColorReceivedHexTwo = "NA"; } ViewData["ID"] = new SelectList(_context.User, "ID", "Name"); return(View(schemeM)); } } catch { return(RedirectToAction(nameof(Index))); } } return(RedirectToAction(nameof(Index))); }
private async void Initialize() { var themeSeeker = themeSeekerFactory.GetThemeSeeker(); try { Themes = new ObservableCollection <ThemeM>(themeSeeker.GetThemes()); if (Themes.Any()) { selectedTheme = Themes.First(); colorSchemes = new ObservableCollection <ColorSchemeM>(Themes.First().ColorSchemeModels); selecteColorScheme = ColorSchemes.FirstOrDefault(); ChangeSelectedTheme(); } } catch (Exception e) { var dialog = new MessageDialog(e.Message); await dialog.ShowAsync(); } }
/// <summary> /// Change theme and color scheme and theme for the application /// </summary> /// <param name="app"><see cref="Application"/></param> /// <param name="styles">new <see cref="ControlStyleM"/></param> /// <param name="numericValues"><see cref="NumericValuesM"/></param> /// <param name="colorScheme">new <see cref="ColorSchemeM"/></param> public static void ChangeApplicationTheme(Application app, IList <ControlStyleM> styles, IList <NumericValuesM> numericValues, ColorSchemeM colorScheme) { if (app == null) { return; } if (styles == null) { return; } if (colorScheme == null) { return; } app.Resources.BeginInit(); app.Resources.MergedDictionaries.Clear(); foreach (var numericValue in numericValues) { app.Resources.MergedDictionaries.Add(numericValue.Resources);//Numerics first } app.Resources.MergedDictionaries.Add(colorScheme.Resources); foreach (var style in styles) { app.Resources.MergedDictionaries.Add(style.Resources); } app.Resources.EndInit(); }
/// <summary> /// Change theme, color scheme and theme for the application. Every resource should contain color scheme inside it merged dictionary (because of StaticResource) /// There is no DynamicResource in UWP /// </summary> /// <param name="app"><see cref="Application"/></param> ///// <param name="styles">new <see cref="ControlStyleM"/></param> /// <param name="colorScheme">new <see cref="ColorSchemeM"/></param> public static void ChangeApplicationTheme(Application app, IList <ControlStyleM> styles, ColorSchemeM colorScheme) { if (app == null) { return; } if (styles == null) { return; } if (colorScheme == null) { return; } var colorSchemeResource = new ResourceDictionary() { Source = colorScheme.Uri }; var colorSchemeResourceThemes = colorSchemeResource.ThemeDictionaries.ToList();//we should copy and clear. Just because we can't add element to new resource while he is a child colorSchemeResource.ThemeDictionaries.Clear(); app.Resources.ThemeDictionaries.Clear(); foreach (var theme in colorSchemeResourceThemes) { app.Resources.ThemeDictionaries.Add(theme.Key, theme.Value); } app.Resources.MergedDictionaries.Clear(); foreach (var controlStyleM in styles) { var styleResource = new ResourceDictionary() { Source = controlStyleM.Uri }; app.Resources.MergedDictionaries.Add(styleResource); } }
/// <summary> /// Saves color scheme returned from API /// </summary> /// <param name="colorScheme"></param> /// <returns></returns> public async Task SaveColorScheme(ColorSchemeM colorScheme) { _context.Add(colorScheme); await _context.SaveChangesAsync(); }