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)); }
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)); }
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); } }
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)); }
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); } }