public async Task <IActionResult> Create([Bind("Id,Name")] StudentsViewModel studentsViewModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(studentsViewModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(studentsViewModel));
        }
Пример #2
0
        public async Task <IActionResult> Create([Bind("Id,Name,BirthDate")] TeacherViewModel teacherViewModel)
        {
            if (ModelState.IsValid)
            {
                teacherViewModel.Age = DateTime.Now.Year - teacherViewModel.BirthDate.Year;
                _context.Add(teacherViewModel);
                await _context.SaveChangesAsync();

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