public ActionResult Edit(int id = 0) { Volunteer volunteer = db.Volunteers.Find(id); if (volunteer == null) { return HttpNotFound(); } VolunteerCreateModel model = new VolunteerCreateModel(); model.volunteer = ConvertToVolunteerProfileModel(volunteer); IEnumerable<VolunteerLocationModel> address = GetVolunteerAddress(id); if (address != null && address.Count() > 0) { model.location = address.ElementAt(0); } else { model.location = new VolunteerLocationModel(); } IEnumerable<VolunteerContactModel> contacts = GetVolunteerContacts(id); if (contacts != null && contacts.Count() > 0) { model.contact = contacts.ElementAt(0); } else { model.contact = new VolunteerContactModel(); } return View(model); }
public ActionResult Edit(VolunteerCreateModel model) { if (ModelState.IsValid) { model.contact.volunteerId = model.volunteer.volunteerId; model.location.volunteerId = model.volunteer.volunteerId; UpdateVolunteerProfile(model.volunteer); if (model.location.locationId < 1) { CreateLocation(model.location); } else { UpdateLocation(model.location); } if (model.contact.contactId < 1) { CreateContact(model.contact); } else { UpdateContact(model.contact); } return RedirectToAction("Details/" + model.volunteer.volunteerId); } return RedirectToAction("Index"); }
public ActionResult Create(VolunteerCreateModel model) { //create a new volunteer Volunteer volunteer = CreateNewVolunteer(model.volunteer); // create a new location for volunteer model.location.volunteerId = volunteer.volunteerId; CreateLocationForNewVolunteer(model.location); // create a emergency contact for volunteer model.contact.volunteerId = volunteer.volunteerId; CreateContactForNewVolunteer(model.contact); return RedirectToAction("Index"); }