public async Task<Response> Register([FromBody]LoginForm form) { if (!ModelState.IsValid) { return OperationResult.Error(ModelState); } var user = new User { UserName = form.UserName }; var result = await userManager.CreateAsync(user, form.Password); if (!result.Succeeded) { return OperationResult.Error(result.Errors.FirstOrDefault().Description); } await signInManager.PasswordSignInAsync(form.UserName, form.Password, false, false); return OperationResult.Success(); }
private Menu CreateMenu(User user, DateTime date) { var menu = new Menu() { Date = date, MenuRecords = new List<MenuRecord>() }; context.Menus.Add(menu); user.Menus.Add(menu); context.Users.Attach(user); context.SaveChanges(); return menu; }