public async Task <IActionResult> Edit(Guid id, [Bind("Id,Name")] FoodClass foodClass) { if (id != foodClass.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(foodClass); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FoodClassExists(foodClass.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(foodClass)); }
void AddCollection(ItemClass item, int amount, int foodType) { FoodClass food = null; switch (foodType) { case 0: //Raw food food = ((ItemFood)item).Raw; break; case 1: //boiled food food = ((ItemFood)item).Boil; break; case 2: //Raw food food = ((ItemFood)item).Bake; break; } if (food == null) { return; } Food.Add(food, amount); if (FoodParams) { FoodParams.Food = Food; } if (TasteParam) { TasteParam.Progress = Food.Taste; } }
// Start is called before the first frame update void Start() { SnakeClass_Access = FindObjectOfType <SnakeClass>() as SnakeClass; FoodClass_Access = FindObjectOfType <FoodClass>() as FoodClass; gamecontrol_Access = FindObjectOfType <GameController>() as GameController; ScoreManager_Access = FindObjectOfType <ScoreManager>() as ScoreManager; }
public void Edit(FoodClass foodClass) { var currentFoodClass = this.GetById(foodClass.Id); currentFoodClass.Name = foodClass.Name; Uow.FoodClasses.Edit(currentFoodClass); Uow.Commit(); }
public void Edit(FoodClass foodClass) { var currentFoodClass = this.GetById(foodClass.Id); currentFoodClass.Name = foodClass.Name; Uow.FoodClasses.Edit(currentFoodClass); Uow.Commit(); }
public void Add(FoodClass collection, int amount = 1) { for (int i = 0; i < amount; i++) { Collection.Add(collection); } Recalc(); }
public void Create(FoodClass foodClass) { if (!IsNameAvailable(foodClass.Name, foodClass.Id)) { throw new ApplicationException("Ya existe un tipo de alimento con el mismo nombre"); } Uow.FoodClasses.Add(foodClass); Uow.Commit(); }
public void Create(FoodClass foodClass) { if (!IsNameAvailable(foodClass.Name, foodClass.Id)) { throw new ApplicationException("Ya existe un tipo de alimento con el mismo nombre"); } Uow.FoodClasses.Add(foodClass); Uow.Commit(); }
public async Task <IActionResult> Create([Bind("Id,Name")] FoodClass foodClass) { if (ModelState.IsValid) { foodClass.Id = Guid.NewGuid(); _context.Add(foodClass); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(foodClass)); }
void OnTabChange(int tab) { _selectedTab = tab; switch (tab) { case 0: if (TypeText) { TypeText.text = "Raw data"; } if (_selectedItem != null) { Food = _selectedItem.Raw; } break; case 1: if (TypeText) { TypeText.text = "Boil data"; } if (_selectedItem != null) { Food = _selectedItem.Boil; } break; case 2: if (TypeText) { TypeText.text = "Bake data"; } if (_selectedItem != null) { Food = _selectedItem.Bake; } break; } if (!gameObject.activeSelf) { return; } if (CurrentInventory) { CurrentInventory.Recalc(tab); } }
public void TestLoad() { var actualClassification = _classificator.Load(); var firstLevelClass1 = new FoodClass("FirstLevelClass1"); var spAttr1 = new StoragePeriodInfo() { FromTime = TimeSpan.FromHours(48), ToTime = TimeSpan.FromDays(6 * 30), FromTemperature = 6, ToTemperature = 10, DerivedFromClass = "FirstLevelClass1" }; var spAttr2 = new StoragePeriodInfo() { FromTime = TimeSpan.FromDays(2), ToTime = TimeSpan.FromDays(3), FromTemperature = 1, ToTemperature = 3, DerivedFromClass = "FirstLevelClass1" }; firstLevelClass1.StoragePeriods = new List <StoragePeriodInfo>() { spAttr1, spAttr2 }; var secondLevelClass11 = new FoodClass("SecondLevelClass11"); secondLevelClass11.Parent = firstLevelClass1; var secondLevelClass12 = new FoodClass("SecondLevelClass12"); secondLevelClass12.Parent = firstLevelClass1; firstLevelClass1.Childs.Add(secondLevelClass11.Title, secondLevelClass11); firstLevelClass1.Childs.Add(secondLevelClass12.Title, secondLevelClass12); var firstLevelClass2 = new FoodClass("FirstLevelClass2"); var secondLevelClass21 = new FoodClass("SecondLevelClass21"); secondLevelClass21.Parent = firstLevelClass2; firstLevelClass2.Childs.Add(secondLevelClass21.Title, secondLevelClass21); var expected = new FoodClassification.Model.FoodClassification(); expected.FoodClasses.Add(firstLevelClass1.Title, firstLevelClass1); expected.FoodClasses.Add(firstLevelClass2.Title, firstLevelClass2); Assert.AreEqual(expected, actualClassification); }
public IDictionary <FridgeItem, string> GetStorageAdviceAttributes(IEnumerable <FridgeItem> fridgeItems) { var result = new Dictionary <FridgeItem, string>(); foreach (var fridgeItem in fridgeItems) { if (fridgeItem.Product.ClassificationPath != null) { var path = fridgeItem.Product.ClassificationPath; var splittedPath = path.Split(new string[] { "&&" }, StringSplitOptions.None); FoodClass foodClass = null; var foodClassChain = new Queue <FoodClass>(); IDictionary <string, FoodClass> curClassSet = FoodClassification.FoodClasses; foreach (var pathPart in splittedPath) { foodClass = curClassSet[pathPart]; foodClassChain.Enqueue(foodClass); curClassSet = foodClass.Childs; } string advice = null; while (foodClassChain.Count != 0) { var fClass = foodClassChain.Dequeue(); if (fClass.StorageAdvice != null) { advice = fClass.StorageAdvice; } } if (advice != null) { result.Add(fridgeItem, advice); } } } return(result); }
private IDictionary <string, FoodClass> _DeserializeFoodClassification(IEnumerable <XmlNode> nodes, FoodClass parent, Model.FoodClassification classification) { var foodClasses = new Dictionary <string, FoodClass>(); foreach (var node in nodes) { var xmlNode = (XmlNode)node; var className = xmlNode.Attributes["name"].Value; var newFoodClass = new FoodClass(className); if (parent != null) { newFoodClass.Parent = parent; } foodClasses.Add(className, newFoodClass); // storage attribute var storagePeriodAttributes = xmlNode.ChildNodes.Cast <XmlNode>() .Where(n => n.Name == "attribute" && n.Attributes["type"].Value == "storagePeriod"); foreach (var storPeriodAttr in storagePeriodAttributes) { // period var childPeriodNodesEnumerable = storPeriodAttr.ChildNodes.Cast <XmlNode>() .Single(n => n.Name == "period").ChildNodes.Cast <XmlNode>(); // from var fromNode = childPeriodNodesEnumerable .Single(n => n.Name == "from"); var fromQuantityNode = fromNode.ChildNodes.Cast <XmlNode>() .Single(n => n.Name == "quantity"); var fromQuantityValue = fromQuantityNode.LastChild.Value; var fromUnitNode = fromNode.ChildNodes.Cast <XmlNode>() .Single(n => n.Name == "unit"); var fromUnitValue = fromUnitNode.LastChild.Value; //to var toNode = childPeriodNodesEnumerable .Single(n => n.Name == "to"); var toQuantityNode = toNode.ChildNodes.Cast <XmlNode>() .Single(n => n.Name == "quantity"); var toQuantityValue = toQuantityNode.LastChild.Value; var toUnitNode = toNode.ChildNodes.Cast <XmlNode>() .Single(n => n.Name == "unit"); var toUnitValue = toUnitNode.LastChild.Value; // temperature var childTemperatureNodesEnumerable = storPeriodAttr.ChildNodes.Cast <XmlNode>() .Single(n => n.Name == "temperature").ChildNodes.Cast <XmlNode>(); // from var fromTemperatureNode = childTemperatureNodesEnumerable .Single(n => n.Name == "from"); var fromTemperatureValue = fromTemperatureNode.LastChild.Value; //to var toemperatureNode = childTemperatureNodesEnumerable .Single(n => n.Name == "to"); var toTemperatureValue = toemperatureNode.LastChild.Value; var storagePeriodInfo = new StoragePeriodInfo(); storagePeriodInfo.FromTime = UnitQuantityConverter.Convert(fromUnitValue, fromQuantityValue); storagePeriodInfo.ToTime = UnitQuantityConverter.Convert(toUnitValue, toQuantityValue); storagePeriodInfo.FromTemperature = int.Parse(fromTemperatureValue); storagePeriodInfo.ToTemperature = int.Parse(toTemperatureValue); storagePeriodInfo.DerivedFromClass = newFoodClass.Title; newFoodClass.StoragePeriods.Add(storagePeriodInfo); } // storage advise var storageAdviseAttribute = xmlNode.ChildNodes.Cast <XmlNode>() .SingleOrDefault(n => n.Name == "attribute" && n.Attributes["type"].Value == "storageAdvise"); if (storageAdviseAttribute != null) { var advice = storageAdviseAttribute.LastChild.Value; newFoodClass.StorageAdvice = advice; } var childClasses = _DeserializeFoodClassification(xmlNode.ChildNodes.Cast <XmlNode>().Where(n => n.Name == "class"), newFoodClass, classification); newFoodClass.Childs = childClasses; } return(foodClasses); }