public async Task<IdentityResult> Register([FromBody] LoginViewModel loginViewModel) { var newUser = new toDoUser() { UserName = loginViewModel.UserName }; IdentityResult IdentityResult = await _userManager.CreateAsync(newUser, loginViewModel.Password); if (IdentityResult.Succeeded) { await _signInManager.PasswordSignInAsync(loginViewModel.UserName, loginViewModel.Password, true, false); _context.Add(new toDo() { tags = "tag1, tag2, tag3...", description = "the detail of toDo", dueDate = new DateTime(2016, 5, 08, 12, 0, 0), state = "Active", UserName = loginViewModel.UserName }); _context.Add(new warning() { Time = 48, UserName = loginViewModel.UserName }); _context.SaveChanges(); } return IdentityResult; }
public async Task SeedData() { if (await _userManager.FindByNameAsync("Samuel") == null) { var defaultUser = new toDoUser() { UserName = "******", }; await _userManager.CreateAsync(defaultUser, "ASDqwe123"); } if (!_context.toDo.Any()) { _context.Add(new toDo() { tags = "life, business", description = "Wake up early in the morning", dueDate = new DateTime(2015, 5, 4, 6, 0, 0), state = "Active", UserName = "******" }); _context.Add(new toDo() { tags = "life", description = "Eat well", dueDate = new DateTime(2015, 3, 5, 12, 0, 0), state = "Active", UserName = "******" }); _context.Add(new toDo() { tags = "business", description = "Skip work", dueDate = new DateTime(2015, 4, 4, 12, 0, 0), state = "Completed", UserName = "******" }); if (!_context.warning.Any()) { _context.Add(new warning() { Time = 48, UserName = "******" }); } _context.SaveChanges(); } }