public ActionResult Create(Volunteer volunteer)
        {
            if (ModelState.IsValid)
            {
                context.Volunteers.Add(volunteer);
                context.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(volunteer);
        }
Example #2
0
 static void AddJob(SceneCRM context, Volunteer volunteer, bool condition, string jobTitle)
 {
     if (!condition) return;
     var job = context.Jobs.FindOrMake(jobTitle, context);
     if (!volunteer.Jobs.Contains(job)) {
         Console.WriteLine("Marking {0} as a {1}", volunteer.Name, job.Description);
         volunteer.Jobs.Add(job);
     }
     context.SaveChanges();
 }
 public ActionResult Edit(Volunteer volunteer)
 {
     if (ModelState.IsValid)
     {
         context.Entry(volunteer).State = EntityState.Modified;
         context.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(volunteer);
 }
Example #4
0
 public static Volunteer FindOrMake(this DbSet<Volunteer> volunteers, string forename, string surname, DbContext ctx)
 {
     var volunteer = volunteers.FirstOrDefault(v => v.FirstName == forename && v.Surname == surname);
     if (volunteer == default(Volunteer)) {
         volunteer = new Volunteer() {
             FirstName = forename,
             Surname = surname,
         };
         volunteers.Add(volunteer);
         ctx.SaveChanges();
     }
     return (volunteer);
 }