예제 #1
0
        public async Task <IActionResult> Create([Bind("ID,Date,Classroom,Type,SubjectID,NumberLesson,Missings,GroupID")] Lesson lesson)
        {
            if (ModelState.IsValid)
            {
                lesson.GroupID = _context.Users
                                 .First(m => m.UserName == User.Identity.Name)
                                 .GroupID;
                _context.Add(lesson);

                var students = _context.Student.OrderBy(m => m.LastName).ToList();

                List <Missing> missings = new List <Missing>(students.Count);
                for (int i = 0; i < students.Count; i++)
                {
                    missings.Add(new Missing());
                    missings[i].LessonID  = lesson.ID;
                    missings[i].StudentID = students[i].ID;
                    missings[i].IsMissing = 0;
                    _context.Add(missings[i]);
                }

                await _context.SaveChangesAsync();

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

            ViewData["SubjectID"] = new SelectList(_context.Subject, "ID", "ID", lesson.SubjectID);
            return(View(lesson));
        }
예제 #2
0
        public async Task <IActionResult> Create([Bind("ID,Name,LastName, Father")] Student student)
        {
            if (ModelState.IsValid)
            {
                student.GroupID = _context.Users.First(m => m.UserName == User.Identity.Name).GroupID;
                _context.Add(student);

                var someStudent = await _context.Student.FirstOrDefaultAsync(m => m.GroupID == student.GroupID);

                if (someStudent != null)
                {
                    var missings = _context.Missing.Where(m => m.StudentID == someStudent.ID).ToList();

                    for (int i = 0; i < missings.Count; i++)
                    {
                        _context.Add(new Missing
                        {
                            StudentID = student.ID,
                            LessonID  = missings[i].LessonID,
                            IsMissing = IsMissing.withoutReason
                        });
                    }
                }

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(student));
        }
예제 #3
0
        public async Task <IActionResult> Create([Bind("ID,Name")] Group group)
        {
            if (ModelState.IsValid)
            {
                _context.Add(group);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(group));
        }
예제 #4
0
        public async Task <IActionResult> Create([Bind("ID,SubjectName,Teacher")] Subject subject)
        {
            if (ModelState.IsValid)
            {
                subject.GroupID = _context.Users.First(m => m.UserName == User.Identity.Name).GroupID;
                _context.Add(subject);
                await _context.SaveChangesAsync();

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