Esempio n. 1
0
        public void CreateEmployeeTest()
        {
            EmployeeService employeeService = new EmployeeService(uow, new Map <Employee, EmployeeDTO>());

            EmployeeDTO employee = new EmployeeDTO
            {
                EmployeeName       = "Екатерина",
                EmployeeSurname    = "Антонович",
                EmployeePatronymic = "Алексеевна",
                RoleId             = 3,
                Email = "*****@*****.**",
            };
            var         errors   = evalidator.Validate(employee);
            var         emp      = employeeService.CreateEmployee(employee);
            EmployeeDTO actual   = employeeService.GetEmployeeById(emp.Id);
            EmployeeDTO expected = new EmployeeDTO
            {
                Id                  = actual.Id,
                EmployeeName        = "Екатерина",
                EmployeeSurname     = "Антонович",
                EmployeePatronymic  = "Алексеевна",
                RoleId              = 3,
                Email               = "*****@*****.**",
                PercentOrScheduleId = 3,
                GitLink             = null,
                PhoneNumber         = null
            };

            Assert.IsTrue(errors.Count == 0 && actual.Id == expected.Id && actual.EmployeeName == expected.EmployeeName &&
                          actual.EmployeeSurname == expected.EmployeeSurname && actual.EmployeePatronymic == expected.EmployeePatronymic &&
                          actual.RoleId == expected.RoleId && actual.Email == expected.Email &&
                          actual.PercentOrScheduleId == expected.PercentOrScheduleId && (actual.PhoneNumber == expected.PhoneNumber || (string.IsNullOrEmpty(actual.PhoneNumber) && string.IsNullOrEmpty(expected.PhoneNumber))) &&
                          (actual.GitLink == expected.GitLink || (string.IsNullOrEmpty(actual.GitLink) && string.IsNullOrEmpty(expected.GitLink))));
            employeeService.DeleteEmployeeById(actual.Id);
        }
Esempio n. 2
0
        public void GivenValidEmployee_WhenValidateCalled_ThenValidResultReturned()
        {
            var validEmployee = GetValidEmployee();

            var result = _testObject.Validate(validEmployee);

            result.IsValid.Should().BeTrue();
        }
Esempio n. 3
0
        public void Add_Valid_EmployeeModel_Returns_Success()
        {
            //Arrange
            var options = TestFactory.CreateDbContextOptions("EmployeeAddDb");

            using var context = new AppDbContext(options);

            var validator = new EmployeeValidator(context);


            //add a department
            var department = new Department {
                DepartmentName = "Tech"
            };

            context.Departments.Add(department);
            context.SaveChanges();

            //Act
            var employee = new Employee
            {
                FirstName     = "John",
                LastName      = "Doe",
                ContactNumber = "1234567",
                DepartmentId  = department.DepartmentId
            };
            var result = validator.Validate(employee);

            //Assert
            Assert.Empty(result.Errors);
        }
Esempio n. 4
0
        private void AddEmpButton_Click(object sender, RoutedEventArgs e)
        {
            Employee emp = new Employee();

            emp.FirstName = FirstNameIn.Text;
            emp.LastName  = LastNameIn.Text;
            emp.JobTitle  = JobTitleIn.Text;

            EmployeeValidator validator = new EmployeeValidator();

            var results = validator.Validate(emp);

            if (results.IsValid == false)
            {
                string messageBox = "";
                foreach (ValidationFailure failure in results.Errors)
                {
                    messageBox += $"{failure.ErrorMessage}\n";
                }
                MessageBox.Show($"{messageBox}");
            }
            if (results.IsValid == true)
            {
                SqliteDataAccess.NewEmployee(emp);
                MessageBox.Show($"{emp.FullName} has been added\nto your directory!");
                Close();
                Owner.Activate();
            }
        }
        public ActionResult UpdateEmployee(EmployeeModel data)
        {
            if (data == null)
            {
                return(Jsend(JsendResult <List <ValidationFailure> > .Error("Employee data can't be null")));
            }
            var validator = new EmployeeValidator();
            ValidationResult validateResult = validator.Validate(data);

            if (validateResult.IsValid)
            {
                try
                {
                    var result = RequestHelper.MakePostWebRequest <EmployeeModel, Jsend <EmployeeModel> >(
                        $"{apiDomain}/api/Employee", data, "PUT");
                    return(Jsend(result));
                }
                catch (WebException ex)
                {
                    Console.WriteLine(ex);
                    return(Jsend(JsendResult.Error("更新員工發生錯誤")));
                }
            }
            List <ValidationFailure> failures = validateResult.Errors.ToList();

            return(Jsend(JsendResult <List <ValidationFailure> > .Fail(failures)));
        }
Esempio n. 6
0
        public void EmployeeValidateName()
        {
            //inicialización
            EmployeeValidatioResult employeeValidatioResult;

            Employee infoEmployee = new Employee
            {
                IDEmployee       = 1,
                IDDocumentType   = -1,
                NameDocumentType = "Cédula de ciudadanía\r\n",
                CodeDocumentType = "CC",
                DocumentNumber   = "123",
                FullName         = "123",
                Name             = "",
                SecondName       = "David",
                Surname          = "",
                SecondSurname    = "Zapata",
                IDSubArea        = 7,
                NameSubArea      = "Control",
                IDArea           = 2,
                NameArea         = "Administración",
                Active           = false,
                URLImage         = null,
                IDUserCreation   = 1,
                DateCreation     = Convert.ToDateTime("2020-04-27T00:00:00")
            };

            //Obtener datos
            employeeValidatioResult = EmployeeValidator.Validate(infoEmployee);

            //Resultado esperado
            Assert.IsFalse(employeeValidatioResult.ISValid);
        }
        public ActionResult EmployeeCreate([Bind(Include = "Id,FirstName,LastName,Salary,IsCEO,IsManager,ManagerId,Role")] int?Rank, Employee employee)
        {
            if (ModelState.IsValid)
            {
                if (EmployeeValidator.Validate(employee).IsValid == false)
                {
                    foreach (ValidationFailure employeeError in EmployeeValidator.Validate(employee).Errors)
                    {
                        ModelState.AddModelError(string.Empty, $"ErrorMessage: {employeeError.ErrorMessage}");
                    }
                    ViewBag.Manager = GetManagerViewBag();
                    return(View());
                }

                if (Rank.GetValueOrDefault(0) == 0)
                {
                    ModelState.AddModelError(string.Empty, "Please choose rank");
                }

                if (employee.Role.Equals(MANAGER))
                {
                    if (employee.ManagerId.GetValueOrDefault(0) == 0)
                    {
                        employee.ManagerId = employee.Id;
                    }
                }

                if (employee.Role.Equals(EMPLOYEE))
                {
                    if (employee.ManagerId.GetValueOrDefault(0) == 0)
                    {
                        ModelState.AddModelError(string.Empty, "Manager must be choosen");
                        ViewBag.Manager = GetManagerViewBag();
                        return(View(employee));
                    }
                }

                decimal CalculatedSalary = CalculateSalary.Calculate(employee, (int)Rank);
                employee.Salary = CalculatedSalary;

                db.Entry(employee).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.Manager = GetManagerViewBag();
            return(View(employee));
        }
Esempio n. 8
0
        public Jsend <List <ValidationFailure> > InsertUpdateEmployee(EmployeeModel data)
        {
            if (data == null)
            {
                return(JsendResult <List <ValidationFailure> > .Error("Employee data can't be null"));
            }
            var validator = new EmployeeValidator();
            ValidationResult validateResult = validator.Validate(data);

            if (validateResult.IsValid)
            {
                try
                {
                    var result = _uow.EmployeeTRepository.FindByID(data.EmployeeID);
                    if (result == null)
                    {
                        _uow.EmployeeTRepository.Add(new EmployeeT
                        {
                            EmployeeName     = data.EmployeeName,
                            EmployeePosition = data.EmployeePosition,
                            EmployeePhone    = data.EmployeePhone,
                            Email            = data.Email,
                            BirthdayDate     = data.BirthdayDate,
                            SignInDate       = data.SignInDate,
                            ResignedDate     = data.ResignedDate,
                            IsResigned       = data.IsResigned,
                            CompanyID        = data.CompanyID
                        });
                    }
                    else
                    {
                        _uow.EmployeeTRepository.Update(new EmployeeT
                        {
                            EmployeeID       = data.EmployeeID,
                            EmployeeName     = data.EmployeeName,
                            EmployeePosition = data.EmployeePosition,
                            EmployeePhone    = data.EmployeePhone,
                            Email            = data.Email,
                            BirthdayDate     = data.BirthdayDate,
                            SignInDate       = data.SignInDate,
                            ResignedDate     = data.ResignedDate,
                            IsResigned       = data.IsResigned,
                            Salary           = data.Salary,
                        });
                    }
                    _uow.Commit();
                }
                catch (SqlException ex)
                {
                    _logger.Error(ex);
                    return(JsendResult <List <ValidationFailure> > .Error("InsertUpdateEmployee() InsertUpdate data occured error"));
                }
                return(JsendResult <List <ValidationFailure> > .Success());
            }

            List <ValidationFailure> failures = validateResult.Errors.ToList();

            return(JsendResult <List <ValidationFailure> > .Fail(failures));
        }
        public void EmployeeValidator_OnValidade_MustFailValidation()
        {
            // Arrange
            var validator = new EmployeeValidator();

            // Act
            var results = validator.Validate(_employeeFixture.GenerateInvalidEmployee());

            // Assert
            Assert.False(results.IsValid);
            Assert.True(results.Errors.Any());
        }
 public string this[string columnName]
 {
     get
     {
         var firstOrDefault = _empValidator.Validate(this).Errors.FirstOrDefault(lol => lol.PropertyName == columnName);
         if (firstOrDefault != null)
         {
             return(_empValidator != null ? firstOrDefault.ErrorMessage : "");
         }
         return("");
     }
 }
        private bool IsEmployeeValid(Employee employee, string mode)
        {
            var validator = new EmployeeValidator(ServiceLocator.Current.GetInstance <IEmployeeManager>(), mode);
            var result    = validator.Validate(employee);

            if (result.IsValid)
            {
                return(true);
            }
            _errorsList = result.Errors;
            return(false);
        }
        public async Task <Response> Insert(EmployeeDTO employee)
        {
            Response          response = new Response();
            EmployeeValidator validate = new EmployeeValidator();
            ValidationResult  result   = validate.Validate(employee);
            Response          password = PasswordValidator.CheckPassword(employee.Password, employee.BirthDate);

            //Verifica se a senha está dentro dos padrões, caso esteja, hasheia e ela
            if (password.HasErrors())
            {
                response.Errors.Add(password.Errors.ToString());
            }
            else
            {
                employee.Password = HashUtils.HashPassword(employee.Password);
            }

            //result.MergeValidationErrors(response);


            if (!result.IsValid)
            {
                foreach (var failure in result.Errors)
                {
                    response.Errors.Add("Property " + failure.PropertyName + " failed validation. Error was: " + "(" + failure.ErrorMessage + ")");
                }

                return(response);
            }

            if (response.HasErrors())
            {
                return(response);
            }
            else
            {
                try
                {
                    employee.SystemEntranceDate = DateTime.Now;
                    employee.IsActive           = true;

                    return(response = await _iEmployeeRepository.Insert(employee));
                }
                catch (Exception ex)
                {
                    _log.Error(ex + "\nStackTrace: " + ex.StackTrace);
                    response.Errors.Add("DataBase error, contact the system owner");
                    return(response);
                }
            }
        }
        private void EditButton_Click(object sender, RoutedEventArgs e)  //When user clicks Edit button
        {
            EmployeeExists exists = new EmployeeExists();

            //Check to see if an employee has been selected from the dropdown menu to edit
            var items = exists.Validate(employee);

            if (items.IsValid == false)  //Code when no employee has been selected
            {
                string messageBox = "";
                int    count      = 0;
                foreach (ValidationFailure failure in items.Errors)
                {
                    count++;
                }

                if (count > 0)
                {
                    MessageBox.Show("Please select an employee to edit!");
                }
            }

            if (items.IsValid == true) //If employee selected, replaces all properties of the temporary employee with the user inputs from the text boxes.
            {
                EmployeeValidator validator = new EmployeeValidator();
                employee.FirstName = FirstNameIn.Text;
                employee.LastName  = LastNameIn.Text;
                employee.JobTitle  = JobTitleIn.Text;
                var results = validator.Validate(employee);
                if (results.IsValid == false)
                {
                    string messageBox = "";
                    foreach (ValidationFailure failure in results.Errors)
                    {
                        messageBox += $"{failure.ErrorMessage}\n";
                    }

                    MessageBox.Show($"{messageBox}");
                }
                if (results.IsValid == true)
                {
                    SqliteDataAccess.EditEmployee(employee);  //Open connection string to database and modify employee data where ID matches the selected employee from the dropdown menu.
                    MessageBox.Show($"{employee.FullName} has been edited successfully!");
                    Close();
                    Owner.Activate();
                }
            }
            items.Errors.Clear();
        }
Esempio n. 14
0
        private static void ImportEmployees()
        {
            var employees = new List <Employee>
            {
                new Employee // Valid entry
                {
                    EmployeeNumber = "1001",
                    ExternalId     = "1001",
                    Dob            = DateTime.Today.AddYears(-35),
                    EmployeeRating = "Meets Expectation",
                    Salary         = 150000
                },
                new Employee
                {
                    ExternalId     = "1002", // EmployeeNumber, a required field is not provided here.
                    Dob            = DateTime.Today.AddYears(-40),
                    EmployeeRating = "Outstanding",
                    Salary         = 150000
                },
                new Employee
                {
                    EmployeeNumber = "1003",
                    ExternalId     = "1003",
                    Dob            = DateTime.Today.AddYears(-45),
                    EmployeeRating = "Exceeds Expectation",
                    Salary         = 1500000 // Expect this to be caught by range validator
                },
                new Employee
                {
                    EmployeeNumber = "1004",
                    ExternalId     = "1004",
                    Dob            = DateTime.Today.AddYears(-65),
                    EmployeeRating = "Overachiever", // Expect this to be caught by custom validator
                    Salary         = 10000000
                }
            };

            var validator = new EmployeeValidator();

            foreach (var employee in employees)
            {
                var validationSummary = validator.Validate(employee);
                Console.WriteLine();
                Console.WriteLine($"Validation Errors: {JsonConvert.SerializeObject(validationSummary, Formatting.Indented)}");
            }

            Console.ReadLine();
        }
Esempio n. 15
0
        public void Empty_EmployeeModel_Returns_Error()
        {
            //Arrange
            var options = TestFactory.CreateDbContextOptions("EmployeeEmptyDb");

            using var context = new AppDbContext(options);

            var validator = new EmployeeValidator(context);
            //Act
            var result = validator.Validate(new Employee());

            //Assert
            Assert.Contains(result.Errors, e => e.PropertyName == "FirstName");
            Assert.Contains(result.Errors, e => e.PropertyName == "LastName");
            Assert.Contains(result.Errors, e => e.PropertyName == "ContactNumber");
        }
        private void DeleteButton_Click(object sender, RoutedEventArgs e)
        {
            EmployeeValidator validator = new EmployeeValidator();

            var results = validator.Validate(employee);  //Check to see if the user selected an employee from the list before allowing to delete

            if (results.IsValid == false)
            {
                string messageBox = "";
                int    count      = 0;
                foreach (ValidationFailure failure in results.Errors)
                {
                    count++;
                }

                if (count > 0)
                {
                    MessageBox.Show(this, "Please select an employee to delete.");
                }
            }
            //errors.Clear();
            if (results.IsValid == true) //Sends confirmation message to user prior to deleting Employee from database.
            {
                MessageBoxResult result = MessageBox.Show(this, $"Are you sure you want to delete {employee.EmployeeDetails}? \nWARNING, THIS ACTION CANNOT BE UNDONE", "Confirm Delete", MessageBoxButton.YesNo, MessageBoxImage.Warning);
                switch (result)
                {
                case MessageBoxResult.Yes:
                    SqliteDataAccess.DeleteEmployee(employee);
                    MessageBox.Show($"{employee.FullName} has been deleted.");
                    Close();
                    Owner.Activate();
                    break;

                case MessageBoxResult.No:
                    Close();
                    Owner.Activate();
                    break;
                }
            }
            results.Errors.Clear();
        }
Esempio n. 17
0
        public void SaveData()
        {
            EmployeeModel currentData = new EmployeeModel();

            CollectDetails(currentData);
            EmployeeValidator validator = new EmployeeValidator();
            ValidationResult  result    = validator.Validate(currentData);

            if (result.IsValid == false)
            {
                string errorMessage = (String.Join(Environment.NewLine + "   • ",
                                                   result.Errors.Select(error => error.ErrorMessage)));
                universalHelper.MessageDialog("Saving of data failed!", "   • " + errorMessage);
                return;
            }
            else
            {
                helper.SaveItem(currentData);
                ClearFields();
            }
        }
        public IActionResult Create(EmployeeModel employee)
        {
            if (!ModelState.IsValid)
            { // re-render the view when validation failed.
                var validator            = new EmployeeValidator();
                ValidationResult results = validator.Validate(employee);
                var errors = new List <string>();
                if (!results.IsValid)
                {
                    foreach (var failure in results.Errors)
                    {
                        var error = $"Property {failure.PropertyName} failed validation. Error was: {failure.ErrorMessage}";
                        errors.Add(error);
                    }
                }

                return(View("Index", employee));
            }


            return(RedirectToAction("Index"));
        }
Esempio n. 19
0
        public async Task <Response> Update(EmployeeDTO employee)
        {
            Response          response = new Response();
            EmployeeValidator validate = new EmployeeValidator();
            ValidationResult  result   = validate.Validate(employee);
            Response          password = PasswordValidator.CheckPassword(employee.Password, employee.BirthDate);

            //Verifica se a senha está dentro dos padrões, caso esteja, hasheia e ela
            if (password.HasErrors())
            {
                response.Errors.Add(password.Errors.ToString());
            }
            else
            {
                employee.Password = HashUtils.HashPassword(employee.Password);
            }

            //result.MergeValidationErrors(response);


            if (!result.IsValid)
            {
                foreach (var failure in result.Errors)
                {
                    response.Errors.Add("Property " + failure.PropertyName + " failed validation. Error was: " + "(" + failure.ErrorMessage + ")");
                }

                return(response);
            }

            if (response.HasErrors())
            {
                return(response);
            }
            else
            {
                return(await _iEmployeeRepository.Update(employee));
            }
        }
Esempio n. 20
0
        public void Duplicate_Employee_Returns_Error()
        {
            //Arrange
            var options = TestFactory.CreateDbContextOptions("EmployeeDuplicateDb");

            using var context = new AppDbContext(options);

            var validator = new EmployeeValidator(context);

            //add a department
            var department = new Department {
                DepartmentName = "Tech"
            };

            //add employee
            context.Employees.Add(new Employee
            {
                FirstName     = "John",
                LastName      = "Doe",
                ContactNumber = "1234567",
                Department    = department
            });
            context.SaveChanges();

            //Act
            var result = validator.Validate(new Employee
            {
                FirstName     = "John",
                LastName      = "Doe",
                ContactNumber = "1234567",
                Department    = department
            });

            //Assert
            Assert.NotEmpty(result.Errors);
        }
        public JsonResult ValidateUniqueNumber(int number, long?id)
        {
            var result = _employeeValidator.Validate(id, e => e.EmployeeNumber, number);

            return(JsonValidationResult(result));
        }
Esempio n. 22
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            if (cboxUserType.SelectedItem.ToString().Equals("Employee User"))
            {
                _user            = new Employee();
                _user.User_Type  = 2;
                _user.First_Name = txtFName.Text;
                _user.Last_Name  = txtLName.Text;
                _user.Address    = txtAddress.Text;
                _user.Birthday   = dpBirthday.Value.Date;
                _user.NIC        = txtNIC.Text;
                _user.Gender     = rbtnMale.Checked ? rbtnMale.Text : _user.Gender;
                _user.Gender     = rbtnFemale.Checked ? rbtnFemale.Text : _user.Gender;

                errorFName.Clear();
                ValidationResult validationResult = _employeeValidator.Validate((Employee)_user);
                if (!validationResult.IsValid)
                {
                    foreach (ValidationFailure validationResultError in validationResult.Errors)
                    {
                        if (validationResultError.PropertyName.Equals(nameof(_user.First_Name)))
                        {
                            errorFName.SetError(txtFName, validationResultError.ErrorMessage);
                        }
                        else if (validationResultError.PropertyName.Equals(nameof(_user.Last_Name)))
                        {
                            errorFName.SetError(txtLName, validationResultError.ErrorMessage);
                        }
                        else if (validationResultError.PropertyName.Equals(nameof(_user.Address)))
                        {
                            errorFName.SetError(txtAddress, validationResultError.ErrorMessage);
                        }
                        else if (validationResultError.PropertyName.Equals(nameof(_user.NIC)))
                        {
                            errorFName.SetError(txtNIC, validationResultError.ErrorMessage);
                        }

                        else if (validationResultError.PropertyName.Equals(nameof(_user.Birthday)))
                        {
                            errorFName.SetError(dpBirthday, validationResultError.ErrorMessage);
                        }

                        else if (validationResultError.PropertyName.Equals(nameof(_user.User_Type)))
                        {
                            errorFName.SetError(cboxUserType, validationResultError.ErrorMessage);
                        }
                    }
                }
                else
                {
                    if (_employeeService.AddNewEmployee(_user, StaticResource.UseType.EMPLOYEE_USER) > 0)
                    {
                        DialogResult dialogResult = MessageBox.Show("Successfully Added!\nDo you want to add more..?",
                                                                    "Result",
                                                                    MessageBoxButtons.YesNo, MessageBoxIcon.Information);

                        if (dialogResult == DialogResult.Yes)
                        {
                            clearForm();
                        }
                        else
                        {
                            Close();
                        }
                    }
                    else
                    {
                        DialogResult dialogResult = MessageBox.Show("Added Failed!", "Result",
                                                                    MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
                        if (dialogResult == DialogResult.Cancel)
                        {
                            Close();
                        }
                    }
                }
            }
            else if (cboxUserType.SelectedItem.ToString().Equals("Admin User"))
            {
                _user            = new AdminUser();
                _user.User_Type  = 1;
                _user.First_Name = txtFName.Text;
                _user.Last_Name  = txtLName.Text;
                _user.Address    = txtAddress.Text;
                _user.Birthday   = dpBirthday.Value.Date;
                _user.NIC        = txtNIC.Text;
                _user.Gender     = rbtnMale.Checked ? rbtnMale.Text : _user.Gender;
                _user.Gender     = rbtnFemale.Checked ? rbtnFemale.Text : _user.Gender;


                errorFName.Clear();
                ValidationResult validationResult = _adminValidator.Validate((AdminUser)_user);
                if (!validationResult.IsValid)
                {
                    foreach (ValidationFailure validationResultError in validationResult.Errors)
                    {
                        if (validationResultError.PropertyName.Equals(nameof(_user.First_Name)))
                        {
                            errorFName.SetError(txtFName, validationResultError.ErrorMessage);
                        }

                        else if (validationResultError.PropertyName.Equals(nameof(_user.Last_Name)))
                        {
                            errorFName.SetError(txtLName, validationResultError.ErrorMessage);
                        }

                        else if (validationResultError.PropertyName.Equals(nameof(_user.Address)))
                        {
                            errorFName.SetError(txtAddress, validationResultError.ErrorMessage);
                        }

                        else if (validationResultError.PropertyName.Equals(nameof(_user.NIC)))
                        {
                            errorFName.SetError(txtNIC, validationResultError.ErrorMessage);
                        }

                        else if (validationResultError.PropertyName.Equals(nameof(_user.Birthday)))
                        {
                            errorFName.SetError(dpBirthday, validationResultError.ErrorMessage);
                        }

                        else if (validationResultError.PropertyName.Equals(nameof(_user.User_Type)))
                        {
                            errorFName.SetError(cboxUserType, validationResultError.ErrorMessage);
                        }
                    }
                }
                else
                {
                    if (_employeeService.AddNewEmployee(_user, StaticResource.UseType.ADMIN_USER) > 0)
                    {
                        DialogResult dialogResult = MessageBox.Show("Successfully Added!\nDo you want to add more..?",
                                                                    "Result",
                                                                    MessageBoxButtons.YesNo, MessageBoxIcon.Information);

                        if (dialogResult == DialogResult.Yes)
                        {
                            clearForm();
                        }
                        else
                        {
                            Close();
                        }
                    }
                    else
                    {
                        DialogResult dialogResult = MessageBox.Show("Added Failed!", "Result",
                                                                    MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
                        if (dialogResult == DialogResult.Cancel)
                        {
                            Close();
                        }
                    }
                }
            }


            else if (cboxUserType.SelectedItem.ToString().Equals("Client"))
            {
                _user            = new Client();
                _user.User_Type  = 3;
                _user.First_Name = txtFName.Text;
                _user.Last_Name  = txtLName.Text;
                _user.Address    = txtAddress.Text;
                _user.Birthday   = dpBirthday.Value.Date;
                _user.NIC        = txtNIC.Text;
                _user.Gender     = rbtnMale.Checked ? rbtnMale.Text : _user.Gender;
                _user.Gender     = rbtnFemale.Checked ? rbtnFemale.Text : _user.Gender;


                errorFName.Clear();
                ValidationResult validationResult = _clientValidator.Validate((Client)_user);
                if (!validationResult.IsValid)
                {
                    foreach (ValidationFailure validationResultError in validationResult.Errors)
                    {
                        if (validationResultError.PropertyName.Equals(nameof(_user.First_Name)))
                        {
                            errorFName.SetError(txtFName, validationResultError.ErrorMessage);
                        }
                        else if (validationResultError.PropertyName.Equals(nameof(_user.Last_Name)))
                        {
                            errorFName.SetError(txtLName, validationResultError.ErrorMessage);
                        }
                        else if (validationResultError.PropertyName.Equals(nameof(_user.Address)))
                        {
                            errorFName.SetError(txtAddress, validationResultError.ErrorMessage);
                        }
                        else if (validationResultError.PropertyName.Equals(nameof(_user.NIC)))
                        {
                            errorFName.SetError(txtNIC, validationResultError.ErrorMessage);
                        }

                        else if (validationResultError.PropertyName.Equals(nameof(_user.Birthday)))
                        {
                            errorFName.SetError(dpBirthday, validationResultError.ErrorMessage);
                        }

                        else if (validationResultError.PropertyName.Equals(nameof(_user.User_Type)))
                        {
                            errorFName.SetError(cboxUserType, validationResultError.ErrorMessage);
                        }
                    }
                }
                else
                {
                    if (_employeeService.AddNewEmployee(_user, StaticResource.UseType.CLIENT_USER) > 0)
                    {
                        DialogResult dialogResult = MessageBox.Show("Successfully Added!\nDo you want to add more..?",
                                                                    "Result",
                                                                    MessageBoxButtons.YesNo, MessageBoxIcon.Information);

                        if (dialogResult == DialogResult.Yes)
                        {
                            clearForm();
                        }
                        else
                        {
                            Close();
                        }
                    }
                    else
                    {
                        DialogResult dialogResult = MessageBox.Show("Added Failed!", "Result",
                                                                    MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
                        if (dialogResult == DialogResult.Cancel)
                        {
                            Close();
                        }
                    }
                }
            }
        }