public bool Add(User user)
 {
     try
     {
         var hash         = new PasswordHasher <string>();
         var hashPassword = hash.HashPassword(user.Username, user.Password);
         user.Password = hashPassword;
         var usr = new DbModel.User
         {
             Id          = Guid.NewGuid(),
             Username    = user.Username,
             Password    = user.Password,
             Email       = user.Email,
             Contact     = user.Contact,
             RoleId      = user.RoleId,
             StatusId    = user.StatusId,
             CreatedDate = DateTime.UtcNow,
             CreatedBy   = _username
         };
         var result      = _userDataAccess.Add(usr);
         var returnValue = result > 0 ? true : false;
         return(returnValue);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public User Search(User user)
 {
     try
     {
         var result = new DbModel.User();
         if (!string.IsNullOrWhiteSpace(user.Username))
         {
             result = _userDataAccess.SearchByUsername(user.Username);
         }
         else if (!string.IsNullOrWhiteSpace(user.Email))
         {
             result = _userDataAccess.SearchByEmail(user.Email);
         }
         else if (Regex.Match(user.Contact.ToString(), @"^[789]\d{9}$").Success)
         {
             result = _userDataAccess.SearchByContact(user.Contact);
         }
         else
         {
             result = null;
         }
         if (result != null)
         {
             var returnValue = new User
             {
                 Id       = result.Id,
                 Username = result.Username,
                 Password = result.Password,
                 Contact  = result.Contact,
                 Email    = result.Email,
                 RoleId   = result.RoleId,
                 Role     = result.Role.Name,
                 StatusId = result.StatusId,
                 Status   = result.Status.Name
             };
             return(returnValue);
         }
         else
         {
             return(null);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }