예제 #1
0
        public async Task <IActionResult> Create([Bind("Id,Name,Info")] Type @type)
        {
            if (ModelState.IsValid)
            {
                _context.Add(@type);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(@type));
        }
        public async Task <IActionResult> Create(int typeId, [Bind("Id,TeacherId,Price,TypeId,Name,Info")] Course course)
        {
            if (ModelState.IsValid)
            {
                _context.Add(course);
                await _context.SaveChangesAsync();

                // return RedirectToAction(nameof(Index));
                return(RedirectToAction("Index", "Courses", new
                {
                    id = typeId,
                    name = _context.Types.FirstOrDefault(t => t.Id == typeId)?.Name,
                    info = _context.Types.FirstOrDefault(t => t.Id == typeId)?.Info
                }));
            }
            // ViewData["TeacherId"] = new SelectList(_context.Teachers, "Id", "Name", course.TeacherId);
            // ViewData["TypeId"] = new SelectList(_context.Types, "Id", "Name", course.TypeId);
            // return View(course);

            return(RedirectToAction("Index", "Courses", new
            {
                id = typeId,
                name = _context.Types.FirstOrDefault(t => t.Id == typeId)?.Name,
                info = _context.Types.FirstOrDefault(t => t.Id == typeId)?.Info
            }));
        }
예제 #3
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Subject subject)
        {
            if (ModelState.IsValid)
            {
                _context.Add(subject);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(subject));
        }
예제 #4
0
        public async Task <IActionResult> Create([Bind("Id,SubjectId,Name,Info")] Teacher teacher)
        {
            if (ModelState.IsValid)
            {
                _context.Add(teacher);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["SubjectId"] = new SelectList(_context.Subjects, "Id", "Name", teacher.SubjectId);
            return(View(teacher));
        }
        public async Task <IActionResult> Create([Bind("Id,CourseId,TutorId")] Group @group)
        {
            if (ModelState.IsValid)
            {
                _context.Add(@group);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CourseId"] = new SelectList(_context.Courses, "Id", "Name", @group.CourseId);
            ViewData["TutorId"]  = new SelectList(_context.Tutors, "Id", "Name", @group.TutorId);
            return(View(@group));
        }