Beispiel #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,StateId,ProgramId")] ProgramsStates programsStates)
        {
            if (id != programsStates.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(programsStates);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProgramsStatesExists(programsStates.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProgramId"] = new SelectList(_context.SpacePrograms, "Id", "Target", programsStates.ProgramId);
            ViewData["StateId"]   = new SelectList(_context.States, "Id", "StateName", programsStates.StateId);
            return(View(programsStates));
        }
 private void AddNewProgramAndStatePairToContext(SpacePrograms program, States state)
 {
     ProgramsStates newProgramAndStateRecord = new ProgramsStates();
     newProgramAndStateRecord.ProgramId = program.Id;
     newProgramAndStateRecord.StateId = state.Id;
     newProgramAndStateRecord.Program = program;
     newProgramAndStateRecord.State = state;
     _context.ProgramsStates.Add(newProgramAndStateRecord);
 }
Beispiel #3
0
        public async Task <IActionResult> Create([Bind("Id,StateId,ProgramId")] ProgramsStates programsStates)
        {
            if (ModelState.IsValid)
            {
                _context.Add(programsStates);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProgramId"] = new SelectList(_context.SpacePrograms, "Id", "Target", programsStates.ProgramId);
            ViewData["StateId"]   = new SelectList(_context.States, "Id", "StateName", programsStates.StateId);
            return(View(programsStates));
        }