Ejemplo n.º 1
0
 public ActionResult Create(VolunteerEditData ved)
 {
     if (ModelState.IsValid)
     {
         _repository.AddVolunteer(ved.Volunteer);
         _repository.Save();
         foreach (int i in ved.ChosenTimeSlots)
         {
             VolunteerTimeSlot vts = _repository.GetVolunteerTimeSlotById(i);
             if (vts != null)
             {
                 _repository.RegisterVolunteerForVolunteerTimeSlot(ved.Volunteer, vts);
             }
         }
         _repository.Save();
         return RedirectToAction("Index");
     }
     ved.VolunteerTimeSlots = _repository.GetAllVolunteerTimeSlots();
     return View("Create", ved);
 }
Ejemplo n.º 2
0
        public static VolunteerEditData CreateEditDataFromVolunteer(
			Volunteer volunteer, IRepository repo)
        {
            var ved = new VolunteerEditData
                        {
                            Volunteer = volunteer,
                            VolunteerTimeSlots = repo.GetAllVolunteerTimeSlots(),
                            ChosenTimeSlots =
                                new int[volunteer.VolunteersVolunteerTimeSlots.Count],
                            Foods = new SelectList(repo.GetAllFoods(), "id", "name"),
                            TShirtSizes =
                                new SelectList(repo.GetAllTShirtSizes(), "id", "name")
                        };
            for (int i = 0; i < volunteer.VolunteersVolunteerTimeSlots.Count; i++)
            {
                ved.ChosenTimeSlots[i] =
                    volunteer.VolunteersVolunteerTimeSlots.ElementAt(i).volunteer_timeslot_id;
            }
            return ved;
        }
 public ActionResult Index(VolunteerEditData ved)
 {
     if (!VolunteerRegistrationOpen())
     {
         return View("RegistrationClosed");
     }
     if (ModelState.IsValid)
     {
         _repository.AddVolunteer(ved.Volunteer);
         _repository.Save();
         foreach (int i in ved.ChosenTimeSlots)
         {
             VolunteerTimeSlot vts = _repository.GetVolunteerTimeSlotById(i);
             if (vts != null)
             {
                 _repository.RegisterVolunteerForVolunteerTimeSlot(ved.Volunteer, vts);
             }
         }
         _repository.Save();
         SettingsData settings = SettingsData.Default;
         var message = new MailMessage(settings.EmailFrom,
                                       ved.Volunteer.People.email,
                                       settings.RegistrationSubject,
                                       settings.RegistrationMessage.Replace(
                                         "{name}", ved.Volunteer.People.name).Replace(
                                             "{role}", "Volunteer"));
         try
         {
             Mailer.Send(message);
             TempData["Message"] = "Confirmation email successfully sent";
         }
         catch
         {
             //TODO: add something to log this or send it to an admin. possibly just log it and have an interface for it plus a message on /Home/Admin
             TempData["Message"] =
                 "An error occurred sending the email confirmation, but registration was successful";
         }
         return RedirectToAction("Success");
     }
     return View("Index", VolunteerController.CreateEditDataFromVolunteer(ved.Volunteer, _repository));
 }
Ejemplo n.º 4
0
 public ActionResult Edit(int id, FormCollection collection)
 {
     var ved = new VolunteerEditData();
     Volunteer vol = _repository.GetVolunteerById(id);
     if (vol == null)
     {
         return View("VolunteerNotFound");
     }
     ved.Volunteer = vol;
     // This will try to update all the fields in the model based on the form collection
     if (TryUpdateModel(ved, collection))
     {
         IQueryable<VolunteerTimeSlot> oldTimeSlots =
             vol.VolunteersVolunteerTimeSlots.Select(x => x.VolunteerTimeSlot).
                 AsQueryable();
         foreach (VolunteerTimeSlot vts in oldTimeSlots)
         {
             _repository.UnRegisterVolunteerForVolunteerTimeSlot(vol, vts);
         }
         _repository.Save();
         foreach (int i in ved.ChosenTimeSlots)
         {
             VolunteerTimeSlot vts = _repository.GetVolunteerTimeSlotById(i);
             if (vts != null)
             {
                 _repository.RegisterVolunteerForVolunteerTimeSlot(ved.Volunteer, vts);
             }
         }
         _repository.Save();
         return RedirectToAction("Index");
     }
     return View("Edit", CreateEditDataFromVolunteer(vol, _repository));
 }