static public List <MarketEntity> suitablePlayers(List <MarketEntity> all, MarketEntity find) { List <MarketEntity> isSuitable = new List <MarketEntity>(); foreach (var entity in all) { if (find.MarketValue >= entity.MarketValue && find.Position == entity.Position) { isSuitable.Add(entity); } } return(isSuitable); }
public static void insert(MarketEntity newPlayer) { string sqlExpression = "INSERT INTO Players VALUES (@name, @position, @age, @marketValue, @nation, @club, @salary)"; List <SqlParameter> sp = new List <SqlParameter>() { new SqlParameter() { ParameterName = "@name", SqlDbType = SqlDbType.NVarChar, Value = newPlayer.Name }, new SqlParameter() { ParameterName = "@position", SqlDbType = SqlDbType.NVarChar, Value = newPlayer.Position }, new SqlParameter() { ParameterName = "@age", SqlDbType = SqlDbType.Int, Value = newPlayer.Age }, new SqlParameter() { ParameterName = "@marketValue", SqlDbType = SqlDbType.Money, Value = newPlayer.MarketValue }, new SqlParameter() { ParameterName = "@nation", SqlDbType = SqlDbType.NVarChar, Value = newPlayer.Nation }, new SqlParameter() { ParameterName = "@club", SqlDbType = SqlDbType.NVarChar, Value = newPlayer.Club }, new SqlParameter() { ParameterName = "@salary", SqlDbType = SqlDbType.Money, Value = newPlayer.Salary } }; using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); SqlCommand command = new SqlCommand(sqlExpression, connection); if (sp.Count > 0) { foreach (SqlParameter param in sp) { command.Parameters.Add(param); } } command.ExecuteNonQuery(); } }
public void addPlayer(object sender, EventArgs args) { inputValidation(); MarketEntity newPlayer = new MarketEntity() { Name = name.Text, Position = position.Text ?? " ", Age = int.Parse(age.Text), MarketValue = decimal.Parse(marketValue.Text.Replace('.', ',')), Nation = nation.Text ?? " ", Club = club.Text ?? " ", Salary = decimal.Parse(salary.Text.Replace('.', ',')) }; Database.insert(newPlayer); }
public void sendData(object sender, EventArgs args) { MarketEntity find = new MarketEntity(); inputValidation(); find.Position = position.Text; find.MarketValue = Decimal.Parse(budget.Text.Replace('.', ',')); List <MarketEntity> all = Database.getDatabase(); List <MarketEntity> isSuitable = Market.suitablePlayers(all, find); Session["list"] = isSuitable; if (isSuitable.Any()) { Response.Redirect("Result.aspx"); } else { Response.Redirect("Error.aspx"); } }