public async void AddBean(BeanCreateDTO bean) { // SQL try { using (var cmd = new NpgsqlCommand( $"INSERT INTO beans(bean_name,price,aroma,colour,imageUrl) " + $"VALUES (" + $"'{bean.Name}', " + $"{bean.CostPer100g}, " + $"'{bean.Aroma}', " + $"'{bean.Colour}', " + $"'{bean.ImageUrl}'" + $")", _sqlConnection)) { await cmd.ExecuteNonQueryAsync(); cmd.Dispose(); _sqlConnection.Close(); } } catch (Exception ex) { // Post errors to a logging service Console.WriteLine(ex.InnerException); } }
public async Task <ActionResult> AddBeanToDb(BeanCreateDTO bean) { // TODO: Add check to see if table exists before pushing into it // Create table and push if not _beanRepo.AddBean(bean); // TODO: Return CreatedAtRoute to the client // This way, the client will receive an URL to the resource they just created for validation return(NoContent()); }