public async Task <IActionResult> Edit(int id, [Bind("EduProgramEduYearId,EduProgramId,EduYearId")] EduProgramEduYear eduProgramEduYear) { if (id != eduProgramEduYear.EduProgramEduYearId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(eduProgramEduYear); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EduProgramEduYearExists(eduProgramEduYear.EduProgramEduYearId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["EduProgramId"] = new SelectList(_context.EduPrograms, "EduProgramId", "EduProgramId", eduProgramEduYear.EduProgramId); ViewData["EduYearId"] = new SelectList(_context.EduYears, "EduYearId", "EduYearId", eduProgramEduYear.EduYearId); return(View(eduProgramEduYear)); }
public async Task <IActionResult> Create([Bind("EduProgramId,EduProfileId,EduProgramPodgId,IsAdopt,UsingElAndDistEduTech,DateUtverjd")] EduProgram eduProgram, IFormFile uploadedFile, int[] eduFormIds, int[] eduYearIds) { if (ModelState.IsValid && uploadedFile != null) { FileModel fileModel = await KisVuzDotNetCore2.Models.Files.Files.LoadFile(_context, _appEnvironment, uploadedFile, "Образовательная программа", FileDataTypeEnum.OPOP); eduProgram.FileModelId = fileModel.Id; _context.Add(eduProgram); await _context.SaveChangesAsync(); if (eduFormIds != null) { var eduProgramEduFormList = new List <EduProgramEduForm>(); foreach (int eduFormId in eduFormIds) { EduProgramEduForm eduProgramEduForm = new EduProgramEduForm { EduProgramId = eduProgram.EduProgramId, EduFormId = eduFormId }; eduProgramEduFormList.Add(eduProgramEduForm); } await _context.EduProgramEduForms.AddRangeAsync(eduProgramEduFormList); await _context.SaveChangesAsync(); } if (eduYearIds != null) { var eduProgramEduYearList = new List <EduProgramEduYear>(); foreach (int eduYearId in eduYearIds) { EduProgramEduYear eduProgramEduYear = new EduProgramEduYear { EduProgramId = eduProgram.EduProgramId, EduYearId = eduYearId }; eduProgramEduYearList.Add(eduProgramEduYear); } await _context.EduProgramEduYears.AddRangeAsync(eduProgramEduYearList); await _context.SaveChangesAsync(); } return(RedirectToAction(nameof(Index))); } ViewData["EduProfileId"] = new SelectList(_context.EduProfiles.Include(p => p.EduNapravl.EduUgs.EduLevel), "EduProfileId", "GetEduProfileFullName", eduProgram.EduProfileId); ViewData["EduProgramPodgId"] = new SelectList(_context.EduProgramPodg, "EduProgramPodgId", "EduProgramPodgName", eduProgram.EduProgramPodgId); //ViewData["FileModelId"] = new SelectList(_context.Files, "Id", "Id", eduProgram.FileModelId); return(View(eduProgram)); }
public async Task <IActionResult> Create([Bind("EduProgramEduYearId,EduProgramId,EduYearId")] EduProgramEduYear eduProgramEduYear) { if (ModelState.IsValid) { _context.Add(eduProgramEduYear); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["EduProgramId"] = new SelectList(_context.EduPrograms, "EduProgramId", "EduProgramId", eduProgramEduYear.EduProgramId); ViewData["EduYearId"] = new SelectList(_context.EduYears, "EduYearId", "EduYearId", eduProgramEduYear.EduYearId); return(View(eduProgramEduYear)); }
/// <summary> /// Обновляет образовательную программу, если она доступна пользователю /// </summary> /// <param name="userName"></param> /// <param name="eduProgram"></param> /// <param name="uploadedFile"></param> /// <param name="eduFormIds"></param> /// <param name="eduYearIds"></param> public async Task UpdateEduProgramByUserNameAsync(string userName, EduProgram eduProgram, IFormFile uploadedFile, int[] eduFormIds, int[] eduYearBeginningTrainingIds, int[] eduYearIds) { /////// try { if (uploadedFile != null) { FileModel fileModel = await KisVuzDotNetCore2.Models.Files.Files.LoadFile(_context, _appEnvironment, uploadedFile, "Образовательная программа", FileDataTypeEnum.OPOP); await _context.SaveChangesAsync(); int?fileToRemoveId = eduProgram.FileModelId; eduProgram.FileModelId = fileModel.Id; await _context.SaveChangesAsync(); KisVuzDotNetCore2.Models.Files.Files.RemoveFile(_context, _appEnvironment, fileToRemoveId); } _context.Update(eduProgram); await _context.SaveChangesAsync(); if (eduFormIds != null) { _context.EduProgramEduForms.RemoveRange(_context.EduProgramEduForms.Where(f => f.EduProgramId == eduProgram.EduProgramId)); await _context.SaveChangesAsync(); var eduProgramEduFormList = new List <EduProgramEduForm>(); foreach (int eduFormId in eduFormIds) { EduProgramEduForm eduProgramEduForm = new EduProgramEduForm { EduProgramId = eduProgram.EduProgramId, EduFormId = eduFormId }; eduProgramEduFormList.Add(eduProgramEduForm); } await _context.EduProgramEduForms.AddRangeAsync(eduProgramEduFormList); await _context.SaveChangesAsync(); } if (eduYearBeginningTrainingIds != null) { _context.EduProgramEduYearBeginningTraining.RemoveRange(_context.EduProgramEduYearBeginningTraining.Where(f => f.EduProgramId == eduProgram.EduProgramId)); await _context.SaveChangesAsync(); var eduProgramEduYearBeginningTrainingList = new List <EduProgramEduYearBeginningTraining>(); foreach (int eduYearBeginningTrainingId in eduYearBeginningTrainingIds) { EduProgramEduYearBeginningTraining eduProgramEduYearBeginningTraining = new EduProgramEduYearBeginningTraining { EduProgramId = eduProgram.EduProgramId, EduYearBeginningTrainingId = eduYearBeginningTrainingId }; eduProgramEduYearBeginningTrainingList.Add(eduProgramEduYearBeginningTraining); } await _context.EduProgramEduYearBeginningTraining.AddRangeAsync(eduProgramEduYearBeginningTrainingList); await _context.SaveChangesAsync(); } if (eduYearIds != null) { _context.EduProgramEduYears.RemoveRange(_context.EduProgramEduYears.Where(f => f.EduProgramId == eduProgram.EduProgramId)); await _context.SaveChangesAsync(); var eduProgramEduYearList = new List <EduProgramEduYear>(); foreach (int eduYearId in eduYearIds) { EduProgramEduYear eduProgramEduYear = new EduProgramEduYear { EduProgramId = eduProgram.EduProgramId, EduYearId = eduYearId }; eduProgramEduYearList.Add(eduProgramEduYear); } await _context.EduProgramEduYears.AddRangeAsync(eduProgramEduYearList); await _context.SaveChangesAsync(); } } catch (DbUpdateConcurrencyException) { throw; } /////// }
public async Task <IActionResult> Edit(int id, [Bind("EduProgramId,EduProfileId,EduProgramPodgId,IsAdopt,UsingElAndDistEduTech,FileModelId,DateUtverjd")] EduProgram eduProgram, IFormFile uploadedFile, int[] eduFormIds, int[] eduYearIds) { if (id != eduProgram.EduProgramId) { return(NotFound()); } if (ModelState.IsValid) { try { if (uploadedFile != null) { FileModel fileModel = await KisVuzDotNetCore2.Models.Files.Files.LoadFile(_context, _appEnvironment, uploadedFile, "Образовательная программа", FileDataTypeEnum.OPOP); await _context.SaveChangesAsync(); int?fileToRemoveId = eduProgram.FileModelId; eduProgram.FileModelId = fileModel.Id; await _context.SaveChangesAsync(); KisVuzDotNetCore2.Models.Files.Files.RemoveFile(_context, _appEnvironment, fileToRemoveId); } _context.Update(eduProgram); await _context.SaveChangesAsync(); if (eduFormIds != null) { _context.EduProgramEduForms.RemoveRange(_context.EduProgramEduForms.Where(f => f.EduProgramId == eduProgram.EduProgramId)); await _context.SaveChangesAsync(); var eduProgramEduFormList = new List <EduProgramEduForm>(); foreach (int eduFormId in eduFormIds) { EduProgramEduForm eduProgramEduForm = new EduProgramEduForm { EduProgramId = eduProgram.EduProgramId, EduFormId = eduFormId }; eduProgramEduFormList.Add(eduProgramEduForm); } await _context.EduProgramEduForms.AddRangeAsync(eduProgramEduFormList); await _context.SaveChangesAsync(); } if (eduYearIds != null) { _context.EduProgramEduYears.RemoveRange(_context.EduProgramEduYears.Where(f => f.EduProgramId == eduProgram.EduProgramId)); await _context.SaveChangesAsync(); var eduProgramEduYearList = new List <EduProgramEduYear>(); foreach (int eduYearId in eduYearIds) { EduProgramEduYear eduProgramEduYear = new EduProgramEduYear { EduProgramId = eduProgram.EduProgramId, EduYearId = eduYearId }; eduProgramEduYearList.Add(eduProgramEduYear); } await _context.EduProgramEduYears.AddRangeAsync(eduProgramEduYearList); await _context.SaveChangesAsync(); } } catch (DbUpdateConcurrencyException) { if (!EduProgramExists(eduProgram.EduProgramId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["EduProfileId"] = new SelectList(_context.EduProfiles.Include(p => p.EduNapravl.EduUgs.EduLevel), "EduProfileId", "GetEduProfileFullName", eduProgram.EduProfileId); ViewData["EduProgramPodgId"] = new SelectList(_context.EduProgramPodg, "EduProgramPodgId", "EduProgramPodgName", eduProgram.EduProgramPodgId); //ViewData["FileModelId"] = new SelectList(_context.Files, "Id", "Id", eduProgram.FileModelId); return(View(eduProgram)); }