public async Task <bool> OnMultiStageFormCreate(Stagedform stagedform)
        {
            // Create a new Stage1, Stage2, and Stage3 form then update the StagedForm
            Stage1 newStage1 = new Stage1();

            newStage1.Name = "";
            _context.Stage1.Add(newStage1);

            Stage2 newStage2 = new Stage2();

            newStage2.Description = "";
            _context.Stage2.Add(newStage2);

            Stage3 newStage3 = new Stage3();

            newStage3.Date = DateTime.Now;
            _context.Stage3.Add(newStage3);

            await _context.SaveChangesAsync();

            stagedform.Stage1       = newStage1.Id;
            stagedform.Stage2       = newStage2.Id;
            stagedform.Stage3       = newStage3.Id;
            stagedform.CurrentStage = (int)MultiStageFormStages.First;
            _context.Update(stagedform);

            await _context.SaveChangesAsync();

            return(true);
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] Stage1 stage1)
        {
            if (id != stage1.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(stage1);
                    await _context.SaveChangesAsync();

                    // Update the form to the second stage
                    MultiStageFormWorkflow multiStageFormWorkflow = new MultiStageFormWorkflow(_context);
                    await multiStageFormWorkflow.MoveFormToStage(stage1, MultiStageFormStages.Second);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!Stage1Exists(stage1.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(RedirectToAction(nameof(Index)));
            }
            return(View(stage1));
        }
示例#3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Stage1,Stage2,Stage3,CurrentStage")] Stagedform stagedform)
        {
            if (id != stagedform.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(stagedform);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StagedformExists(stagedform.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Stage1"] = new SelectList(_context.Stage1, "Id", "Name", stagedform.Stage1);
            ViewData["Stage2"] = new SelectList(_context.Stage2, "Id", "Description", stagedform.Stage2);
            ViewData["Stage3"] = new SelectList(_context.Stage3, "Id", "Id", stagedform.Stage3);
            return(View(stagedform));
        }