예제 #1
0
        public async Task <IActionResult> OnGetAsync(string BibleId, int PathId, int BookNumber, int Chapter, int?VerseNum, int Position)
        {
            //Note that StepId isn't used here, but is here to support consistency with the Edit signature.

            //Does the path exist? if not we've got an error.
            Path = await _context.Paths.FindAsync(PathId);

            if (Path == null)
            {
                return(RedirectToPage("/error", new { errorMessage = "That's Odd! We weren't able to find this Path" }));
            }
            // confirm our owner is a valid path editor i.e. owner or the path is publicly editable
            IdentityUser user = await _userManager.GetUserAsync(User);

            if (!Path.IsValidPathEditor(user.Email))
            {
                return(RedirectToPage("/error", new { errorMessage = "Sorry! You do not have sufficient rights to add to this Path" }));
            }

            BibleId = await Path.GetValidBibleIdAsync(_context, BibleId);

            Step            = new PathNode();
            Step.PathId     = Path.Id;
            Step.BookNumber = BookNumber;
            Step.Chapter    = Chapter;
            Step.StartVerse = VerseNum ?? 1; // set to 1 if VersNum is Null.
            Step.EndVerse   = VerseNum ?? 1; // set to 1 if VersNum is Null.
            Step.Position   = Position;

            // Populate Step for display
            _ = await Step.AddBookNameAsync(_context, BibleId);

            Step.Verses = await Step.GetBibleVersesAsync(_context, BibleId, false, false);

            // and now we need a Verse Select List
            ViewData["VerseSelectList"] = new SelectList(Step.Verses, "Verse", "Verse");
            ViewData["TargetPage"]      = "AddStep";
            return(Page());
        }