//TODO: Add logs to database and use this helper to log all user activities // so they can see all the tasks they've done later on. //public static void LoggerInit(Garden garden) //{ // GardenLog newLog = new GardenLog(); // newLog.Message = $"Created {garden.Name}"; // newLog.Date = DateTime.Now; // newLog.UserID = 1; //admin user // newLog.GardenID = garden.GardenID; // garden.GardenLogs.Add(newLog); //} protected static void VegetablesInit(Garden garden, CreateGardenVM gardenvm) { //TODO:Refactor this to do it automatically depending on garden type and size List <int> vegIds = new List <int>(); if (garden.SqFeet == 4) { vegIds.Add(gardenvm.VegetableTypeID1); vegIds.Add(gardenvm.VegetableTypeID2); vegIds.Add(gardenvm.VegetableTypeID3); vegIds.Add(gardenvm.VegetableTypeID4); } if (garden.SqFeet == 6) { vegIds.Add(gardenvm.VegetableTypeID1); vegIds.Add(gardenvm.VegetableTypeID2); vegIds.Add(gardenvm.VegetableTypeID3); vegIds.Add(gardenvm.VegetableTypeID4); vegIds.Add(gardenvm.VegetableTypeID5); vegIds.Add(gardenvm.VegetableTypeID6); } for (int j = 0; j < vegIds.Count; j++) { //Create the vegetables and add to the garden var newVeg = new Vegetable(); newVeg.VegetableTypeID = vegIds[j]; newVeg.GardenID = gardenvm.GardenID; garden.Vegetables.Add(newVeg); } }
// GET: Gardens/Create public ActionResult Create() { //TODO: Refactor create garden experience with Angular and delete this nonsense CreateGardenVM createGardenVM = new CreateGardenVM(); ViewBag.CityID = new SelectList(db.Cities, "CityID", "Name"); ViewBag.VegetableTypeID1 = new SelectList(db.VegetableTypes, "VegetableTypeID", "Name"); ViewBag.VegetableTypeID2 = new SelectList(db.VegetableTypes, "VegetableTypeID", "Name"); ViewBag.VegetableTypeID3 = new SelectList(db.VegetableTypes, "VegetableTypeID", "Name"); ViewBag.VegetableTypeID4 = new SelectList(db.VegetableTypes, "VegetableTypeID", "Name"); ViewBag.VegetableTypeID5 = new SelectList(db.VegetableTypes, "VegetableTypeID", "Name"); ViewBag.VegetableTypeID6 = new SelectList(db.VegetableTypes, "VegetableTypeID", "Name"); //get select list for garden size choices List <SelectListItem> items = new List <SelectListItem>(); items.Add(new SelectListItem { Text = "4", Value = "4", Selected = true }); items.Add(new SelectListItem { Text = "6", Value = "6" }); ViewBag.Sqft = items; return(View(createGardenVM)); }
protected static void MergeGardenModels(Garden garden, CreateGardenVM gardenvm) { garden.GardenID = gardenvm.GardenID; garden.Name = gardenvm.Name; garden.SqFeet = Int32.Parse(gardenvm.Sqft); //VM Sqft is string because it receives from selectlist viewbag garden.CreatedDate = DateTime.Now; garden.CityID = gardenvm.CityID; }
/// <summary> /// Converts the viewmodel to a garden with vegetables and prompts that can /// be saved to the database /// </summary> /// <param name="garden"></param> /// <param name="gardenvm"></param> public static void GardenInit(Garden garden, CreateGardenVM gardenvm) { MergeGardenModels(garden, gardenvm); //LoggerInit(garden); see below VegetablesInit(garden, gardenvm); //TODO: MAJOR - GardenSageSort() put vegetables in the ideal spot for the garden type and location and sun DailyCheck(garden); }
public ActionResult Create([Bind(Include = "GardenID,Name,Sqft,CityID,VegetableTypeID1,VegetableTypeID2,VegetableTypeID3,VegetableTypeID4,VegetableTypeID5,VegetableTypeID6")] CreateGardenVM createGardenVM) { if (ModelState.IsValid) { Garden newGarden = new Garden(); //converts the viewmodel to a new garden with vegetables and prompts GardenHelpers.GardenInit(newGarden, createGardenVM); db.Gardens.Add(newGarden); db.SaveChanges(); //show the details of created garden return(RedirectToAction("Details", "Gardens", new { id = newGarden.GardenID })); } return(View()); }