public ActionResult Edit(int id)
        {
            var service = CreateMedicationService();
            var detail  = service.GetMedicationById(id);
            var model   =
                new MedicationEdit
            {
                MedicationId    = detail.MedicationId,
                MedicationName  = detail.MedicationName,
                MedicationClass = detail.MedicationClass,
                MedicationUse   = detail.MedicationUse
            };

            return(View(model));
        }
Beispiel #2
0
        public bool UpdateMedication(MedicationEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Medications
                    .Single(e => e.MedicationID == model.MedicationId && e.OwnerID == _userId);

                entity.MedicationName  = model.MedicationName;
                entity.MedicationClass = model.MedicationClass;
                entity.MedicationUse   = model.MedicationUse;

                return(ctx.SaveChanges() == 1);
            }
        }
Beispiel #3
0
        public bool UpdateMedication(MedicationEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Medications
                    .Single(e => e.MedId == model.MedId && e.OwnerId == _userId);

                entity.Name = model.Name;
                //entity.PetId = model.PetId;
                //entity.Dosage = model.Dosage;
                entity.TimesPerDay = model.TimesPerDay;
                entity.BeginDate   = model.BeginDate;
                entity.EndDate     = model.EndDate;
                entity.RefillLink  = model.RefillLink;

                return(ctx.SaveChanges() == 1);
            }
        }
Beispiel #4
0
        public ActionResult Edit(int id)
        {
            ViewData["Pets"] = _db.Pets.Select(p => new SelectListItem
            {
                Text  = p.Name,
                Value = p.PetId.ToString()
            });
            var service = CreateMedicationService();
            var detail  = service.GetMedicationById(id);
            var model   =
                new MedicationEdit
            {
                MedId = detail.MedId,
                Name  = detail.Name,
                /* PetId = detail.PetId,  */                /* Dosage = detail.Dosage,*/
                BeginDate   = detail.BeginDate,
                EndDate     = detail.EndDate,
                TimesPerDay = detail.TimesPerDay,
                RefillLink  = detail.RefillLink
            };

            return(View(model));
        }
Beispiel #5
0
        public ActionResult Edit(int id, MedicationEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.MedId != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }

            var service = CreateMedicationService();

            if (service.UpdateMedication(model))
            {
                TempData["SaveResult"] = "Your medication has been updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Your medication could not be updated.");
            return(View(model));
        }