public ActionResult CreateForLocation(int locationId)
        {
            viewModel = new DiveSitesModel();
              IList<SelectListItem> DiveLocationsListItems = BuildLocationList(locationId);
              viewModel.DiveLocationsListItems = DiveLocationsListItems;

              return View("Create", viewModel);
        }
 public ActionResult Create()
 {
     //DiveSiteFormViewModel viewModel = DiveSiteFormViewModel.CreateDiveSiteFormViewModel();
       viewModel = new DiveSitesModel();
       viewModel.DiveSite = new DiveSite();
       IList<SelectListItem> DiveLocationsListItems = BuildLocationList(null);
       viewModel.DiveLocationsListItems = DiveLocationsListItems;
       //viewModel.DiveLocationsListItems = DiveLocationsListItems.OrderBy(m => m.Text).ToList(); //this works too as opposed to the following 2 lines
       //var sortedList = from row in DiveLocationsListItems orderby row.Text select row;
       //viewModel.DiveLocationsListItems = sortedList.ToList();
       return View(viewModel);
 }
        public ActionResult Create(DiveSitesModel diveSitesModel)
        {
            user = userServices.FindUser(this.User.Identity.Name);

              if (ModelState.IsValid) {
            diveSitesModel.DiveSite.User = user;
            diveSitesModel.DiveSite.DiveLocation = locationServices.Get(diveSitesModel.DiveSite.DiveLocationId);
            diveSitesModel.DiveSite.Created = DateTime.Now;
            diveSitesModel.DiveSite.LastModified = DateTime.Now;
            diveSiteServices.Save(diveSitesModel.DiveSite);

            TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = "The diveSite was successfully created.";
            return RedirectToAction("Index");
              }
              diveSitesModel.DiveLocationsListItems = BuildLocationList(null);
              return View(diveSitesModel);
        }
        public ActionResult Edit(DiveSitesModel diveSitesModel)
        {
            diveSitesModel.DiveLocationsListItems = BuildLocationList(diveSitesModel.DiveSite.Id);
              DiveSite diveSiteToUpdate = diveSiteServices.Get(diveSitesModel.DiveSite.Id);
              diveSitesModel.DiveSite.User = diveSiteToUpdate.User;
              TransferFormValuesTo(diveSiteToUpdate, diveSitesModel.DiveSite);
              diveSiteToUpdate.DiveLocation = locationServices.Get(diveSitesModel.DiveSite.DiveLocationId);

              if (ModelState.IsValid) {
            diveSiteServices.Save(diveSiteToUpdate);
            TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] =
               "The diveSite was successfully updated.";
            return RedirectToAction("Index");
              }
              else {
            return View(diveSitesModel);
              }
        }
        public ActionResult Edit(int id)
        {
            //DiveSiteFormViewModel viewModel = DiveSiteFormViewModel.CreateDiveSiteFormViewModel();
              viewModel = new DiveSitesModel();
              IList<DiveLocation> DiveLocations = GetDiveLocations();
              SelectListItem locationItem;
              IList<SelectListItem> DiveLocationsList = new List<SelectListItem>();

              viewModel.DiveSite = diveSiteServices.Get(id);
              foreach (var location in DiveLocations) {
            locationItem = new SelectListItem();
            locationItem.Text = location.Title;
            locationItem.Value = location.Id.ToString();
            if (viewModel.DiveSite.DiveLocation != null) {
              if (location.Id == viewModel.DiveSite.DiveLocation.Id) {
            locationItem.Selected = true;
              }
            }
            DiveLocationsList.Add(locationItem);
              }
              viewModel.DiveLocationsListItems = DiveLocationsList;
              return View(viewModel);
        }