public bool CreatePlant(PlantCreate model) { var entity = new Plant() { OwnerID = _userId, PlantName = model.PlantName, //PlantZone = model.PlantZone, //Season = model.Season, SowStartDate = model.SowStartDate, SowEndDate = model.SowEndDate, ReapStartDate = model.ReapStartDate, ReapEndDate = model.ReapEndDate, SpaceNeeds = model.SpaceNeeds, //WaterNeeds = model.WaterNeeds, //SoilNeeds = model.SoilNeeds, //SolarNeeds = model.SolarNeeds, //PlantHealth = model.PlantHealth, //Comments = model.Comments }; using (var ctx = new ApplicationDbContext()) { ctx.Plants.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(PlantCreate model) { if (!ModelState.IsValid) { return(View(model)); } var userId = Guid.Parse(User.Identity.GetUserId()); var service = new PlantService(userId); service.CreatePlant(model); return(RedirectToAction("Index")); }
public bool CreatePlants(PlantCreate model) { var entity = new Plant.Data.PlantItem() { OwnerId = _userId, Quantity = model.Quantity, TypeOfPlant = model.TypeOfPlant, PlantName = model.PlantName, Price = model.TotalPrice, }; using (var ctx = new ApplicationDbContext()) { ctx.Plants.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(PlantCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreatePlantService(); if (service.CreatePlant(model)) { TempData["SaveResult"] = "Your plant is growing!"; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Item could not be created."); return(View(model)); }
public bool CreatePlant(PlantCreate model) { var entity = new Plant() { OwnerID = _userId, TypeOfPlant = model.TypeOfPlant, SoilMix = model.SoilMix, WateringFrequency = model.WateringFrequency, TimeFertilized = model.TimeFertilized, TimeWatered = model.TimeWatered, NextWatering = CalculateNextWatering(model.WateringFrequency, model.TimeWatered), }; using (var ctx = new ApplicationDbContext()) { ctx.Plants.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(PlantCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreatePlantService(); if (service.CreatePlants(model)) { TempData["SaveResult"] = "The plant was created."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Plant could not be created."); return(View(model)); }