public async Task <IActionResult> Create([Bind("Id,Description,Family,Category,Range,DateCreated,Delay")] Product product) { if (ModelState.IsValid) { _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(product)); }
public async Task <ActionResult <UserDto> > Register(RegisterDto registerDto) { if (await UserExists(registerDto.Username)) { return(BadRequest("Username is already taken")); } using var hmac = new HMACSHA512(); var user = new AppUser { UserName = registerDto.Username.ToLower(), PasswordHash = hmac.ComputeHash(Encoding.UTF8.GetBytes(registerDto.Password)), PasswordSalt = hmac.Key }; _context.Users.Add(user); await _context.SaveChangesAsync(); return(new UserDto { Username = user.UserName, Token = _tokenService.CreateToken(user) }); }