public ActionResult Create(CreateTherapistViewModel model) { if (ModelState.IsValid) { List<Treatment> treats = new List<Treatment>(); model.SelectedTreatmentId = model.SelectedTreatmentId ?? new int[0]; foreach (int i in model.SelectedTreatmentId) { treats.Add(service.TreatmentGateway.GetOne(i)); } Therapist therapist = new Therapist { Name = model.Name, Description = model.Description, WorkingHourses = model.WorkingHourses, Treatments = treats }; service.TherapistGateway.CreateOne(therapist); return RedirectToAction("Index"); } return View(); }
public ActionResult Edit(int id, TherapistViewModel model) { try { if (ModelState.IsValid) { List<Treatment> treats = new List<Treatment>(); model.SelectedTreatmentId = model.SelectedTreatmentId ?? new int[0]; foreach (int i in model.SelectedTreatmentId) { treats.Add(service.TreatmentGateway.GetOne(i)); } Therapist therapist = new Therapist { Id = id, Name = model.Name, Description = model.Description, Treatments = treats }; service.TherapistGateway.Update(therapist); return RedirectToAction("Index"); } return Edit(id); } catch { return Edit(id); } }