Пример #1
0
 internal static IEnumerable <FermentableIngredientDataModel> GetFermentableIngredientsForRecipe(int recipeId, SQLiteConnection connection)
 {
     using SQLiteCommand selectIngredientsCommand = connection.CreateCommand();
     selectIngredientsCommand.CommandText         = "SELECT FermentableIngredients.id, FermentableIngredients.amount, Fermentables.name, Fermentables.yield, Fermentables.yieldByWeight, Fermentables.color, Fermentables.origin, Fermentables.notes, Fermentables.diastaticPower, Fermentables.type, Fermentables.maltCategory, Fermentables.gravityPoint FROM FermentableIngredients " +
                                                    "JOIN FermentablesInRecipe ON FermentablesInRecipe.fermentableIngredient = FermentableIngredients.id AND FermentablesInRecipe.recipe = @recipeId " +
                                                    "JOIN Fermentables ON Fermentables.id = FermentableIngredients.fermentableInfo";
     selectIngredientsCommand.Parameters.AddWithValue("recipeId", recipeId);
     using SQLiteDataReader reader = selectIngredientsCommand.ExecuteReader();
     while (reader.Read())
     {
         string       yieldValue          = reader[3].ToString();
         float?       yield               = !yieldValue.IsNullOrEmpty() ? (float?)float.Parse(yieldValue) : null;
         string       yieldByWeightValue  = reader[4].ToString();
         float?       yieldByWeight       = !yieldByWeightValue.IsNullOrEmpty() ? (float?)float.Parse(yieldByWeightValue) : null;
         string       diastaticPowerValue = reader[8].ToString();
         float?       diastaticPower      = !diastaticPowerValue.IsNullOrEmpty() ? (float?)float.Parse(diastaticPowerValue) : null;
         string       maltCategoryValue   = reader[10].ToString();
         MaltCategory?maltCategory        = !maltCategoryValue.IsNullOrEmpty() ? EnumConverter.Parse <MaltCategory>(maltCategoryValue) : null;
         var          characteristics     = new FermentableCharacteristics(yield, reader.GetFloat(5), diastaticPower)
         {
             GravityPoint  = reader.GetInt32(11),
             Type          = EnumConverter.Parse <FermentableType>(reader.GetString(9)),
             MaltCategory  = maltCategory,
             YieldByWeight = yieldByWeight
         };
         var fermentableInfo = new Fermentable(reader.GetString(2), characteristics, reader.GetString(7), reader.GetString(6));
         yield return(new FermentableIngredientDataModel(fermentableInfo, reader.GetInt32(0))
         {
             Amount = reader.GetFloat(1)
         });
     }
 }
Пример #2
0
 public void Add(Fermentable fermentable)
 {
     using (var context = new MicrobrewitContext())
     {
         if (fermentable.Supplier != null)
         {
             fermentable.Supplier = null;
         }
         context.Entry(fermentable).State = EntityState.Added;
         try
         {
             context.SaveChanges();
         }
         catch (DbEntityValidationException dbEx)
         {
             foreach (var validationErrors in dbEx.EntityValidationErrors)
             {
                 foreach (var validationError in validationErrors.ValidationErrors)
                 {
                     Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName,
                                            validationError.ErrorMessage);
                     Log.DebugFormat("Property: {0} Error: {1}", validationError.PropertyName,
                                     validationError.ErrorMessage);
                 }
             }
         }
     }
 }
Пример #3
0
        private async Task UpdateFermantableFlavours(Fermentable fermentable, DbConnection connection, DbTransaction transaction)
        {
            await connection.ExecuteAsync("DELETE FROM fermentable_flavours WHERE fermentable_id = @FermentableId", new { fermentable.FermentableId });

            await SetCorrectFlavourId(fermentable.Flavours, connection, transaction);
            await InsertFermentableFlavours(fermentable, connection, transaction);
        }
Пример #4
0
 private async Task AddFermentableSources(Fermentable fermentable, DbConnection connection, DbTransaction transaction)
 {
     foreach (var source in fermentable?.Sources)
     {
         await connection.ExecuteAsync("INSERT INTO fermentable_sources (fermentable_id, social_id, site, url) VALUE(@FermentableId,@SocialId,@Site,@Url);", new { fermentable.FermentableId, source.SocialId, source.Site, source.Url }, transaction);
     }
 }
Пример #5
0
        public async Task <IActionResult> Edit(Guid id, [Bind("Id,Name,Version,Amount,Color,AddAfterBoil,Notes")] Fermentable fermentable)
        {
            if (id != fermentable.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(fermentable);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!FermentableExists(fermentable.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(fermentable));
        }
Пример #6
0
        public async Task AddAsync(Fermentable fermentable)
        {
            using (DbConnection connection = new NpgsqlConnection(_databaseSettings.DbConnection))
            {
                connection.Open();
                using (var transaction = connection.BeginTransaction())
                {
                    try
                    {
                        fermentable.UpdatedDate = DateTime.Now;
                        fermentable.CreatedDate = DateTime.Now;
                        var result =
                            await connection.ExecuteAsync("INSERT INTO fermentables(name,super_fermentable_id,EBC,Lovibond,PPG,supplier_id,Type,Custom,created_date,updated_date, note, must_mash, max_in_batch, protein, diastatic_power, add_after_boil, moisture, coarse_fine_diff, dry_yield) " +
                                                          "VALUES(@Name,@SuperFermentableId,@EBC,@Lovibond,@PPG,@SupplierId,@Type,@Custom,@CreatedDate,@UpdatedDate,@Note,@MustMash,@MaxInBatch, @Protein, @DiastaticPower, @AddAfterBoil, @Moisture, @CoarseFineDiff, @DryYield);", fermentable, transaction);

                        var fermentableId = await connection.QueryAsync <int>("SELECT last_value FROM fermentables_seq;");

                        fermentable.FermentableId = fermentableId.SingleOrDefault();
                        await AddFermentableFlavours(fermentable, connection, transaction);

                        transaction.Commit();
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                        throw;
                    }
                }
            }
        }
 public void Update(Fermentable fermentable)
 {
     using (var context = DapperHelper.GetConnection())
     {
         context.Open();
         using (var transaction = context.BeginTransaction())
         {
             try
             {
                 context.Execute("Update Fermentables set Name = @Name,SuperFermentableId = @SuperFermentableId,EBC = @EBC,Lovibond = @Lovibond,PPG= @PPG,SupplierId = @SupplierId,Type = @Type, Custom = @Custom " +
                                 "WHERE FermentableId = @FermentableId;",
                                 new
                 {
                     fermentable.FermentableId,
                     fermentable.Name,
                     fermentable.SuperFermentableId,
                     fermentable.EBC,
                     fermentable.Lovibond,
                     fermentable.PPG,
                     fermentable.SupplierId,
                     fermentable.Type,
                     fermentable.Custom,
                 }, transaction);
                 transaction.Commit();
             }
             catch (Exception e)
             {
                 Log.Error(e.ToString());
                 transaction.Rollback();
                 throw;
             }
         }
     }
 }
Пример #8
0
 public virtual async Task AddAsync(Fermentable fermentable)
 {
     using (var context = new MicrobrewitContext())
     {
         if (fermentable.Supplier != null)
         {
             fermentable.Supplier = null;
         }
         context.Entry(fermentable).State = EntityState.Added;
         try
         {
             await context.SaveChangesAsync();
         }
         catch (DbEntityValidationException dbEx)
         {
             //foreach (var validationErrors in dbEx.EntityValidationErrors)
             //{
             //    foreach (var validationError in validationErrors.ValidationErrors)
             //    {
             //        Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
             //        Log.DebugFormat("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
             //        throw dbEx;
             //    }
             //}
             throw;
         }
         catch (Exception ex)
         {
             throw;
         }
     }
 }
Пример #9
0
        public void Fermentable_Invalid_CombinationErrorCode()
        {
            string          fermentableName = "Ferm";
            FermentableType type            = FermentableType.Dry_Extract;
            double          amount          = 14;
            double          yield           = 50;
            double          color           = 40;

            Fermentable ferm = new Fermentable(
                fermentableName,
                type,
                amount,
                yield,
                color);

            ferm.Ibu_Gal_Per_Lb = 5;
            ferm.Moisture       = 5;

            ValidationCode errorCode = ValidationCode.SUCCESS;

            ValidationCode expected = ValidationCode.HOPPED_FERMENTABLE_EXTRACT_ONLY | ValidationCode.GRAIN_DETAILS_ONLY_GRAIN_TYPE;

            ferm.IsValid(ref errorCode);

            Assert.AreEqual(expected, errorCode);
        }
Пример #10
0
 private async Task UpdateFermentableSources(Fermentable fermentable, DbConnection connection, DbTransaction transaction)
 {
     foreach (var source in fermentable?.Sources)
     {
         await connection.ExecuteAsync("UPDATE fermentable_sources SET site = @Site, url = @Url WHERE fermentable_id = @FermentableId AND social_id = @SocialId;", new { fermentable.FermentableId, source.SocialId, source.Site, source.Url }, transaction);
     }
 }
Пример #11
0
        private void AddFermentableIngredient(Fermentable fermentable)
        {
            FermentableIngredientDataModel fermentableIngredient = FermentableUtility.CreateFermentableIngredient(fermentable, CurrentRecipe.RecipeId);

            fermentableIngredient.PropertyChanged += CurrentRecipe.Ingredient_PropertyChanged;
            CurrentRecipe.FermentableIngredients.Add(fermentableIngredient);
        }
Пример #12
0
        public async Task <IActionResult> PutFermentable(int id, Fermentable fermentable)
        {
            if (id != fermentable.IngredientId)
            {
                return(BadRequest());
            }

            _context.Entry(fermentable).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FermentableExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #13
0
        public async Task <Fermentable> SaveFermentable(Fermentable fermentable, string userEmail)
        {
            var db = _mongoClient.GetDatabase("BeerDb");
            var mongoCollection = db.GetCollection <FermentableCollection>("Fermentables");
            var query           = Builders <FermentableCollection> .Filter.Eq(f => f.UserEmail, userEmail);

            var fermCollections = await mongoCollection.Find(query).ToListAsync();

            FermentableCollection usersCollection = null;

            if (fermCollections == null || fermCollections.Count == 0)
            {
                usersCollection = CreateNewFermentableCollection(userEmail, mongoCollection);
            }
            else
            {
                //should only be one collection per user
                usersCollection = fermCollections[0];
            }
            var fermToUpdate = usersCollection.Fermentables.SingleOrDefault(f => f.Id == fermentable.Id);

            if (fermToUpdate == null)
            {
                fermentable.Id = Guid.NewGuid();
            }
            else
            {
                usersCollection.Fermentables.Remove(fermToUpdate);
            }
            usersCollection.Fermentables.Add(fermentable);
            var filter = Builders <FermentableCollection> .Filter.Eq(f => f.Id, usersCollection.Id);

            mongoCollection.ReplaceOne(filter, usersCollection);
            return(fermentable);
        }
Пример #14
0
        public async Task <int> UpdateAsync(Fermentable fermentable)
        {
            using (DbConnection connection = new NpgsqlConnection(_databaseSettings.DbConnection))
            {
                connection.Open();
                using (var transaction = connection.BeginTransaction())
                {
                    try
                    {
                        fermentable.UpdatedDate = DateTime.Now;
                        var result = await connection.ExecuteAsync(
                            "Update Fermentables set Name = @Name,super_fermentable_id = @SuperFermentableId,EBC = @EBC," +
                            "Lovibond = @Lovibond,PPG= @PPG,supplier_id = @SupplierId,Type = @Type, Custom = @Custom, dry_yield = @DryYield," +
                            "updated_date = @UpdatedDate, note = @Note, must_mash = @MustMash, max_in_batch = @MaxInBatch, coarse_fine_diff = @CoarseFineDiff" +
                            "protein = @Protein, diastatic_power = @DiastaticPower, add_after_boil = @AddAfterBoil, moisture = @Moisture " +
                            "WHERE fermentable_id = @FermentableId;",
                            fermentable, transaction);
                        await UpdateFermantableFlavours(fermentable, connection, transaction);
                        await UpdateFermentableSources(fermentable, connection, transaction);

                        transaction.Commit();
                        return(result);
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                        throw;
                    }
                }
            }
        }
Пример #15
0
 public ActionResult CreateFermentable(FermentableViewModel vm)
 {
     try
     {
         using (var context = new Models.ModelsContext())
         {
             Fermentable newFermentable = new Fermentable();
             newFermentable.CoarseFineDiff = (float) (vm.CourseGrainYield - vm.Yield);
             newFermentable.Color = vm.Color;
             newFermentable.DiastaticPower = (float) vm.DiastaticPower;
             newFermentable.Name = vm.Name;
             newFermentable.Yield = (float) vm.Yield;
             newFermentable.IBUs = (float) vm.IBU;
             context.Fermentables.Add(newFermentable);
             context.SaveChanges();
             if (Request.IsAjaxRequest())
             {
                 return PartialView("~/Views/Ingredients/DisplayTemplates/FermentableViewModel.cshtml", vm);
             }
             else
             {
                 return RedirectToAction("Show", new {name = vm.Name, type = "fermentable"});
             }
         }
     }
     catch (Exception e)
     {
         return PartialView("~/Views/Ingredients/EditorTemplates/HopViewModel.cshtml", vm);
     }
 }
Пример #16
0
        public static FermentableIngredientDataModel CreateFermentableIngredient(Fermentable fermentableInfo, int recipeId)
        {
            using SQLiteConnection connection = DatabaseUtility.GetNewConnection();
            var fermentableIngredient = CreateFermentableIngredient(fermentableInfo, recipeId, connection);

            connection.Close();
            return(fermentableIngredient);
        }
Пример #17
0
 public virtual void Update(Fermentable fermentable)
 {
     using (var context = new MicrobrewitContext())
     {
         context.Entry(fermentable).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Пример #18
0
 public ActionResult CreateFermentable(Fermentable fermentable)
 {
     if (!IsContentCreator())
     {
         return(new ForbidResult());
     }
     _logger.LogInformation("Creating fermentable '{name}'", fermentable.Name);
     _homebrewingDbService.CreateFermentable(fermentable);
     return(new OkResult());
 }
Пример #19
0
 public static FermentableIngredientDataModel CreateFermentableIngredient(Fermentable fermentableInfo, int recipeId)
 {
     FermentableIngredientDataModel fermentableIngredient = null;
     using (SQLiteConnection connection = DatabaseUtility.GetNewConnection())
     {
         fermentableIngredient = CreateFermentableIngredient(fermentableInfo, recipeId, connection);
         connection.Close();
     }
     return fermentableIngredient;
 }
        public void Add_Gets_Added()
        {
            var newFermentable = new Fermentable {
                Name = "newFermentable" + DateTime.Now.Ticks, Type = "Grain", Custom = true
            };

            _fermentableRepository.Add(newFermentable);
            var fermentables = _fermentableRepository.GetAll();

            Assert.True(fermentables.Any(o => o.Name == newFermentable.Name));
        }
        public async Task AddAsync_Gets_Added()
        {
            var newFermentable = new Fermentable {
                Name = "newFermentable" + DateTime.Now.Ticks, Type = "Grain", Custom = true
            };
            await _fermentableRepository.AddAsync(newFermentable);

            var fermentables = await _fermentableRepository.GetAllAsync(0, 20);

            Assert.True(fermentables.Any(o => o.Name == newFermentable.Name));
        }
        public void Add_FermentableId_Gets_Set()
        {
            var newFermentable = new Fermentable {
                Name = "newFermentable" + DateTime.Now.Ticks, Type = "Grain", Custom = true
            };

            _fermentableRepository.Add(newFermentable);
            var fermentable = _fermentableRepository.GetSingle(newFermentable.FermentableId);

            Assert.NotNull(fermentable);
        }
        public void Remove_Gets_Removed()
        {
            var newFermentable = new Fermentable {
                Name = "newFermentable" + DateTime.Now.Ticks, Type = "Grain", Custom = true
            };

            _fermentableRepository.Add(newFermentable);
            _fermentableRepository.Remove(newFermentable);
            var fermentables = _fermentableRepository.GetAll();

            Assert.True(fermentables.All(o => o.FermentableId != newFermentable.FermentableId));
        }
Пример #24
0
        public async Task <IActionResult> Create([Bind("Id,Name,Version,Amount,Color,AddAfterBoil,Notes")] Fermentable fermentable)
        {
            if (ModelState.IsValid)
            {
                fermentable.Id = Guid.NewGuid();
                _context.Add(fermentable);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(fermentable));
        }
        public async Task RemoveAsync_Gets_Removed()
        {
            var newFermentable = new Fermentable {
                Name = "newFermentable" + DateTime.Now.Ticks, Type = "Grain", Custom = true
            };
            await _fermentableRepository.AddAsync(newFermentable);

            await _fermentableRepository.RemoveAsync(newFermentable);

            var fermentables = await _fermentableRepository.GetAllAsync(0, 20);

            Assert.True(fermentables.All(o => o.FermentableId != newFermentable.FermentableId));
        }
        public IActionResult Update(string oid, [FromBody] Fermentable fermentable)
        {
            var fermentableDb = _fermentableRepository.Find(x => x.Oid == new Guid(oid));

            fermentableDb.Name        = fermentable.Name;
            fermentableDb.Description = fermentable.Description;
            fermentableDb.Link        = fermentable.Link;
            fermentableDb.Vendor      = fermentable.Vendor;

            _fermentableRepository.Update(fermentableDb);

            _unitOfWork.Complete();
            return(Ok(fermentableDb));
        }
Пример #27
0
        public void GetColorInSrmTest()
        {
            Fermentable crystal60 = new Fermentable("Caramel/Crystal Malt - 60L", new FermentableCharacteristics(74, 60, 0) { Type = FermentableType.Grain }, "Test Notes", "US");
            FermentableIngredient crystal60InRecipe = new FermentableIngredient(crystal60) { Amount = 0.50f };

            double crystal60Color = ColorUtility.GetColorInSrm(new[] { crystal60InRecipe }, 5);
            Assert.AreEqual(5.1, crystal60Color);

            Fermentable marisOtter = new Fermentable("Pale Malt, Maris Otter", new FermentableCharacteristics(82.5f, 3, 120) { Type = FermentableType.Grain }, "Test Notes", "US");
            FermentableIngredient marisOtterInRecipe = new FermentableIngredient(marisOtter) { Amount = 8 };

            List<FermentableIngredient> fermentablesUsed = new List<FermentableIngredient>() { marisOtterInRecipe, crystal60InRecipe };
            double colorInSrm = ColorUtility.GetColorInSrm(fermentablesUsed, 5);
            Assert.AreEqual(7.6, colorInSrm);
        }
Пример #28
0
 public BreweryDb(string key)
 {
     _key         = key;
     Adjunct      = new Adjunct(_client, _baseAddress, _key);
     Brewery      = new Brewery(_client, _baseAddress, _key);
     Yeast        = new Yeast(_client, _baseAddress, _key);
     Style        = new Style(_client, _baseAddress, _key);
     SocialSite   = new SocialSite(_client, _baseAddress, _key);
     Ingredient   = new Ingredient(_client, _baseAddress, _key);
     Hop          = new Hop(_client, _baseAddress, _key);
     BeerCategory = new BeerCategory(_client, _baseAddress, _key);
     Beer         = new Beer(_client, _baseAddress, _key);
     Feature      = new Feature(_client, _baseAddress, _key);
     Fermentable  = new Fermentable(_client, _baseAddress, _key);
 }
Пример #29
0
        public void GetSpecificAndFinalGravityTest()
        {
            Fermentable crystal60 = new Fermentable("Caramel/Crystal Malt - 60L", new FermentableCharacteristics(74, 60, 0) { Type = FermentableType.Grain, GravityPoint = 34 }, "Test Notes", "US");
            FermentableIngredient crystal60InRecipe = new FermentableIngredient(crystal60) { Amount = 0.50f };
            Fermentable chocolateMalt = new Fermentable("Chocolate Malt", new FermentableCharacteristics(60, 350, 0) { Type = FermentableType.Grain, GravityPoint = 28 }, "Test Notes", "US");
            FermentableIngredient chocolateMaltInRecipe = new FermentableIngredient(chocolateMalt) { Amount = 1 };
            Fermentable marisOtter = new Fermentable("Pale Malt, Maris Otter", new FermentableCharacteristics(82.5f, 3, 120) { Type = FermentableType.Grain, GravityPoint = 38 }, "Test Notes", "US");
            FermentableIngredient marisOtterInRecipe = new FermentableIngredient(marisOtter) { Amount = 8 };

            List<FermentableIngredient> fermentablesInRecipe = new List<FermentableIngredient>() { crystal60InRecipe, chocolateMaltInRecipe, marisOtterInRecipe };
            float actualSpecificGravity = AlcoholUtility.GetOriginalGravity(fermentablesInRecipe, 5, 70);
            Assert.AreEqual(1.049f, actualSpecificGravity);
            float actualFinalGravity = AlcoholUtility.GetFinalGravity(actualSpecificGravity, 75);
            Assert.AreEqual(1.012f, actualFinalGravity);
        }
Пример #30
0
        internal static FermentableIngredientDataModel CreateFermentableIngredient(Fermentable fermentableInfo, int recipeId, SQLiteConnection connection)
        {
            using SQLiteCommand insertIngredientCommand = connection.CreateCommand();
            insertIngredientCommand.CommandText         = "INSERT INTO FermentableIngredients (amount, fermentableInfo) VALUES(0, (SELECT id FROM Fermentables WHERE name = @name))";
            insertIngredientCommand.Parameters.AddWithValue("name", fermentableInfo.Name);
            insertIngredientCommand.ExecuteNonQuery();
            var fermentableIngredient = new FermentableIngredientDataModel(fermentableInfo, DatabaseUtility.GetLastInsertedRowId(connection));

            using SQLiteCommand insertJunctionCommand = connection.CreateCommand();
            insertJunctionCommand.CommandText         = "INSERT INTO FermentablesInRecipe (fermentableIngredient, recipe) VALUES(@fermentableIngredientId, @recipeId)";
            insertJunctionCommand.Parameters.AddWithValue("fermentableIngredientId", fermentableIngredient.FermentableId);
            insertJunctionCommand.Parameters.AddWithValue("recipeId", recipeId);
            insertJunctionCommand.ExecuteNonQuery();
            return(fermentableIngredient);
        }
Пример #31
0
 public virtual async Task <int> UpdateAsync(Fermentable fermentable)
 {
     using (var context = new MicrobrewitContext())
     {
         context.Entry(fermentable).State = EntityState.Modified;
         try
         {
             return(await context.SaveChangesAsync());
         }
         catch (Exception e)
         {
             throw;
         }
     }
 }
Пример #32
0
 public virtual async Task RemoveAsync(Fermentable fermentable)
 {
     using (var context = new MicrobrewitContext())
     {
         context.Entry(fermentable).State = EntityState.Deleted;
         try
         {
             await context.SaveChangesAsync();
         }
         catch (Exception e)
         {
             Log.Debug(e);
             throw;
         }
     }
 }
Пример #33
0
        public void Fermentable_Valid()
        {
            string          fermentableName = "Ferm";
            FermentableType type            = FermentableType.Extract;
            double          amount          = 14;
            double          yield           = 50;
            double          color           = 40;

            Fermentable ferm = new Fermentable(
                fermentableName,
                type,
                amount,
                yield,
                color);

            Assert.IsTrue(ferm.IsValid());
        }
Пример #34
0
        internal static FermentableIngredientDataModel CreateFermentableIngredient(Fermentable fermentableInfo, int recipeId, SQLiteConnection connection)
        {
            using (SQLiteCommand insertIngredientCommand = connection.CreateCommand())
            {
                insertIngredientCommand.CommandText = "INSERT INTO FermentableIngredients (amount, fermentableInfo) VALUES(0, (SELECT id FROM Fermentables WHERE name = @name))";
                insertIngredientCommand.Parameters.AddWithValue("name", fermentableInfo.Name);
                insertIngredientCommand.ExecuteNonQuery();
            }
            FermentableIngredientDataModel fermentableIngredient = new FermentableIngredientDataModel(fermentableInfo, DatabaseUtility.GetLastInsertedRowId(connection));

            using (SQLiteCommand insertJunctionCommand = connection.CreateCommand())
            {
                insertJunctionCommand.CommandText = "INSERT INTO FermentablesInRecipe (fermentableIngredient, recipe) VALUES(@fermentableIngredientId, @recipeId)";
                insertJunctionCommand.Parameters.AddWithValue("fermentableIngredientId", fermentableIngredient.FermentableId);
                insertJunctionCommand.Parameters.AddWithValue("recipeId", recipeId);
                insertJunctionCommand.ExecuteNonQuery();
            }
            return fermentableIngredient;
        }
Пример #35
0
        public void Fermentable_Invalid_Extract_InvalidParam_CoarseFineDiff()
        {
            string          fermentableName = "Ferm";
            FermentableType type            = FermentableType.Extract;
            double          amount          = 14;
            double          yield           = 50;
            double          color           = 40;

            Fermentable ferm = new Fermentable(
                fermentableName,
                type,
                amount,
                yield,
                color);

            ferm.Coarse_Fine_Diff = 5;

            Assert.IsFalse(ferm.IsValid());
        }
Пример #36
0
 public FermentableIngredient(Fermentable fermentableInfo)
 {
     m_fermentableInfo = fermentableInfo;
 }
Пример #37
0
        /// <summary>
        /// Adds a fermentable item to the data set.
        /// </summary>
        public Fermentable AddFermentable(string name, FermentableType fermentableType, string notes)
        {
            Fermentable fermentable = new Fermentable(name, fermentableType);

            fermentable.Notes = notes;

            return fermentable;

            //<NAME>Barley Hulls</NAME>
            // <VERSION>1</VERSION>
            // <TYPE>Adjunct</TYPE>
            // <AMOUNT>0.0000000</AMOUNT>
            // <YIELD>0.0000000</YIELD>
            // <COLOR>0.0000000</COLOR>
            // <ADD_AFTER_BOIL>FALSE</ADD_AFTER_BOIL>
            // <ORIGIN>US</ORIGIN>
            // <SUPPLIER></SUPPLIER>
            // <NOTES>Hulls are introduced to improve the speed of lautering when making high gravity or high adjunct beers.
            //Hulls are neutral in flavor, body and color, and are inert
            //Good for wheat beers, Wits, and others that have high protein mashes.</NOTES>
            // <COARSE_FINE_DIFF>1.5000000</COARSE_FINE_DIFF>
            // <MOISTURE>4.0000000</MOISTURE>
            // <DIASTATIC_POWER>120.0000000</DIASTATIC_POWER>
            // <PROTEIN>11.7000000</PROTEIN>
            // <MAX_IN_BATCH>5.0000000</MAX_IN_BATCH>
            // <RECOMMEND_MASH>FALSE</RECOMMEND_MASH>
            // <IBU_GAL_PER_LB>0.0000000</IBU_GAL_PER_LB>
            // <DISPLAY_AMOUNT>0.0 oz</DISPLAY_AMOUNT>
            // <INVENTORY>0.0 oz</INVENTORY>
            // <POTENTIAL>1.0000000</POTENTIAL>
            // <DISPLAY_COLOR>0.0 SRM</DISPLAY_COLOR>
            // <EXTRACT_SUBSTITUTE></EXTRACT_SUBSTITUTE>
        }
Пример #38
0
 internal static IEnumerable<FermentableIngredientDataModel> GetFermentableIngredientsForRecipe(int recipeId, SQLiteConnection connection)
 {
     using (SQLiteCommand selectIngredientsCommand = connection.CreateCommand())
     {
         selectIngredientsCommand.CommandText = "SELECT FermentableIngredients.id, FermentableIngredients.amount, Fermentables.name, Fermentables.yield, Fermentables.yieldByWeight, Fermentables.color, Fermentables.origin, Fermentables.notes, Fermentables.diastaticPower, Fermentables.type, Fermentables.maltCategory, Fermentables.gravityPoint FROM FermentableIngredients " +
             "JOIN FermentablesInRecipe ON FermentablesInRecipe.fermentableIngredient = FermentableIngredients.id AND FermentablesInRecipe.recipe = @recipeId " +
             "JOIN Fermentables ON Fermentables.id = FermentableIngredients.fermentableInfo";
         selectIngredientsCommand.Parameters.AddWithValue("recipeId", recipeId);
         using (SQLiteDataReader reader = selectIngredientsCommand.ExecuteReader())
         {
             while (reader.Read())
             {
                 string yieldValue = reader[3].ToString();
                 float? yield = !yieldValue.IsNullOrEmpty() ? (float?) float.Parse(yieldValue) : null;
                 string yieldByWeightValue = reader[4].ToString();
                 float? yieldByWeight = !yieldByWeightValue.IsNullOrEmpty() ? (float?) float.Parse(yieldByWeightValue) : null;
                 string diastaticPowerValue = reader[8].ToString();
                 float? diastaticPower = !diastaticPowerValue.IsNullOrEmpty() ? (float?) float.Parse(diastaticPowerValue) : null;
                 string maltCategoryValue = reader[10].ToString();
                 MaltCategory? maltCategory = !maltCategoryValue.IsNullOrEmpty() ? (MaltCategory?) EnumConverter.Parse<MaltCategory>(maltCategoryValue) : null;
                 FermentableCharacteristics characteristics = new FermentableCharacteristics(yield, reader.GetFloat(5), diastaticPower)
                 {
                     GravityPoint = reader.GetInt32(11),
                     Type = EnumConverter.Parse<FermentableType>(reader.GetString(9)),
                     MaltCategory = maltCategory,
                     YieldByWeight = yieldByWeight
                 };
                 Fermentable fermentableInfo = new Fermentable(reader.GetString(2), characteristics, reader.GetString(7), reader.GetString(6));
                 yield return new FermentableIngredientDataModel(fermentableInfo, reader.GetInt32(0)) { Amount = reader.GetFloat(1) };
             }
         }
     }
 }