public bool IsExistUser(User user)
 {
     ILDAPComponent component = new LDAPComponent();
     bool results = false;
     results = component.IsExistUser(user.LoginID);
     return results;
 }
        public void Save(User user)
        {
            try
            {
                LDAPComponent ADService = new LDAPComponent();

                #region Field Validation Logic
                //Perform business logic validation here
                if (user.FirstName.Trim().Length == 0)
                {
                    throw (new Exception("FirstName is a required field"));
                }
                if (user.LastName.Trim().Length == 0)
                {
                    throw (new Exception("LastName is a required field"));
                }
                if (user.Email.Trim().Length == 0)
                {
                    throw (new Exception("Email is a required field"));
                }
                if (user.Email.Trim().Length > 0)
                {
                    Regex regex = new Regex(@"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
                    Match match = regex.Match(user.Email.Trim());
                    if (!match.Success)
                        throw (new Exception("Email is invalid format"));
                }
                if (user.LoginID.Trim().Length == 0)
                {
                    throw (new Exception("LoginID is a required field"));
                }
                if (user.LoginID.Trim().Length < 6)
                {
                    throw (new Exception("LoginID must at least 6 characters or more"));
                }
                else if(userRepository.IsExistingLoginID(user.LoginID.Trim(),user.ID))
                {
                    throw (new Exception("LoginID already exists"));
                }
                if (user.IsWindowAuthenticate == true && ADService.IsExistUser(user.LoginID) == false)
                {
                    throw (new Exception("LoginID is not valid!"));
                }
                if (user.Password != null && user.Password.Trim().Length == 0 && user.IsWindowAuthenticate == false)
                {
                    throw (new Exception("Password is a required field"));
                }
                else if (user.Password != null && user.Password.Trim().Length < 8 && user.IsWindowAuthenticate == false)
                {
                    throw (new Exception("Password must at least 8 characters"));
                }


                if (user.ID > 0)
                {
                    userRepository.Update(user);
                }
                else
                {
                    userRepository.Add(user);
                }
                //Duplicate checks
                //
                //
                //

                #endregion

      
            }
            catch (Exception ex)
            {
                //Insert error Logging/Handling Mechanism here
                throw ex;
            }
           
        }