public IActionResult Post([FromBody] Composter composter) { if (composter.Id == 0) { _db.Composters.Add(composter); _db.SaveChanges(); } else { var composterToEdit = _db.Composters.FirstOrDefault(c => c.Id == composter.Id); composterToEdit.Name = composter.Name; composterToEdit.Website = composter.Website; _db.SaveChanges(); } return(Ok()); }
public static void Initialize(IServiceProvider sp) { var db = sp.GetService <ApplicationDbContext>(); db.Database.EnsureCreated(); #region seed Composter if (!db.Composters.Any()) { var composters = new Composter[] { new Composter { Name = "Yelm Earthworm & Castings Farm", Website = "www.yelmworms.com" }, new Composter { Name = "Seattle Tilth", Website = "www.seattletilth.org" }, new Composter { Name = "Uncle Jim's Worm Farm", Website = "www.unclejimswormfarm.com" }, new Composter { Name = "Amazon", Website = "www.amazon.com" }, new Composter { Name = "3 in 1 Worm Ranch", Website = "www.3in1wormranch.com" }, new Composter { Name = "Red Worm Composting", Website = "www.redwormcomposting.com" }, };//end of var composters db.Composters.AddRange(composters); db.SaveChanges(); }//end of if Composters #endregion #region seed Product if (!db.Products.Any()) { var products = new Product[] { new Product { Name = "Red Wigglers" }, new Product { Name = "Worm Factory 360" }, new Product { Name = "Castings & Soils" }, new Product { Name = "Compost Tea" }, new Product { Name = "Garden Tower" }, new Product { Name = "Bedding" }, new Product { Name = "Starter Kits" }, };//end of var products db.Products.AddRange(products); db.SaveChanges(); }//end of if Products #endregion #region seed CompostersProducts if (!db.CompostersProducts.Any()) { var compostersProducts = new ComposterProduct[] { new ComposterProduct { ComposterId = db.Composters.FirstOrDefault(c => c.Name == "Yelm Earthworm & Castings Farm").Id, ProductId = db.Products.FirstOrDefault(p => p.Name == "Red Wigglers").Id }, new ComposterProduct { ComposterId = db.Composters.FirstOrDefault(c => c.Name == "Yelm Earthworm & Castings Farm").Id, ProductId = db.Products.FirstOrDefault(p => p.Name == "Castings & Soils").Id }, new ComposterProduct { ComposterId = db.Composters.FirstOrDefault(c => c.Name == "Yelm Earthworm & Castings Farm").Id, ProductId = db.Products.FirstOrDefault(p => p.Name == "Compost Tea").Id }, new ComposterProduct { ComposterId = db.Composters.FirstOrDefault(c => c.Name == "Seattle Tilth").Id, ProductId = db.Products.FirstOrDefault(p => p.Name == "Castings & Soils").Id }, new ComposterProduct { ComposterId = db.Composters.FirstOrDefault(c => c.Name == "Uncle Jim's Worm Farm").Id, ProductId = db.Products.FirstOrDefault(p => p.Name == "Red Wigglers").Id }, new ComposterProduct { ComposterId = db.Composters.FirstOrDefault(c => c.Name == "Uncle Jim's Worm Farm").Id, ProductId = db.Products.FirstOrDefault(p => p.Name == "Worm Factory 360").Id }, new ComposterProduct { ComposterId = db.Composters.FirstOrDefault(c => c.Name == "Uncle Jim's Worm Farm").Id, ProductId = db.Products.FirstOrDefault(p => p.Name == "Castings & Soils").Id }, new ComposterProduct { ComposterId = db.Composters.FirstOrDefault(c => c.Name == "Uncle Jim's Worm Farm").Id, ProductId = db.Products.FirstOrDefault(p => p.Name == "Compost Tea").Id }, new ComposterProduct { ComposterId = db.Composters.FirstOrDefault(c => c.Name == "Uncle Jim's Worm Farm").Id, ProductId = db.Products.FirstOrDefault(p => p.Name == "Garden Tower").Id }, new ComposterProduct { ComposterId = db.Composters.FirstOrDefault(c => c.Name == "Uncle Jim's Worm Farm").Id, ProductId = db.Products.FirstOrDefault(p => p.Name == "Bedding").Id }, new ComposterProduct { ComposterId = db.Composters.FirstOrDefault(c => c.Name == "Uncle Jim's Worm Farm").Id, ProductId = db.Products.FirstOrDefault(p => p.Name == "Starter Kits").Id }, new ComposterProduct { ComposterId = db.Composters.FirstOrDefault(c => c.Name == "Amazon").Id, ProductId = db.Products.FirstOrDefault(p => p.Name == "Red Wigglers").Id }, new ComposterProduct { ComposterId = db.Composters.FirstOrDefault(c => c.Name == "Amazon").Id, ProductId = db.Products.FirstOrDefault(p => p.Name == "Worm Factory 360").Id }, new ComposterProduct { ComposterId = db.Composters.FirstOrDefault(c => c.Name == "Amazon").Id, ProductId = db.Products.FirstOrDefault(p => p.Name == "Castings & Soils").Id }, new ComposterProduct { ComposterId = db.Composters.FirstOrDefault(c => c.Name == "Amazon").Id, ProductId = db.Products.FirstOrDefault(p => p.Name == "Compost Tea").Id }, new ComposterProduct { ComposterId = db.Composters.FirstOrDefault(c => c.Name == "3 in 1 Worm Ranch").Id, ProductId = db.Products.FirstOrDefault(p => p.Name == "Garden Tower").Id }, new ComposterProduct { ComposterId = db.Composters.FirstOrDefault(c => c.Name == "3 in 1 Worm Ranch").Id, ProductId = db.Products.FirstOrDefault(p => p.Name == "Bedding").Id }, new ComposterProduct { ComposterId = db.Composters.FirstOrDefault(c => c.Name == "3 in 1 Worm Ranch").Id, ProductId = db.Products.FirstOrDefault(p => p.Name == "Compost Tea").Id }, new ComposterProduct { ComposterId = db.Composters.FirstOrDefault(c => c.Name == "3 in 1 Worm Ranch").Id, ProductId = db.Products.FirstOrDefault(p => p.Name == "Red Wigglers").Id }, new ComposterProduct { ComposterId = db.Composters.FirstOrDefault(c => c.Name == "3 in 1 Worm Ranch").Id, ProductId = db.Products.FirstOrDefault(p => p.Name == "Castings & Soils").Id }, };//end of var compostersProducts db.CompostersProducts.AddRange(compostersProducts); db.SaveChanges(); }//end of if CompostersProducts #endregion }
public double Process(Composter x) { return(_compostProduced); }
public static void CollectInput(List <Facility> facilityList, IEquipment equipment) { bool readyToProcess = false; List <Facility> availableFacilities = facilityList; var equipmentCapacity = equipment.Capacity; do { Console.Clear(); var resourceCount = ChooseEquipment._discardList.Count; if (equipment.Name == "Egg Gatherer") { resourceCount = 0; ChooseEquipment._discardList.ForEach(resource => { IEggProducing eggRes = (IEggProducing)resource; resourceCount += eggRes.CollectEggs(); }); } if (resourceCount >= equipmentCapacity) { Console.WriteLine("You have reached the maximum number that can be processed at one time"); Console.WriteLine("Press enter to process resources"); Console.ReadLine(); readyToProcess = true; } else { Console.Clear(); if (ChooseEquipment.selectedFacility == null && equipment.Name == "Composter") { Composter compostEquipment = (Composter)equipment; Console.WriteLine($"The {equipment.Name} can process either {equipmentCapacity} plant resources or {compostEquipment.CapacityGoat} animal resources at one time."); } else { Console.WriteLine($"The {equipment.Name} can process {equipmentCapacity} resources at one time."); } Console.WriteLine($"You have currently selected {resourceCount} resources to process."); Console.WriteLine(); //if the equipment type is composter then if the discardList has resources in it, only show facilities that contain that resource, else show all the facilities if (equipment.Name == "Composter" && resourceCount != 0) { if (ChooseEquipment.selectedFacility.Type == "Grazing Field") { availableFacilities = facilityList.Where(facility => facility.Type == "Grazing Field").ToList(); } else { availableFacilities = facilityList.Where(facility => facility.Type != "Grazing Field").ToList(); } } if (resourceCount != 0) { Console.WriteLine("0. Ready to process resources"); } for (var i = 0; i < availableFacilities.Count; i++) { var currentFacility = availableFacilities[i]; Console.WriteLine($"{i + 1}. {currentFacility.Type} ({currentFacility.Total} {currentFacility.Category})"); } Console.WriteLine(); Console.WriteLine("Choose facility to process resources from."); Console.Write("> "); int facilityIndex = Int32.Parse(Console.ReadLine()) - 1; if (facilityIndex == -1) { readyToProcess = true; } else { var facilityChoosen = availableFacilities[facilityIndex]; if (equipment.Name == "Composter" && resourceCount == 0) { ChooseEquipment.selectedFacility = facilityChoosen; Composter compostEquipment = (Composter)equipment; if (ChooseEquipment.selectedFacility.Type == "Grazing Field") { equipmentCapacity = compostEquipment.CapacityGoat; } else { equipmentCapacity = compostEquipment.Capacity; } } Console.Clear(); //add only resources that the equipment can process and that have not already been selected to discard to availableResourcesList List <IResource> availableResourcesList = equipment.GetFacilityResources(facilityChoosen.Resources).Where(resource => !ChooseEquipment._discardList.Contains(resource)).ToList(); if (availableResourcesList.Count == 0) { Console.WriteLine("This facility does not have any resources that can be processed"); Console.ReadLine(); } else { var availableSpace = equipmentCapacity - resourceCount; readyToProcess = ChooseResource.CollectInput(availableResourcesList, ChooseEquipment._discardList, availableSpace, equipment); } } } }while(!readyToProcess); equipment.ProcessResources(ChooseEquipment._discardList, availableFacilities); ChooseEquipment._discardList = new List <IResource>(); ChooseEquipment.selectedFacility = null; Console.WriteLine(); Console.WriteLine("Please press enter to return to main menu"); Console.ReadLine(); }