private bool ValidateUser(string userName, string passWord, int selectedProvider) { try { var providers = new ProviderRepository().GetAllProviders(); if (providers.Count > 0) { var providerRepository = new ProviderRepository(); if (providerRepository.ValidateUser(userName, passWord, selectedProvider)) { Session["UserName"] = userName; Session["ProviderId"] = selectedProvider; return true; } else { throw new Exception("Invalid username or password"); } } } catch (Exception ex) { throw ex; } return false; }