public async Task <ActionResult> AddAttribute([Required, FromBody] Attribute attribute) { if (await PlantModel.AddAttribute(attribute)) { return(Ok()); } return(new BadRequestResult()); }
/// <summary> /// /// </summary> /// <param name="attribute"></param> /// <returns></returns> public static async Task <bool> AddAttribute(Attribute attribute) { bool success = false; try { using (DbConnection db = new DbConnection()) { MySqlCommand cmd = await db.GetCommandAsync(); cmd.CommandText = "INSERT INTO attribute (PlantID, AttributeDescription) " + "VALUES (@PlantID, @AttributeDescription);"; cmd.Parameters.AddWithValue("@PlantID", attribute.PlantID); cmd.Parameters.AddWithValue("@AttributeDescription", attribute.AttributeDescription); success = await cmd.ExecuteNonQueryAsync() > 0; } } catch (MySqlException ex) { } return(success); }