public async Task <IActionResult> UpdateSettings(SettingsModel settingsModel) { User user = await userManager.GetUserAsync(User); Settings prevSettings = context.Settings.Find(user.Id); Settings settings = new Settings { UserId = user.Id, HoursPerDay = settingsModel.HoursPerDay, CardsPerDay = settingsModel.CardsPerDay, CardsOrder = Int32.Parse(settingsModel.CardsOrder), DarkTheme = settingsModel.DarkTheme, ShowImages = settingsModel.ShowImages }; if (prevSettings != null) { context.Remove(prevSettings); } await context.AddAsync(settings); await context.SaveChangesAsync(); return(View(nameof(Settings), settingsModel)); }
public async Task <IActionResult> CreateDeck(CreateDeckModel model) { if (ModelState.IsValid) { var user = await _userManager.GetUserAsync(User); var deck = new Deck { Name = model.Name, Creator = user }; await _context.AddAsync(deck); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(EditDeck), new { deckId = deck.Id })); } return(View(new CreateDeckModel { Username = (await _userManager.GetUserAsync(User)).UserName })); }