Exemplo n.º 1
0
        private string UploadedProject(AuthStudentEditViewModel model)
        {
            string uniqueFileName = null;

            if (model.project != null)
            {
                string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "projects");
                uniqueFileName = Guid.NewGuid().ToString() + "_" + Path.GetFileName(model.project.FileName);
                string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    model.project.CopyTo(fileStream);
                }
            }
            return(uniqueFileName);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> EditStudent(int?courseId, int?studentId)
        {
            IQueryable <Enrollment> enrollments = _context.Enrollment.AsQueryable();

            if (courseId == null || studentId == null)
            {
                return(NotFound());
            }

            //var course = await _context.Course.FindAsync(id);

            var enrollmentId = enrollments.Where(s => s.CourseId == courseId).Where(s => s.StudentId == studentId);
            var projecturl   = await enrollmentId.ToListAsync();

            var pr    = "";
            var projj = -1;

            if (projecturl.Count == 0)
            {
                pr    = "";
                projj = -1;
            }
            else
            {
                pr    = projecturl[0].ProjectUrl;
                projj = projecturl[0].Id;
            }

            //enrollmentId = enrollments.Where(s => s.Id == enrollmentId)
            var authStudentVM = new AuthStudentEditViewModel
            {
                //ProjectUrl = enrollmentId.ToString(),
                enrollId = projj,
                PURL     = pr
            };

            return(View(authStudentVM));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> EditStudent(int?id, [FromRoute] int enrollId, AuthStudentEditViewModel model)
        {
            IQueryable <Enrollment> enrollments = _context.Enrollment.AsQueryable();
            var neededenroll = enrollments.Where(s => s.Id == enrollId);
            var enroll       = await neededenroll.ToListAsync();

            var enrollment = enroll[enroll.Count];

            if (ModelState.IsValid)
            {
                try
                {
                    string uniqueFileName = UploadedProject(model);
                    enrollment.SeminalUrl = uniqueFileName;
                    _context.Update(enrollment);
                    await _context.SaveChangesAsync();
                    await TryUpdateModelAsync <Enrollment>(
                        enrollment,
                        "",
                        s => s.ProjectUrl, s => s.SeminalUrl);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EnrollmentExists(enrollment.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(enrollment));
        }