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

                Student student = new Student
                {
                    FirstName       = model.Student.FirstName,
                    LastName        = model.Student.LastName,
                    StudentId       = model.Student.StudentId,
                    EnrollmentDate  = model.Student.EnrollmentDate,
                    AcquiredCredits = model.Student.AcquiredCredits,
                    CurrentSemestar = model.Student.CurrentSemestar,
                    EducationLevel  = model.Student.EducationLevel,
                    ProfilePicture  = uniqueFileName,
                };
                _context.Student.Add(student);
                //dbContext.Add(employee);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View());
        }
        private string UploadedFile(StudentsImageDemoModel model)
        {
            string uniqueFileName = null;


            if (model.ProfileImage != null)
            {
                string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "images");
                uniqueFileName = Guid.NewGuid().ToString() + "_" + Path.GetFileName(model.ProfileImage.FileName);
                string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    model.ProfileImage.CopyTo(fileStream);
                }
            }
            return(uniqueFileName);
        }
        public async Task <IActionResult> Edit(int id, StudentsImageDemoModel model)
        {
            if (id != model.Student.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    /**string uniqueFileName = UploadedFile(model);
                     * Student student = new Student
                     * {
                     *  FirstName = model.Student.FirstName,
                     *  LastName = model.Student.LastName,
                     *  StudentId = model.Student.StudentId,
                     *  EnrollmentDate = model.Student.EnrollmentDate,
                     *  AcquiredCredits = model.Student.AcquiredCredits,
                     *  CurrentSemestar = model.Student.CurrentSemestar,
                     *  EducationLevel = model.Student.EducationLevel,
                     *  ProfilePicture = uniqueFileName,
                     * };**/
                    _context.Update(model.Student);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StudentExists(model.Student.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var student = await _context.Student.FindAsync(id);

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

            var viewmodel = new StudentsImageDemoModel
            {
                Student = student
            };

            return(View(viewmodel));
        }