コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: GiveCampUK/SceneAndHeard
 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);
 }
コード例 #3
0
        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
                });
            }
        }
コード例 #4
0
        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);
        }