internal bool UpdateItem() { string fullName = EditorDetails.FullName; string shortName = EditorDetails.ShortName; double inventoryAmount = EditorDetails.InventoryAmount; MeasurementUnit unit = EditorDetails.MeasurementUnit; double costPerUnit = EditorDetails.CostPerUnit; double? parQuantity = EditorDetails.ParQuantity; // Is there an ActiveItem? if (ActiveIngredient == null) { ActiveIngredient = Ingredient.Add(fullName, shortName, inventoryAmount, unit, costPerUnit, parQuantity); EditorPreparation.Update(ActiveIngredient.Id); ActiveIngredient = Ingredient.Get(ActiveIngredient.Id); } else { if (Math.Abs(ActiveIngredient.InventoryAmount - inventoryAmount) > double.Epsilon) { double originalAmount = UnitConversion.Convert(ActiveIngredient.InventoryAmount, ActiveIngredient.MeasurementUnit, unit); IngredientAdjustment.Add(SessionManager.ActiveEmployee.Id, ActiveIngredient.Id, originalAmount, inventoryAmount, unit); } if (ActiveIngredient.MeasurementUnit != unit) { IngredientAdjustment.Add(SessionManager.ActiveEmployee.Id, ActiveIngredient.Id, -1, -1, ActiveIngredient.MeasurementUnit, (int)unit); } if (EditorDetails.IsAdjustedByRecipe) { ProcessInventoryChangesForPrepIngredients( ActiveIngredient.InventoryAmount, inventoryAmount); } // Update the category values for the ActiveItem ActiveIngredient.SetFullName(fullName); ActiveIngredient.SetShortName(shortName); ActiveIngredient.SetInventoryAmount(inventoryAmount); ActiveIngredient.SetMeasurementUnit(unit); ActiveIngredient.SetCostPerUnit(costPerUnit); ActiveIngredient.SetParQuantity(parQuantity); // Update the database ActiveIngredient.Update(); EditorPreparation.Update(ActiveIngredient.Id); ActiveIngredient = Ingredient.Get(ActiveIngredient.Id); } return(true); }
public void Add(Item item) { if (empty) { content = new Ingredient(item); } else if (item.Equals(item)) { content.Add(); } }
public SmeltingRecipeBuilder AddIngredients(params ItemStack[] items) { var ingredient = new Ingredient(); foreach (var item in items) { ingredient.Add(item); } return(this); }
internal void Add(Item item = null) { if (item != null) { content = new Ingredient(item); } else if (content != null) { content.Add(); } }
public void AddIngredient_WithIncorrectDiet_DontAdd() { IngredientTestDAL dal = new(); Ingredient ingredient = new Ingredient("testIngredient", 3, dal); bool result = ingredient.Add(); Assert.IsFalse(result); Assert.AreEqual(dal.TestList.Count, 0); }
public ShapedRecipeBuilder WithKey(char key, params ItemStack[] matches) { var ingredient = new Ingredient(); foreach (var match in matches) { ingredient.Add(match); } this.key.Add(key, ingredient); return(this); }
public void FindByName_DoesExist_Return() { IngredientTestDAL dal = new(); Ingredient i = new Ingredient(name: "test", dal: dal); i.Add(dal); Ingredient shouldExist = new IngredientContainer(dal).FindByName("test"); Assert.AreEqual(shouldExist.Name, i.Name); Assert.AreEqual(shouldExist.Diet, i.Diet); }
public void AddIngredient_WithCorrectParameters_Added() { IngredientTestDAL dal = new(); Ingredient ingredient = new Ingredient("test", 0, dal); bool result = ingredient.Add(); Assert.IsTrue(result); Assert.AreEqual(dal.TestList.Count, 1); Assert.AreEqual(dal.TestList[0].Name, "test"); }
public void AddIngredient_TwoWithSameName_DontAdd() { IngredientTestDAL dal = new(); Ingredient ingredient1 = new Ingredient("testIngredient", 0, dal); Ingredient ingredient2 = new Ingredient("testIngredient", 1, dal); bool result1 = ingredient1.Add(dal); bool result2 = ingredient2.Add(dal); Assert.IsTrue(result1); Assert.IsFalse(result2); Assert.AreEqual(dal.TestList.Count, 1); Assert.AreEqual(dal.TestList[0].Diet, 0); }
public void EditIngredient_WithCorrectParameters_Update() { IngredientTestDAL dal = new(); Ingredient ingredient = new Ingredient("testIngredient", 0, dal); ingredient.Add(); int ingredientID = dal.FindByName("testIngredient").Id; Ingredient ingredient2 = new Ingredient("newName", 1, dal); bool result = ingredient2.Update("testIngredient", dal); Assert.IsTrue(result); IngredientDTO i = dal.FindByName("newName"); Assert.AreEqual(i.Id, ingredientID); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var token = serializer.Deserialize <JToken>(reader); var list = token.ToObject <List <JToken> >(); var ingredients = new List <Ingredient>(); foreach (var itemToken in list) { if (itemToken.Type == JTokenType.Array) { var items = itemToken.ToObject <List <RecipeItem> >(); var ingredient = new Ingredient(); foreach (var recipeItem in items) { if (recipeItem.Item == null && recipeItem.Tag != null) { var tag = Tags["items"].FirstOrDefault(x => x.Name.EqualsIgnoreCase(recipeItem.Tag.Replace("minecraft:", ""))); foreach (var id in tag.Entries) { var item = GetItem(id); ingredient.Add(new ItemStack(item.Type, (short)recipeItem.Count)); } } else { var i = GetItem(recipeItem.Item); ingredient.Add(new ItemStack(i.Type, (short)recipeItem.Count)); } } ingredients.Add(ingredient); } else { var recipeItem = itemToken.ToObject <RecipeItem>(); var ingredient = new Ingredient(); if (recipeItem.Item == null && recipeItem.Tag != null) { var tag = Tags["items"].FirstOrDefault(x => x.Name.EqualsIgnoreCase(recipeItem.Tag.Replace("minecraft:", ""))); foreach (var id in tag.Entries) { var item = GetItem(id); ingredient.Add(new ItemStack(item.Type, (short)ingredient.Count)); } } else { var i = GetItem(recipeItem.Item); ingredient.Add(new ItemStack(i.Type, (short)ingredient.Count)); } ingredients.Add(ingredient); } } return(new ReadOnlyCollection <Ingredient>(ingredients)); }