public async Task <IActionResult> Create([Bind("ProfessionalRetrainingId,ProfessionalRetrainingDiplomRegNumber,ProfessionalRetrainingDiplomNumber,ProfessionalRetrainingProgramName,ProfessionalRetrainingHours,ProfessionalRetrainingCity,ProfessionalRetrainingInstitition,ProfessionalRetrainingDateStart,ProfessionalRetrainingDateFinish,ProfessionalRetrainingDateIssue,AppUserId")] ProfessionalRetraining professionalRetraining,
                                                 IFormFile uploadedFile)
        {
            if (ModelState.IsValid && uploadedFile != null)
            {
                FileModel fileModel = await KisVuzDotNetCore2.Models.Files.Files.LoadFile(_context, _appEnvironment, uploadedFile, "Диплом о профессиональной переподготовке", FileDataTypeEnum.DiplomOProfessionalnoyPerepodgotovke);

                professionalRetraining.ProfessionalRetrainingFileId = fileModel.Id;
                professionalRetraining.RowStatusId = (int)RowStatusEnum.NotConfirmed;
                _context.Add(professionalRetraining);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index), new { id = professionalRetraining.AppUserId }));
            }

            ViewBag.AppUserId = professionalRetraining.AppUserId;
            return(View(professionalRetraining));
        }
        public async Task <IActionResult> Edit(int id, [Bind("ProfessionalRetrainingId,ProfessionalRetrainingDiplomRegNumber,ProfessionalRetrainingDiplomNumber,ProfessionalRetrainingProgramName,ProfessionalRetrainingHours,ProfessionalRetrainingCity,ProfessionalRetrainingInstitition,ProfessionalRetrainingDateStart,ProfessionalRetrainingDateFinish,ProfessionalRetrainingDateIssue,ProfessionalRetrainingFileId,AppUserId")] ProfessionalRetraining professionalRetraining,
                                               IFormFile uploadedFile)
        {
            if (id != professionalRetraining.ProfessionalRetrainingId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (uploadedFile != null)
                    {
                        FileModel fileModel = await KisVuzDotNetCore2.Models.Files.Files.LoadFile(_context, _appEnvironment, uploadedFile, "Диплом о профессиональной переподготовке", FileDataTypeEnum.DiplomOProfessionalnoyPerepodgotovke);

                        await _context.SaveChangesAsync();

                        int?fileToRemoveId = professionalRetraining.ProfessionalRetrainingFileId;
                        professionalRetraining.ProfessionalRetrainingFileId = fileModel.Id;
                        await _context.SaveChangesAsync();

                        KisVuzDotNetCore2.Models.Files.Files.RemoveFile(_context, _appEnvironment, fileToRemoveId);
                    }
                    professionalRetraining.RowStatusId = (int)RowStatusEnum.NotConfirmed;
                    _context.Update(professionalRetraining);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProfessionalRetrainingExists(professionalRetraining.ProfessionalRetrainingId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index), new { id = professionalRetraining.AppUserId }));
            }

            return(View(professionalRetraining));
        }