public IActionResult RegisterEmployee(Employee emp) { Employee CheckEmail = _context.Employees .Where(e => e.Email == emp.Email) .SingleOrDefault(); if (CheckEmail != null) { ViewBag.errors = "That email already exists"; return(RedirectToAction("Register")); } if (ModelState.IsValid) { PasswordHasher <Employee> Hasher = new PasswordHasher <Employee>(); Employee newEmp = new Employee { Name = emp.Name, Email = emp.Email, Password = Hasher.HashPassword(emp, emp.Password), Active = true, Age = emp.Age, Title = emp.Title, Department = emp.Department, Salary = emp.Salary }; _context.Add(newEmp); _context.SaveChanges(); ViewBag.success = "Successfully registered"; return(RedirectToAction("Login")); } else { return(View("Register")); } }
public async Task <IActionResult> Create([Bind("ID,FirstName,LastName,Gender,Birthday,Address,PhoneNumber,Department,Email")] Employee employee) { if (ModelState.IsValid) { _context.Add(employee); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(employee)); }
public async Task Remove_Should_Delete_Employee(Employee employee) { var options = DbContextOptionsFactory.Create(nameof(Remove_Should_Delete_Employee)); using (var context = new EmployeeManagerContext(options)) { context.Add(employee); await context.SaveChangesAsync(); } using (var context = new EmployeeManagerContext(options)) { var sut = new EmployeeWriter(context); await sut.Remove(employee); employee.DeletedAt.Should().NotBeNull(); } }
public async Task Any_When_EmailAddress_Exists_Should_Return_True( Employee employee) { var options = DbContextOptionsFactory.Create(nameof(Any_When_EmailAddress_Exists_Should_Return_True)); using (var context = new EmployeeManagerContext(options)) { context.Add(employee); await context.SaveChangesAsync(); } using (var context = new EmployeeManagerContext(options)) { var sut = new EmployeeReader(context); var actual = await sut.Any(employee.Email.Address); actual.Should().BeTrue(); } }
public async Task Read_When_EmployeeId_Exists_Should_Return_Employee(Employee employee) { var options = DbContextOptionsFactory.Create(nameof(Read_When_EmployeeId_Exists_Should_Return_Employee)); using (var context = new EmployeeManagerContext(options)) { context.Add(employee); await context.SaveChangesAsync(); } using (var context = new EmployeeManagerContext(options)) { var sut = new EmployeeReader(context); var actual = await sut.Read(employee.Id); actual.Should().NotBeNull(); actual.Value.Id.Should().Be(employee.Id); } }
public async Task Any_When_EmailAddress_Does_Not_Exist_Should_Return_False( Employee employee, string someEmployeeEmail) { var options = DbContextOptionsFactory.Create(nameof(Any_When_EmailAddress_Does_Not_Exist_Should_Return_False)); using (var context = new EmployeeManagerContext(options)) { context.Add(employee); await context.SaveChangesAsync(); } using (var context = new EmployeeManagerContext(options)) { var sut = new EmployeeReader(context); var actual = await sut.Any(someEmployeeEmail); actual.Should().BeFalse(); } }
public async Task Read_When_EmployeeId_Does_Not_Exist_Should_Return_Maybe_None( Employee employee, int someEmployeeId) { var options = DbContextOptionsFactory.Create(nameof(Read_When_EmployeeId_Does_Not_Exist_Should_Return_Maybe_None)); using (var context = new EmployeeManagerContext(options)) { context.Add(employee); await context.SaveChangesAsync(); } using (var context = new EmployeeManagerContext(options)) { var sut = new EmployeeReader(context); var actual = await sut.Read(someEmployeeId); actual.Should().Be(Maybe <Employee> .None); } }