public async Task <IActionResult> Create(StudentForm Vmodel)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = UploadedFile(Vmodel);

                Student student = new Student
                {
                    ProfilePicture  = uniqueFileName,
                    StudentId       = Vmodel.Index,
                    FirstName       = Vmodel.FirstName,
                    LastName        = Vmodel.LastName,
                    EnrollmentDate  = Vmodel.EnrollmentDate,
                    AcquiredCredits = Vmodel.AcquiredCredits,
                    CurrentSemestar = Vmodel.CurrentSemestar,
                    EducationLevel  = Vmodel.EducationLevel,
                    Enrollments     = Vmodel.Courses,
                };

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

                return(RedirectToAction(nameof(Index)));
            }
            return(View());
        }
Exemple #2
0
        public async Task <IActionResult> Create(TeacherForm Vmodel)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = UploadedFile(Vmodel);

                Teacher teacher = new Teacher
                {
                    ProfilePicture = uniqueFileName,
                    FirstName      = Vmodel.FirstName,
                    LastName       = Vmodel.LastName,
                    Degree         = Vmodel.Degree,
                    AcademicRank   = Vmodel.AcademicRank,
                    OfficeNumber   = Vmodel.OfficeNumber,
                    HireDate       = Vmodel.HireDate,

                    Course1 = Vmodel.Courses_first,
                    Course2 = Vmodel.Courses_second
                };

                _context.Add(teacher);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View());
        }
Exemple #3
0
        public async Task <IActionResult> EnrollStudents(EnrollStudentsViewModel entry)
        {
            Course course = await _context.Courses.FirstOrDefaultAsync(c => c.Id == entry.CourseId);

            if (course == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                foreach (int sId in entry.StudentIds)
                {
                    Enrollment enrollment = await _context.Enrollments
                                            .FirstOrDefaultAsync(c => c.CourseId == entry.CourseId && c.StudentId == sId &&
                                                                 c.Year == entry.Year && c.Semester == entry.Semester);

                    if (enrollment == null)
                    {
                        enrollment = new Enrollment
                        {
                            CourseId  = entry.CourseId,
                            StudentId = sId,
                            Year      = entry.Year,
                            Semester  = entry.Semester
                        };
                        _context.Add(enrollment);
                    }
                }
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index), new { sTitle = course.Title, sSem = entry.Semester, sYear = entry.Year }));
            }
            return(RedirectToAction(nameof(Index)));
        }
Exemple #4
0
        public async Task <IActionResult> Create([Bind("Id,StudentId,FirstName,LastName,EnrollmentDate,AcquiredCredits,CurrentSemester,EducationLevel")] Student student)
        {
            if (ModelState.IsValid)
            {
                _context.Add(student);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(student));
        }
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Degree,AcademicRank,OfficeNumber,HireDate")] Teacher teacher)
        {
            if (ModelState.IsValid)
            {
                _context.Add(teacher);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(teacher));
        }
        public async Task <IActionResult> Create([Bind("Id,title,desc")] Labvezba labvezba)
        {
            if (ModelState.IsValid)
            {
                _context.Add(labvezba);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(labvezba));
        }
        public async Task <IActionResult> Create([Bind("CourseID,Title,Credits,Semestar,Programme,EducationLevel,FirstTeacherId,SecondTeacherId")] Course course)
        {
            if (ModelState.IsValid)
            {
                _context.Add(course);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["FirstTeacherID"]  = new SelectList(_context.Set <Teacher>(), "Id", "FullName", course.FirstTeacherId);
            ViewData["SecondTeacherID"] = new SelectList(_context.Set <Teacher>(), "Id", "FullName", course.SecondTeacherId);
            return(View(course));
        }
        public async Task <IActionResult> EditEnrollment(int id, int tId, TeacherEnrollmentViewModel input)
        {
            Enrollment entry = input.Enrollment;

            if (entry.Id != id)
            {
                return(NotFound());
            }

            var enrollment = await _context.Enrollments
                             .Include(e => e.Course)
                             .Include(e => e.Student)
                             .FirstOrDefaultAsync(m => m.Id == id &&
                                                  (m.Course.FirstTeacherId == tId || m.Course.SecondTeacherId == tId));

            if (enrollment == null)
            {
                return(NotFound());
            }

            AppUser user = await userManager.GetUserAsync(User);

            if (tId != user.TeacherId)
            {
                return(RedirectToAction("AccessDenied", "Account", null));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    enrollment.ExamPoints       = entry.ExamPoints;
                    enrollment.SeminalPoints    = entry.SeminalPoints;
                    enrollment.ProjectPoints    = entry.ProjectPoints;
                    enrollment.AdditionalPoints = entry.AdditionalPoints;
                    enrollment.Grade            = entry.Grade;
                    enrollment.FinishDate       = entry.FinishDate;
                    _context.Update(enrollment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EnrollmentExists(id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            return(RedirectToAction(nameof(EditEnrollment), new { id, tId }));
        }
        public async Task <IActionResult> Enroll(int?studentId, int?labId)
        {
            if ((studentId == null) || (labId == null))
            {
                return(NotFound());
            }

            Student toInsert = await _context.students.AsQueryable().Where(s => s.Id == studentId).FirstOrDefaultAsync();

            Labvezba toPut = await _context.vezbi.AsQueryable().Where(s => s.Id == labId).FirstOrDefaultAsync();

            Studentlab nov_lab = new Studentlab {
                studentId = (int)studentId, student = toInsert, labvezbaId = (int)labId, vezba = toPut
            };

            _context.Add(nov_lab);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> EditEnrollment(int id, EnrollmentUploadViewModel entry)
        {
            if (entry.Enrollment.Id != id)
            {
                return(NotFound());
            }

            var enrollment = await _context.Enrollments
                             .Include(e => e.Course)
                             .Include(e => e.Student)
                             .FirstOrDefaultAsync(m => m.Id == id);

            if (enrollment == null)
            {
                return(NotFound());
            }

            AppUser user = await userManager.GetUserAsync(User);

            if (enrollment.StudentId != user.StudentId)
            {
                return(RedirectToAction("AccessDenied", "Account", null));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    enrollment.ProjectUrl = entry.Enrollment.ProjectUrl;
                    enrollment.SeminalUrl = UploadedFile(entry);
                    _context.Update(enrollment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EnrollmentExists(id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            return(RedirectToAction(nameof(EditEnrollment)));
        }
Exemple #11
0
        public async Task <IActionResult> EditByProfessorPost(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            int    crsId = 1;
            string crs   = null;

            if (TempData["selectedCourse"] != null)
            {
                crs   = TempData["selectedCourse"].ToString();
                crsId = Int32.Parse(crs);
            }

            var enrollmentToUpdate = await _context.Enrollments.FirstOrDefaultAsync(s => s.EnrollmentID == id);

            await TryUpdateModelAsync <Enrollment>(
                enrollmentToUpdate,
                "", s => s.ExamPoints, s => s.SeminalPoints, s => s.ProjectPoints, s => s.AdditionalPoints,
                s => s.Grade, s => s.FinishDate);

            try
            {
                await _context.SaveChangesAsync();

                return(RedirectToAction("getStudentsByCourse", "Enrollments", new { id = crsId }));
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex vari  able name and write a log.)
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists, " +
                                         "see your system administrator.");
            }
            return(View(enrollmentToUpdate));
        }