// GET: Student/EditEnrollment/11
        public async Task <IActionResult> EditEnrollment(int?id)
        {
            if (id == null)
            {
                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));
            }

            var memory = new MemoryStream();

            var enrollmentUploadViewModel = new EnrollmentUploadViewModel
            {
                Enrollment  = enrollment,
                SeminalFile = null
            };

            return(View(enrollmentUploadViewModel));
        }
Exemplo n.º 2
0
        // StudentEdit
        public async Task <IActionResult> StudentEdit(long?Id)
        {
            if (Id == null)
            {
                return(NotFound());
            }

            var enrollment = await _context.Enrollment.FindAsync(Id);

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

            ViewData["CourseId"]  = new SelectList(_context.Course, "Id", "Title", enrollment.CourseId);
            ViewData["StudentId"] = new SelectList(_context.Student, "Id", "FullName", enrollment.StudentId);

            // for the _NonAdminLayout
            Student s = await _context.Student.FindAsync(enrollment.StudentId);

            ViewData["ProfilePicture"] = s.ProfilePicture;
            ViewData["FullName"]       = s.FullName;

            EnrollmentUploadViewModel ViewModel = new EnrollmentUploadViewModel
            {
                Enrollment  = enrollment,
                SeminalFile = null
            };

            return(View(ViewModel));
        }
        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)));
        }
Exemplo n.º 4
0
        private string UploadedFile(EnrollmentUploadViewModel model)
        {
            string uniqueFileName = null;

            if (model.SeminalFile != null)
            {
                string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "documents");
                uniqueFileName = Guid.NewGuid().ToString() + "_" + Path.GetFileName(model.SeminalFile.FileName);
                string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    model.SeminalFile.CopyTo(fileStream);
                }
            }

            return(uniqueFileName);
        }
Exemplo n.º 5
0
        public async Task <IActionResult> StudentEdit(long Id, EnrollmentUploadViewModel ViewModel)
        {
            if (Id != ViewModel.Enrollment.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    string uniqueFileName = UploadedFile(ViewModel);
                    ViewModel.Enrollment.SeminalUrl = uniqueFileName;

                    _context.Update(ViewModel.Enrollment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EnrollmentExists(Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(RedirectToAction("StudentIndex", new { StudentId = ViewModel.Enrollment.StudentId }));
            }

            ViewData["CourseId"]  = new SelectList(_context.Course, "Id", "Title", ViewModel.Enrollment.CourseId);
            ViewData["StudentId"] = new SelectList(_context.Student, "Id", "FullName", ViewModel.Enrollment.StudentId);

            return(View(ViewModel));
        }