예제 #1
0
        public async Task <IActionResult> Create([Bind("Id,CourseName,TotalCredits")] Course course)
        {
            if (ModelState.IsValid)
            {
                _context.Add(course);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(course));
        }
        public async Task <IActionResult> Create([Bind("Id,StudentId,CourseId,StartDate,EndDate")] Enrolment enrolment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(enrolment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CourseId"]  = new SelectList(_context.Course, "Id", "Id", enrolment.CourseId);
            ViewData["StudentId"] = new SelectList(_context.Set <Student>(), "Id", "Id", enrolment.StudentId);
            return(View(enrolment));
        }
예제 #3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Email,Phone,Password")] Student student)
        {
            if (id != student.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var user = await _userManager.FindByEmailAsync(student.Email);

                    if (student.Password != null)
                    {
                        user.PasswordHash = _userManager.PasswordHasher.HashPassword(user, student.Password);
                    }

                    await _userManager.UpdateAsync(user);

                    _context.Update(student);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StudentExists(student.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(student));
        }