Ejemplo n.º 1
0
 public async Task <ActionResult> AddAttribute([Required, FromBody] Attribute attribute)
 {
     if (await PlantModel.AddAttribute(attribute))
     {
         return(Ok());
     }
     return(new BadRequestResult());
 }
Ejemplo n.º 2
0
        /// <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);
        }