Ejemplo n.º 1
0
        public ActionResult Edit(int id)
        {
            var service = CreatePlantService();
            var detail  = service.GetPlantById(id);
            var model   =
                new PlantEdit
            {
                Quantity    = detail.Quantity,
                TypeOfPlant = detail.TypeOfPlant,
                PlantName   = detail.PlantName,
                PlantId     = detail.PlantId,
                Price       = detail.Price,
            };

            return(View(model));
        }
Ejemplo n.º 2
0
        public ActionResult Edit(int id)
        {
            var service = CreatePlantService();
            var detail  = service.GetPlantById(id);
            var model   =
                new PlantEdit
            {
                PlantID           = detail.PlantID,
                TypeOfPlant       = detail.TypeOfPlant,
                SoilMix           = detail.SoilMix,
                TimeFertilized    = detail.TimeFertilized,
                TimeWatered       = detail.TimeWatered,
                WateringFrequency = detail.WateringFrequency,
            };

            return(View(model));
        }
Ejemplo n.º 3
0
        public bool UpdatePlant(PlantEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Plants
                    .Single(e => e.PlantId == model.PlantId && e.OwnerId == _userId);

                entity.Quantity    = model.Quantity;
                entity.TypeOfPlant = model.TypeOfPlant;
                entity.PlantName   = model.PlantName;
                entity.PlantId     = model.PlantId;
                entity.Price       = model.Price;

                return(ctx.SaveChanges() == 1);
            }
        }
Ejemplo n.º 4
0
        public bool UpdatePlant(PlantEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Plants
                    .Single(e => e.OwnerID == _userId && e.PlantID == model.PlantID);
                entity.PlantID           = model.PlantID;
                entity.TypeOfPlant       = model.TypeOfPlant;
                entity.SoilMix           = model.SoilMix;
                entity.WateringFrequency = model.WateringFrequency;
                entity.TimeWatered       = model.TimeWatered;
                entity.TimeFertilized    = model.TimeFertilized;
                entity.NextWatering      = CalculateNextWatering(model.WateringFrequency, model.TimeWatered);

                return(ctx.SaveChanges() == 1);
            }
        }
Ejemplo n.º 5
0
        public ActionResult Edit(int id, PlantEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            if (model.PlantID != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }

            var service = CreatePlantService();

            if (service.UpdatePlant(model))
            {
                TempData["SaveResult"] = "Your Item was updated.";
                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("", "Your Item could not be updated.");
            return(View());
        }