public ActionResult Create(Production production)
        {
            if (ModelState.IsValid)
            {
                db.Productions.Add(production);

                ApplyProductionVolunteerAllocations(production);

                db.SaveChanges();
                return RedirectToAction("Index");
            }

            _initialisesVolunteerAllocationView.Initialise(ViewBag, db);

            return View(production);
        }
Exemplo n.º 2
0
 public static Production FindOrMake(this DbSet<Production> productions, string productionTitle, DbContext ctx)
 {
     if (String.IsNullOrWhiteSpace(productionTitle)) return (null);
     var production = productions.FirstOrDefault(p => p.Title == productionTitle);
     if (production == null) {
         production = new Production() { Title = productionTitle };
         productions.Add(production);
         ctx.SaveChanges();
     }
     return (production);
 }
        private void ApplyProductionVolunteerAllocations(Production production)
        {
            var volunteerAllocations = _interpretsPostedVolunteerAllocations.Interpret(Request.Form);

            production.ProductionVolunteers.Clear();
            foreach (var volunteerAllocation in volunteerAllocations)
            {
                production.ProductionVolunteers.Add(new ProductionVolunteer
                {
                    VolunteerId = volunteerAllocation.VolunteerId,
                    JobId = volunteerAllocation.JobId,
                    Notes = volunteerAllocation.Notes
                });
            }
        }
        public ActionResult Edit(Production production)
        {
            if (ModelState.IsValid)
            {
                db.Entry(production).State = EntityState.Modified;
                ApplyProductionVolunteerAllocations(production);

                db.SaveChanges();
                return RedirectToAction("Index");
            }

            _initialisesVolunteerAllocationView.Initialise(ViewBag, db, production.ProductionVolunteers
                .Select(pv => new VolunteerAllocation(pv.VolunteerId, pv.JobId, pv.Notes)));

            return View(production);
        }