public HttpResponseMessage PostNewPlantGroups(HttpRequestMessage request, [FromBody] EditPlantDTO editPlant) { if (!ModelState.IsValid) { return(request.CreateResponse(HttpStatusCode.BadRequest, editPlant)); } try { var plantId = editPlant.PlantId; foreach (var group in editPlant.GroupDetails) { var thisPlantGroup = new PlantGroup(); thisPlantGroup.PlantId = plantId; thisPlantGroup.GroupId = group.GroupId; db.PlantGroups.Add(thisPlantGroup); } db.SaveChanges(); return(request.CreateResponse(HttpStatusCode.OK, editPlant)); } catch (Exception ex) { return(request.CreateResponse(HttpStatusCode.BadRequest, ex)); } }
public void DeletePlantFromPlantGroup(string gardenName, string plantGroupName, string plantName, string accountID) { if (string.IsNullOrEmpty(gardenName)) { throw new ArgumentException("message", nameof(gardenName)); } if (string.IsNullOrEmpty(plantGroupName)) { throw new ArgumentException("message", nameof(plantGroupName)); } if (string.IsNullOrEmpty(plantName)) { throw new ArgumentException("message", nameof(plantName)); } Garden garden = GardenRepository.GetByName(gardenName, accountID); PlantGroup plantGroup = PlantGroupRepository.GetByName(plantGroupName, accountID); Plant plant = PlantRepository.GetByName(plantName); //Not sure this is needed? plantGroup.DeletePlant(plant); PlantGroupRepository.DeletePlantFromPlantGroup(plantGroup, plant, accountID); }
public HttpResponseMessage PostPlant(HttpRequestMessage request, [FromBody] NewPlantDTO newPlant) { if (!ModelState.IsValid) { return(request.CreateResponse(HttpStatusCode.BadRequest, newPlant)); } try { var thisPlant = new PlantName(); thisPlant.Name = newPlant.Name; thisPlant.Sku = newPlant.Sku; db.PlantNames.Add(thisPlant); //Add the plant to the database db.SaveChanges(); //Save the changes db.Entry(thisPlant).Reload(); //reload the entry so that we are able to get the plant id var plantId = thisPlant.PlantId; //this can then be used to assign to the plant groups foreach (var group in newPlant.GroupDetails) { var thisPlantGroup = new PlantGroup(); thisPlantGroup.PlantId = plantId; thisPlantGroup.GroupId = group.GroupId; db.PlantGroups.Add(thisPlantGroup); } db.SaveChanges(); return(request.CreateResponse(HttpStatusCode.OK, newPlant)); } catch (Exception ex) { return(request.CreateResponse(HttpStatusCode.BadRequest, ex)); } }
public void AddPlantToPlantGroup(string gardenName, string plantGroupName, string plantName, string accountID) { if (string.IsNullOrEmpty(gardenName)) { throw new ArgumentException("message", nameof(gardenName)); } if (string.IsNullOrEmpty(plantGroupName)) { throw new ArgumentException("message", nameof(plantGroupName)); } if (string.IsNullOrEmpty(plantName)) { throw new ArgumentException("message", nameof(plantName)); } Garden garden = GardenRepository.GetByName(gardenName, accountID); PlantGroup plantGroup = PlantGroupRepository.GetByName(plantGroupName, accountID); Plant plant = PlantRepository.GetByName(plantName); plantGroup.AddPlant(plant); PlantGroupRepository.AddPlantToPlantGroup(plantGroup, plant, accountID); //should be update }
public ActionResult RemoveConfirm(int?PlantGroupId) { PlantGroup group = db.PlantGroups.Find(PlantGroupId); db.PlantGroups.Remove(group); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult DeleteConfirmed(int id) { PlantGroup plantGroup = db.PlantGroups.Find(id); db.PlantGroups.Remove(plantGroup); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "PlantGroupId,PlantId,GroupId")] PlantGroup plantGroup) { if (ModelState.IsValid) { db.PlantGroups.Add(plantGroup); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.GroupId = new SelectList(db.Groups, "GroupId", "Description", plantGroup.GroupId); ViewBag.PlantId = new SelectList(db.PlantNames, "PlantId", "Sku", plantGroup.PlantId); return(View(plantGroup)); }
// GET: PlantGroups/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PlantGroup plantGroup = db.PlantGroups.Find(id); if (plantGroup == null) { return(HttpNotFound()); } return(View(plantGroup)); }
public static void CollectInput(Farm farm, ICompostProducing plant) { foreach (NaturalField field in farm.NaturalFields) { if (field.Plants.Count < field.Capacity) { StringBuilder output = new StringBuilder(); output.Append($"{farm.NaturalFields.IndexOf(field)+1}. Natural Field ("); if (field.Plants.Count == 0) { output.Append("0"); } else { //group by List <TypeCounter> plantCount = ( from flower in field.Plants group flower by flower.Type into PlantGroup select new TypeCounter { Type = PlantGroup.Key, Count = PlantGroup.Count() } ).ToList(); foreach (TypeCounter entry in plantCount) { // TODO: remove trailing comma output.Append($"{entry.Count} {entry.Type},"); } } output.Append($" of {field.Capacity} rows)"); Console.WriteLine(output); //Console.WriteLine ($"{farm.NaturalFields.IndexOf(field)+1}. Natural Field ({field.Plants.Count} of {field.Capacity} rows)"); } } Console.WriteLine(); Console.WriteLine($"Plant the seeds where?"); Console.Write("> "); int choice = Int32.Parse(Console.ReadLine()); try { farm.NaturalFields[choice - 1].AddResource(farm, plant); } catch (ArgumentOutOfRangeException) { Console.WriteLine($"Invalid option: {choice}"); Console.WriteLine("Press any key to go back to main menu."); Console.ReadLine(); } }
public ActionResult Edit([Bind(Include = "PlantGroupId,PlantId,GroupId")] PlantGroup plantGroup) { var found = db.PlantGroups.FirstOrDefault(pg => pg.GroupId == plantGroup.GroupId && pg.PlantId == plantGroup.PlantId); if (ModelState.IsValid && found == null) { db.Entry(plantGroup).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", "Groups")); } ViewBag.GroupId = new SelectList(db.Groups, "GroupId", "Description", plantGroup.GroupId); ViewBag.PlantId = new SelectList(db.PlantNames, "PlantId", "Sku", plantGroup.PlantId); return(View(plantGroup)); }
public ActionResult Remove(int?id, int?gid) { if (id == null | gid == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PlantGroup plantGroup = db.PlantGroups.SingleOrDefault(p => p.GroupId == gid && p.PlantId == id); if (plantGroup == null) { return(RedirectToAction("Index")); } return(View(plantGroup)); }
// GET: PlantGroups/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PlantGroup plantGroup = db.PlantGroups.Find(id); if (plantGroup == null) { return(HttpNotFound()); } ViewBag.GroupId = new SelectList(db.Groups, "GroupId", "Description", plantGroup.GroupId); ViewBag.PlantId = new SelectList(db.PlantNames, "PlantId", "Sku", plantGroup.PlantId); return(View(plantGroup)); }
public void DeletePlantGroup(string gardenName, string plantGroupName, string accountID) { if (string.IsNullOrEmpty(gardenName)) { throw new ArgumentException("message", nameof(gardenName)); } if (plantGroupName == null) { throw new ArgumentNullException(nameof(plantGroupName)); } Garden garden = GardenRepository.GetByName(gardenName, accountID); PlantGroup plantGroup = PlantGroupRepository.GetByName(plantGroupName, accountID); PlantGroupRepository.DeletePlantGroup(garden, plantGroup, accountID); }
public void CreatePlantGroup(string gardenName, string plantGroupName, string accountID) { if (string.IsNullOrEmpty(gardenName)) { throw new ArgumentException("message", nameof(gardenName)); } if (plantGroupName == null) { throw new ArgumentNullException(nameof(plantGroupName)); } Garden garden = GardenRepository.GetByName(gardenName, accountID); PlantGroup plantGroup = new PlantGroup(plantGroupName); PlantGroupRepository.CreatePlantGroup(garden, plantGroup, accountID); garden.AddPlantGroup(plantGroup); GardenRepository.AddPlantGroup(garden, plantGroup, accountID); //should be update }
public void AddPlants(PlantGroup group) { plantGroup = group; }
public void AddPlantGroup(Garden garden, PlantGroup plantGroup, string userID) { }
public TheGetAllIncompatibilitiesMethod() { _plantGroup = new PlantGroup("test plant group"); }
public TheAddHardwareMethod() { _plantGroup = new PlantGroup("test plant group"); }
public TheAddPlantMethod() { _plantGroup = new PlantGroup("test plant group"); }