public async Task <IActionResult> Edit(int id, [Bind("EduSheduleId,EduYearId,EduProfileId,EduFormId,FileModelId")] EduShedule eduShedule, IFormFile uploadedFile) { if (id != eduShedule.EduSheduleId) { return(NotFound()); } if (ModelState.IsValid) { if (uploadedFile != null) { FileModel fileModel = await KisVuzDotNetCore2.Models.Files.Files.LoadFile(_context, _appEnvironment, uploadedFile, "Календарный учебный график", FileDataTypeEnum.KalendarniyUchebniyGraphik); await _context.SaveChangesAsync(); int?fileToRemoveId = eduShedule.FileModelId; eduShedule.FileModelId = fileModel.Id; await _context.SaveChangesAsync(); KisVuzDotNetCore2.Models.Files.Files.RemoveFile(_context, _appEnvironment, fileToRemoveId); } try { _context.Update(eduShedule); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EduSheduleExists(eduShedule.EduSheduleId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["EduFormId"] = new SelectList(_context.EduForms, "EduFormId", "EduFormId", eduShedule.EduFormId); ViewData["EduProfileId"] = new SelectList(_context.EduProfiles, "EduProfileId", "EduProfileId", eduShedule.EduProfileId); ViewData["EduYearId"] = new SelectList(_context.EduYears, "EduYearId", "EduYearId", eduShedule.EduYearId); ViewData["FileModelId"] = new SelectList(_context.Files, "Id", "Id", eduShedule.FileModelId); return(View(eduShedule)); }
public async Task <IActionResult> Create([Bind("EduSheduleId,EduYearId,EduProfileId,EduFormId")] EduShedule eduShedule, IFormFile uploadedFile) { if (ModelState.IsValid && uploadedFile != null) { FileModel fileModel = await KisVuzDotNetCore2.Models.Files.Files.LoadFile(_context, _appEnvironment, uploadedFile, "Календарный учебный график", FileDataTypeEnum.KalendarniyUchebniyGraphik); eduShedule.FileModelId = fileModel.Id; _context.Add(eduShedule); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["EduFormId"] = new SelectList(_context.EduForms, "EduFormId", "EduFormName", eduShedule.EduFormId); ViewData["EduProfileId"] = new SelectList(_context.EduProfiles.Include(p => p.EduNapravl.EduUgs.EduLevel), "EduProfileId", "GetEduProfileFullName", eduShedule.EduProfileId); ViewData["EduYearId"] = new SelectList(_context.EduYears, "EduYearId", "EduYearName", eduShedule.EduYearId); //ViewData["FileModelId"] = new SelectList(_context.Files, "Id", "Id", eduShedule.FileModelId); return(View(eduShedule)); }