public Result ValidateLogin(string email, string password) { try { Result result = Result.GetInstance; PostgreConnection postgre = new PostgreConnection(); var sql = $"Select * from users where email = '{email}' "; DataSet dataResult = postgre.ExecuteQuery(sql); if (dataResult.Tables.Count == 0) { return(Result.CreateResult(true, "Email não encontrado.")); } var row = dataResult.Tables[0].Rows[0]; var user = new User(); user.idUser = ConvertDatasetToClass.validateValue(row, "idUser", 0); user.nameUser = ConvertDatasetToClass.validateValue(row, "nameUser", ""); user.email = ConvertDatasetToClass.validateValue(row, "email", ""); user.password = ConvertDatasetToClass.validateValue(row, "password", ""); if (user.password != password) { return(Result.CreateResult(true, "Senha incorreta")); } //some code return(Result.CreateResult(false, "Login efetuado com sucesso!", null)); } catch (Exception ex) { return(Result.CreateResult(true, ex.Message)); } }
/// <summary> /// Executes a transaction (a sequence of SQL sentences) from /// <para/>the "buffer". After completion of the "buffer" excecution, /// <para/>the "buffer" is cleared and buffering is disabled. /// </summary> public void EndBufferPostgreSQL() { if (buffer) { buffer = false; using (NpgsqlTransaction trans = PostgreConnection.BeginTransaction()) { using (NpgsqlCommand command = new NpgsqlCommand(sql_entry, PostgreConnection)) { command.CommandText = sql_entry; command.ExecuteNonQuery(); } trans.Commit(); } sql_entry = string.Empty; } }
protected BaseRepository(PostgreConnection connection) : base(connection) { }
/// <summary> /// The most important method in LangLib. This creates the database, /// <para/>the tables to it (MESSAGES, FORMITEMS, CULTURES). /// <para/><para/>Also the FallBackCulture is updated for the underlying form/window. /// <para/>Messages from the given <paramref name="messageResource"/> are inserted to /// <para/>the database if their don't exists. /// <para/><para/>The table fields FORMITEMS.INUSE and MESSAGES.INUSE are updated /// <para/>for the FallBackCulture. /// </summary> /// <param name="messageResource">A resource name that contains the application /// <para/>messages in the fall FallBackCulture language. /// <para/>For example if I have an application which assembly name is /// <para/>LangLibTestWinforms and it has a .resx file called Messages /// <para/>I would give this parameter a value of "LangLibTestWinforms.Messages".</param> /// <param name="culture">The culture to use for the localization. /// <para/>If no culture is given the current system culture is used and /// <para/>the FallBackCulture is used as fallback culture.</param> /// <param name="loadItems">To load language items or not.</param> public void InitalizeLanguagePostgreSQL(string messageResource, CultureInfo culture = null, bool loadItems = true) { if (culture == null) { culture = CultureInfo.CurrentCulture; } if (!Design) { try { DateTime dt = DateTime.Now; if (!Directory.Exists(DataDir)) { Directory.CreateDirectory(DataDir); } if (PostgreConnection == null) { string connStr = dbConnectionStr == string.Empty ? string.Format("Server={0};Port={1};Database={2};Uid={3};Pwd={4};", dbHost, dbPort, dbName, dbUser, dbPassword) : dbConnectionStr; PostgreConnection = new NpgsqlConnection(connStr); PostgreConnection.Open(); if (!dbNoTables) { using (NpgsqlCommand command = new NpgsqlCommand(PostgrSQLCreateLanguage1(), PostgreConnection)) // in PostgreSQL we need to create a language! { command.AllResultTypesAreUnknown = true; // void function call causes an exception otherwise command.ExecuteNonQuery(); command.CommandText = PostgrSQLCreateLanguage2(); command.ExecuteNonQuery(); } } } if (!tablesCreated && !dbNoTables) { using (NpgsqlCommand command = new NpgsqlCommand(TableCreateMessages, PostgreConnection)) { command.ExecuteNonQuery(); command.CommandText = "SELECT CREATE_LANGTABLE(); "; // conditional table creation is not possible otherways command.ExecuteNonQuery(); } using (NpgsqlCommand command = new NpgsqlCommand(TableCreateFormItems, PostgreConnection)) { command.ExecuteNonQuery(); command.CommandText = "SELECT CREATE_LANGTABLE(); "; // conditional table creation is not possible otherways command.ExecuteNonQuery(); } using (NpgsqlCommand command = new NpgsqlCommand(TableCreateCultures, PostgreConnection)) { command.ExecuteNonQuery(); command.CommandText = "SELECT CREATE_LANGTABLE(); "; // conditional table creation is not possible otherways command.ExecuteNonQuery(); } tablesCreated = true; } if (!culturesInserted && !loadItems) { string sql = string.Empty; CultureInfo[] allCultures; allCultures = CultureInfo.GetCultures(CultureTypes.AllCultures); foreach (CultureInfo ci in allCultures) { sql += InsertCulture(ci); } using (NpgsqlTransaction trans = PostgreConnection.BeginTransaction()) { using (NpgsqlCommand command = new NpgsqlCommand(sql, PostgreConnection)) { command.CommandText = sql; command.ExecuteNonQuery(); } trans.Commit(); } culturesInserted = true; } if (!loadItems) { GetGuiObjets(fallBackCulture); if (!langUseUpdated) { using (NpgsqlTransaction trans = PostgreConnection.BeginTransaction()) { using (NpgsqlCommand command = new NpgsqlCommand("UPDATE " + Schema + "FORMITEMS SET INUSE = 0 WHERE CULTURE = '" + fallBackCulture + "' ", PostgreConnection)) { command.ExecuteNonQuery(); } trans.Commit(); } langUseUpdated = true; } SaveLanguageItems(this.BaseInstance, fallBackCulture); } if (loadItems) { List <string> localProps = LocalizedPropsPostgreSQL(AppForm, CultureInfo.CurrentCulture); GetGuiObjets(CultureInfo.CurrentCulture, localProps); LoadLanguageItems(CultureInfo.CurrentCulture); } if (!loadItems) { SaveMessages(messageResource, Assembly.GetExecutingAssembly(), ref PostgreConnection); } ts = ts.Add((DateTime.Now - dt)); } catch (Exception ex) { if (ex.GetType() == typeof(MissingManifestResourceException)) // This is fun. The user actually gets some help from the exception message ;-) { throw new LangLibException(string.Format("Missing resource '{0}'.{1}Perhaps {2}.[Resource file name] would do,{3}without the .resx file extension.", messageResource, Environment.NewLine, GetAssemblyName(this.appType), Environment.NewLine)); } else { throw; } } } }
protected BaseSmallRepository(PostgreConnection connection) { Connection = connection; }
public UserRepository(PostgreConnection connection) : base(connection) { }