// GET: Treatment/Edit/5 public ActionResult Edit(int id) { Treatment treat = service.TreatmentGateway.GetOne(id,"TreatmentType,Therapists"); if (treat == null) { return HttpNotFound(); } TreatmentEditViewModel model = new TreatmentEditViewModel(); model.Id = treat.Id; model.Duration = treat.Duration; model.Description = treat.Description; model.Name = treat.Name; model.Price = treat.Price; model.Therap = GetTherapists(treat.Therapists); model.Types = GetTypes(treat.TreatmentType); model.SelectedTypeId = treat.TreatmentType.Id; return View(model); }
public ActionResult Edit(int id, TreatmentEditViewModel model) { try { if (ModelState.IsValid) { List<Therapist> allThera = new List<Therapist>(); foreach (int therapistId in model.SelectedTherapistId) { Therapist thera = service.TherapistGateway.GetOne(therapistId); allThera.Add(thera); } Treatment treatment = new Treatment { Id = id, Name = model.Name, Description = model.Description, Price = model.Price, Duration = model.Duration, TreatmentTypeId = model.SelectedTypeId, Therapists = allThera }; service.TreatmentGateway.Update(treatment); return RedirectToAction("Index"); } return View(model); } catch { return View(model); } }