/// <summary> /// Actualizeaza profilul unui user. /// </summary> /// <param name="user">Userul care a carui profil trebuie actualizat.</param> /// <param name="type">Tipul de actualizare (nume, parola, poza).</param> public static void ProfileUpdate(User user, ProfileUpdateType type) { string query = null; MySqlParameter parameter = null; switch(type) { case ProfileUpdateType.NameUpdate: query = string.Format("UPDATE {0} SET name = @name WHERE id = @id", Globals.TABLE_USER); parameter = new MySqlParameter("@name", user.Name); break; case ProfileUpdateType.PasswordUpdate: query = string.Format("UPDATE {0} SET password = @password WHERE id = @id", Globals.TABLE_USER); parameter = new MySqlParameter("@password", user.Password); break; case ProfileUpdateType.PhotoUpdate: query = string.Format("UPDATE {0} SET image = @image WHERE id = @id", Globals.TABLE_USER); parameter = new MySqlParameter("@image", user.Image); break; default: return; } MySqlCommand command = new MySqlCommand(query, connection); command.Parameters.Add(parameter); command.Parameters.AddWithValue("@id", user.Id); command.ExecuteNonQuery(); Destroy(command); }
public void ProfileUpdate(User user, ProfileUpdateType type) { string query; MySqlParameter parameter; if (type == ProfileUpdateType.NameUpdate) { query = "UPDATE user SET name = @name WHERE id = @id"; parameter = new MySqlParameter("@name", user.Name); } else if (type == ProfileUpdateType.PasswordUpdate) { query = "UPDATE user SET password = @password WHERE id = @id"; parameter = new MySqlParameter("@password", user.Password); } else// if(type == ProfileUpdateType.PhotoUpdate) { query = "UPDATE user SET image = @image WHERE id = @id"; parameter = new MySqlParameter("@image", user.Image); } MySqlCommand command = new MySqlCommand(query, connection); command.Parameters.Add(parameter); command.Parameters.AddWithValue("@id", user.Id); command.ExecuteNonQuery(); command.Dispose(); }