public IActionResult Register(RegisterUser model) { var ts = _context.Database.BeginTransaction(); try { var customer = _mapper.Map <User>(model); customer.MaNgauNhien = MyTool.GetRandom(); customer.MatKhau = model.MatKhau.ToSHA512Hash(customer.MaNgauNhien); _context.Add(customer); _context.SaveChanges(); var userRole = new UserRole { RoleId = RoleContants.Customer, UserId = customer.MaNd }; _context.Add(userRole); _context.SaveChanges(); ts.Commit(); return(RedirectToAction("Login")); } catch { ts.Rollback(); return(View()); } }
protected override void Up(MigrationBuilder migrationBuilder) { var randomKey = MyTool.GetRandom(); var matkhauHash = "admin".ToSHA512Hash(randomKey); var adminId = 1; var sqlInsertAdminuser = @$ " SET IDENTITY_INSERT [dbo].[User] ON