コード例 #1
0
ファイル: Edit.cshtml.cs プロジェクト: TomThomasPaul/IS7012
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Faculty = await _context.Faculty
                      .Include(f => f.Branch)
                      .Include(f => f.Genre).FirstOrDefaultAsync(m => m.FacultyId == id);

            if (Faculty == null)
            {
                return(NotFound());
            }
            ViewData["BranchId"] = new SelectList(_context.Branch, "BranchId", "Address");
            ViewData["GenreId"]  = new SelectList(_context.Set <Genre>(), "GenreId", "GenreName");
            return(Page());
        }
コード例 #2
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            ClassSchedule = await _context.ClassSchedule
                            .Include(c => c.BuddingDancer)
                            .Include(c => c.Faculty).FirstOrDefaultAsync(m => m.ClassScheduleId == id);

            if (ClassSchedule == null)
            {
                return(NotFound());
            }
            ViewData["BuddingDancerId"] = new SelectList(_context.BuddingDancer, "BuddingDancerId", "DancerFullName");
            ViewData["FacultyId"]       = new SelectList(_context.Set <Faculty>(), "FacultyId", "FacultyFullName");
            return(Page());
        }
コード例 #3
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            int birthYear       = BuddingDancer.DancerBirthDate.Year;
            int lastAllowedYear = DateTime.Now.Year - 5;

            if (birthYear > lastAllowedYear)
            {
                ModelState.AddModelError(key: "BuddingDancer.DancerBirthDate", errorMessage: "Must be older than 5 years");
            }

            if (!ModelState.IsValid)
            {
                ViewData["BranchId"] = new SelectList(_context.Branch, "BranchId", "Address");
                ViewData["GenreId"]  = new SelectList(_context.Set <Genre>(), "GenreId", "GenreName");

                return(Page());
            }

            _context.Attach(BuddingDancer).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BuddingDancerExists(BuddingDancer.BuddingDancerId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
コード例 #4
0
 public IActionResult OnGet()
 {
     ViewData["BranchId"] = new SelectList(_context.Branch, "BranchId", "Address");
     ViewData["GenreId"]  = new SelectList(_context.Set <Genre>(), "GenreId", "GenreName");
     return(Page());
 }
コード例 #5
0
ファイル: Create.cshtml.cs プロジェクト: TomThomasPaul/IS7012
 public IActionResult OnGet()
 {
     ViewData["BuddingDancerId"] = new SelectList(_context.BuddingDancer, "BuddingDancerId", "DancerFullName");
     ViewData["FacultyId"]       = new SelectList(_context.Set <Faculty>(), "FacultyId", "FacultyFullName");
     return(Page());
 }