Ejemplo n.º 1
0
        public ActionResult Create(MedicationCreate model)
        {
            //ViewData["Pets"] = _db.Pets.Select(p => new SelectListItem
            //{
            //    Text = p.Name,
            //    Value = p.PetId.ToString()
            //});

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateMedicationService();

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

            ModelState.AddModelError("", "Medication could not be added.");

            return(View(model));
        }
Ejemplo n.º 2
0
        public ActionResult Create()
        {
            var viewModel = new MedicationCreate();

            //viewModel.Pets = _db.Pets.Select(p => new SelectListItem
            //{
            //    Text = p.Name,
            //    Value = p.PetId.ToString()
            //});

            return(View(viewModel));
        }
Ejemplo n.º 3
0
        public bool CreateMedication(MedicationCreate model)
        {
            var entity =
                new Medication()
            {
                OwnerID         = _userId,
                MedicationName  = model.MedicationName,
                MedicationClass = model.MedicationClass,
                MedicationUse   = model.MedicationUse
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Medications.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Ejemplo n.º 4
0
        public ActionResult Create(MedicationCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateMedicationService();

            if (service.CreateMedication(model))
            {
                TempData["SaveResult"] = "Your medication entry was saved.";
                return(RedirectToAction("Index"));
            }
            ;

            ModelState.AddModelError("", "Medication entry could not be created.");

            return(View(model));
        }
Ejemplo n.º 5
0
        public bool CreateMedication(MedicationCreate model)
        {
            var entity =
                new Medication()
            {
                OwnerId = _userId,
                Name    = model.Name,
                //PetId = model.PetId,
                //Dosage = model.Dosage,
                TimesPerDay = model.TimesPerDay,
                BeginDate   = model.BeginDate,
                EndDate     = model.EndDate,
                RefillLink  = model.RefillLink
            };

            using (var ctx = new ApplicationDbContext())
            {
                Medication medication = ctx.Medications.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }