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 <ActionResult <Employee> > PostTodoItem(Employee data)
        {
            _context.Employees.Add(data);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetEmployees), new { id = data.Id }, data));
        }
예제 #3
0
        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();
            }
        }
예제 #4
0
        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();
            }
        }
예제 #5
0
        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);
            }
        }
예제 #6
0
        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();
            }
        }
예제 #7
0
        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);
            }
        }
예제 #8
0
        public async Task Read_Should_Paginated_Employees(List <Employee> employees)
        {
            const int pageIndex = 1;
            const int pageSize  = 1;

            var options = DbContextOptionsFactory.Create(nameof(Read_Should_Paginated_Employees));

            using (var context = new EmployeeManagerContext(options))
            {
                context.AddRange(employees);
                await context.SaveChangesAsync();
            }

            using (var context = new EmployeeManagerContext(options))
            {
                var sut = new EmployeeReader(context);

                var actual = await sut.Read(pageIndex, pageSize);

                actual.Count.Should().Be(pageSize);
            }
        }