예제 #1
0
        public async Task <IActionResult> Edit(studentViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            var user = await GetCurrentUserAsync();

            var student = await _context.Student
                          .FirstOrDefaultAsync(s => s.StudentId == viewModel.StudentId);

            if (student != null)
            {
                student.StudentName           = viewModel.StudentName;
                student.NICNo                 = viewModel.NICNo;
                student.DateofBirth           = viewModel.DateofBirth;
                student.School                = viewModel.School;
                student.Grade                 = viewModel.Grade;
                student.ContactNumber         = viewModel.ContactNumber;
                student.Email                 = viewModel.Email;
                student.Address               = viewModel.Address;
                student.GuardianName          = viewModel.GuardianName;
                student.GuardianContactNumber = viewModel.GuardianContactNumber;
                student.GuardianAddress       = viewModel.GuardianAddress;

                _context.Student.Update(student);
                await _context.SaveChangesAsync();
            }

            return(RedirectToAction(nameof(Index)));
        }
예제 #2
0
        public async Task <IActionResult> Create(studentViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            var user = await GetCurrentUserAsync();

            var student = new Student
            {
                StudentId             = viewModel.StudentId,
                StudentName           = viewModel.StudentName,
                NICNo                 = viewModel.NICNo,
                DateofBirth           = viewModel.DateofBirth,
                School                = viewModel.School,
                Grade                 = viewModel.Grade,
                ContactNumber         = viewModel.ContactNumber,
                Email                 = viewModel.Email,
                Address               = viewModel.Address,
                GuardianName          = viewModel.GuardianName,
                GuardianContactNumber = viewModel.GuardianContactNumber,
                GuardianAddress       = viewModel.GuardianAddress
            };

            _context.Student.Add(student);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }