public async Task Creates_employee(
            [Frozen, Greedy] EmployeeContext db,
            SaveEmployee request,
            SaveEmployeeHandler sut)
        {
            request.Value.Id = Guid.Empty;

            var success = await sut.Handle(request);

            success.Should().BeTrue();
            request.Value.Id.Should().NotBe(Guid.Empty);
            db.Employees.Find(request.Value.Id).Should().BeEquivalentTo(request.Value);
        }
        public async Task Updates_employee(
            [Frozen, Greedy] EmployeeContext db,
            Employee existingEmployee,
            SaveEmployee request,
            SaveEmployeeHandler sut)
        {
            await db.Employees.AddAsync(existingEmployee);

            await db.SaveChangesAsync();

            db.Entry(existingEmployee).State = EntityState.Detached;
            request.Value.Id = existingEmployee.Id;

            var success = await sut.Handle(request);

            success.Should().BeTrue();
            var updatedEmployee = db.Find <Employee>(existingEmployee.Id);

            updatedEmployee.Should().BeEquivalentTo(request.Value);
            updatedEmployee.Should().NotBeEquivalentTo(existingEmployee);
        }
Beispiel #3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            //Required Employee Records
            string name       = txtEmpName.Text;
            string city       = txtEmpCity.Text;
            string department = txtEmpDept.Text;
            string gender     = cboEmpGender.Text;

            //Employee Health Insurance Records
            string   healthInsProvider = txtEmpHealthInsuranceProvider.Text;
            string   insPlanName       = txtEmpInsurancePlanName.Text;
            string   insMonthlyFee     = txtEmpInsuranceMonthlyFee.Text;
            DateTime insStartDate      = dtpInsuranceStartDate.Value.Date;

            //Employee Image
            PictureBox employeeImage = pictureBox1;
            string     fileExtension = lblFileExtension.Text;

            //Action Type
            string actionType = btnSave.Text;

            if (string.IsNullOrWhiteSpace(name))
            {
                MessageBox.Show("Enter Employee Name !!!");
            }
            else if (string.IsNullOrWhiteSpace(city))
            {
                MessageBox.Show("Enter Current City !!!");
            }
            else if (string.IsNullOrWhiteSpace(department))
            {
                MessageBox.Show("Enter Department !!!");
            }
            else if (cboEmpGender.SelectedIndex <= -1)
            {
                MessageBox.Show("Select Gender !!!");
            }
            else
            {
                //TestSave t = new TestSave(ConnectionString.config)
                //{
                //    Id = EmployeeId,
                //    Name = name,
                //    City = city,
                //    Department = department,
                //    Gender = gender,

                //    HealthInsuranceProvider = healthInsProvider,
                //    InsurancePlanName = insPlanName,
                //    InsuranceMonthlyFee = insMonthlyFee,
                //    InsuranceStartDate = insStartDate,

                //    EmployeeImage = employeeImage,
                //    FileExtension = fileExtension
                //};
                //t.InsertOrUpdate(btnSaveText);
                SaveEmployee saveEmployee = new SaveEmployee(ConnectionString.config)
                {
                    Id         = EmployeeId,
                    Name       = name,
                    City       = city,
                    Department = department,
                    Gender     = gender,

                    HealthInsuranceProvider = healthInsProvider,
                    InsurancePlanName       = insPlanName,
                    InsuranceMonthlyFee     = insMonthlyFee,
                    InsuranceStartDate      = insStartDate,

                    EmployeeImage = employeeImage,
                    FileExtension = fileExtension,

                    ActionType = actionType
                };
                saveEmployee.InsertOrUpdate();
                //check if InsertOrUpdate, if not, dont refresh
                RefreshData();
            }
        }