/// <summary> /// Инициализация таблицы "Таблица для связи EduPlan и EduVidDeyat" /// </summary> /// <param name="serviceProvider"></param> /// <param name="configuration"></param> /// <returns></returns> public static async Task CreateEduPlanEduVidDeyats(IServiceProvider serviceProvider, IConfiguration configuration) { using (var serviceScope = serviceProvider.GetRequiredService <IServiceScopeFactory>().CreateScope()) { AppIdentityDBContext context = serviceScope.ServiceProvider.GetService <AppIdentityDBContext>(); #region Инициализация таблицы "Таблица для связи EduPlan и EduVidDeyat" if (!await context.EduPlanEduVidDeyats.AnyAsync()) { EduPlanEduVidDeyat EduPlanEduVidDeyat1 = new EduPlanEduVidDeyat { EduPlanEduVidDeyatId = 1, EduPlanId = 1, EduVidDeyatId = 1 }; await context.EduPlanEduVidDeyats.AddRangeAsync( EduPlanEduVidDeyat1 ); await context.SaveChangesAsync(); } #endregion } }
public async Task <IActionResult> Edit(int id, [Bind("EduPlanEduVidDeyatId,EduPlanId,EduVidDeyatId")] EduPlanEduVidDeyat eduPlanEduVidDeyat) { if (id != eduPlanEduVidDeyat.EduPlanEduVidDeyatId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(eduPlanEduVidDeyat); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EduPlanEduVidDeyatExists(eduPlanEduVidDeyat.EduPlanEduVidDeyatId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } var EduPlans = _context.EduPlans .Include(p => p.EduProfile.EduNapravl.EduUgs.EduLevel) .Include(p => p.EduForm); ViewData["EduPlanId"] = new SelectList(EduPlans, "EduPlanId", "EduPlanDescription", eduPlanEduVidDeyat.EduPlanId); ViewData["EduVidDeyatId"] = new SelectList(_context.EduVidDeyat, "EduVidDeyatId", "EduVidDeyatName", eduPlanEduVidDeyat.EduVidDeyatId); return(View(eduPlanEduVidDeyat)); }
public async Task <IActionResult> Create(EduPlanEduVidDeyat eduPlanEduVidDeyat) { if (ModelState.IsValid) { _context.Add(eduPlanEduVidDeyat); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["EduPlanId"] = new SelectList(_context.EduPlans, "EduPlanId", "EduPlanId", eduPlanEduVidDeyat.EduPlanId); ViewData["EduVidDeyatId"] = new SelectList(_context.EduVidDeyat, "EduVidDeyatId", "EduVidDeyatId", eduPlanEduVidDeyat.EduVidDeyatId); return(View(eduPlanEduVidDeyat)); }
public async Task <IActionResult> Edit(int id, EduPlan eduPlan, IFormFile uploadedFile, int[] EduVidDeyatIds, int[] EduYearBeginningTrainingIds, int[] EduPlanEduYearIds) { if (id != eduPlan.EduPlanId) { return(NotFound()); } if (ModelState.IsValid) { if (uploadedFile != null) { FileModel fileModel = await KisVuzDotNetCore2.Models.Files.Files.LoadFile(_context, _appEnvironment, uploadedFile, "Учебный план", FileDataTypeEnum.UchebniyPlan); await _context.SaveChangesAsync(); int?fileToRemoveId = eduPlan.EduPlanPdfId; eduPlan.EduPlanPdfId = fileModel.Id; await _context.SaveChangesAsync(); KisVuzDotNetCore2.Models.Files.Files.RemoveFile(_context, _appEnvironment, fileToRemoveId); } try { _context.Update(eduPlan); await _context.SaveChangesAsync(); if (EduVidDeyatIds != null) { _context.EduPlanEduVidDeyats.RemoveRange(_context.EduPlanEduVidDeyats.Where(v => v.EduPlanId == eduPlan.EduPlanId)); await _context.SaveChangesAsync(); var eduPlanEduVidDeyats = new List <EduPlanEduVidDeyat>(); foreach (var EduVidDeyatId in EduVidDeyatIds) { EduPlanEduVidDeyat eduPlanEduVidDeyat = new EduPlanEduVidDeyat(); eduPlanEduVidDeyat.EduPlanId = eduPlan.EduPlanId; eduPlanEduVidDeyat.EduVidDeyatId = EduVidDeyatId; eduPlanEduVidDeyats.Add(eduPlanEduVidDeyat); } await _context.EduPlanEduVidDeyats.AddRangeAsync(eduPlanEduVidDeyats); await _context.SaveChangesAsync(); } if (EduYearBeginningTrainingIds != null) { _context.EduPlanEduYearBeginningTraining.RemoveRange(_context.EduPlanEduYearBeginningTraining.Where(y => y.EduPlanId == eduPlan.EduPlanId)); await _context.SaveChangesAsync(); var eduPlanEduYearBeginningTrainings = new List <EduPlanEduYearBeginningTraining>(); foreach (var EduYearBeginningTrainingId in EduYearBeginningTrainingIds) { EduPlanEduYearBeginningTraining eduPlanEduYearBeginningTraining = new EduPlanEduYearBeginningTraining(); eduPlanEduYearBeginningTraining.EduPlanId = eduPlan.EduPlanId; eduPlanEduYearBeginningTraining.EduYearBeginningTrainingId = EduYearBeginningTrainingId; eduPlanEduYearBeginningTrainings.Add(eduPlanEduYearBeginningTraining); } await _context.EduPlanEduYearBeginningTraining.AddRangeAsync(eduPlanEduYearBeginningTrainings); await _context.SaveChangesAsync(); } if (EduPlanEduYearIds != null) { _context.EduPlanEduYears.RemoveRange(_context.EduPlanEduYears.Where(y => y.EduPlanId == eduPlan.EduPlanId)); await _context.SaveChangesAsync(); var eduPlanEduYears = new List <EduPlanEduYear>(); foreach (var EduPlanEduYearId in EduPlanEduYearIds) { EduPlanEduYear eduPlanEduYear = new EduPlanEduYear(); eduPlanEduYear.EduPlanId = eduPlan.EduPlanId; eduPlanEduYear.EduYearId = EduPlanEduYearId; eduPlanEduYears.Add(eduPlanEduYear); } await _context.EduPlanEduYears.AddRangeAsync(eduPlanEduYears); await _context.SaveChangesAsync(); } } catch (DbUpdateConcurrencyException) { if (!EduPlanExists(eduPlan.EduPlanId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["EduFormId"] = new SelectList(_context.EduForms, "EduFormId", "EduFormId", eduPlan.EduFormId); ViewData["EduPlanPdfId"] = new SelectList(_context.Files, "Id", "Id", eduPlan.EduPlanPdfId); ViewData["EduProfileId"] = new SelectList(_context.EduProfiles, "EduProfileId", "EduProfileId", eduPlan.EduProfileId); ViewData["EduProgramPodgId"] = new SelectList(_context.EduProgramPodg, "EduProgramPodgId", "EduProgramPodgId", eduPlan.EduProgramPodgId); ViewData["EduSrokId"] = new SelectList(_context.EduSrok, "EduSrokId", "EduSrokId", eduPlan.EduSrokId); ViewData["StructKafId"] = new SelectList(_context.StructKafs, "StructKafId", "StructKafId", eduPlan.StructKafId); return(View(eduPlan)); }
public async Task <IActionResult> Create(EduPlan eduPlan, IFormFile uploadedFile, int[] EduVidDeyatIds, int[] EduYearBeginningTrainingIds, int[] EduPlanEduYearIds) { if (ModelState.IsValid && uploadedFile != null) { FileModel fileModel = await KisVuzDotNetCore2.Models.Files.Files.LoadFile(_context, _appEnvironment, uploadedFile, "Учебный план", FileDataTypeEnum.UchebniyPlan); eduPlan.EduPlanPdfId = fileModel.Id; _context.EduPlans.Add(eduPlan); await _context.SaveChangesAsync(); if (EduVidDeyatIds != null) { var eduPlanEduVidDeyats = new List <EduPlanEduVidDeyat>(); foreach (var EduVidDeyatId in EduVidDeyatIds) { EduPlanEduVidDeyat eduPlanEduVidDeyat = new EduPlanEduVidDeyat(); eduPlanEduVidDeyat.EduPlanId = eduPlan.EduPlanId; eduPlanEduVidDeyat.EduVidDeyatId = EduVidDeyatId; eduPlanEduVidDeyats.Add(eduPlanEduVidDeyat); } await _context.EduPlanEduVidDeyats.AddRangeAsync(eduPlanEduVidDeyats); await _context.SaveChangesAsync(); } if (EduYearBeginningTrainingIds != null) { var eduPlanEduYearBeginningTrainings = new List <EduPlanEduYearBeginningTraining>(); foreach (var EduYearBeginningTrainingId in EduYearBeginningTrainingIds) { EduPlanEduYearBeginningTraining eduPlanEduYearBeginningTraining = new EduPlanEduYearBeginningTraining(); eduPlanEduYearBeginningTraining.EduPlanId = eduPlan.EduPlanId; eduPlanEduYearBeginningTraining.EduYearBeginningTrainingId = EduYearBeginningTrainingId; eduPlanEduYearBeginningTrainings.Add(eduPlanEduYearBeginningTraining); } await _context.EduPlanEduYearBeginningTraining.AddRangeAsync(eduPlanEduYearBeginningTrainings); await _context.SaveChangesAsync(); } if (EduPlanEduYearIds != null) { var eduPlanEduYears = new List <EduPlanEduYear>(); foreach (var EduPlanEduYearId in EduPlanEduYearIds) { EduPlanEduYear eduPlanEduYear = new EduPlanEduYear(); eduPlanEduYear.EduPlanId = eduPlan.EduPlanId; eduPlanEduYear.EduYearId = EduPlanEduYearId; eduPlanEduYears.Add(eduPlanEduYear); } await _context.EduPlanEduYears.AddRangeAsync(eduPlanEduYears); await _context.SaveChangesAsync(); } return(RedirectToAction(nameof(Index))); } ViewData["EduFormId"] = new SelectList(_context.EduForms, "EduFormId", "EduFormName", eduPlan.EduFormId); ViewData["EduProfileId"] = new SelectList(_context.EduProfiles.Include(p => p.EduNapravl.EduUgs.EduLevel), "EduProfileId", "GetEduProfileFullName", eduPlan.EduProfileId); ViewData["EduProgramPodgId"] = new SelectList(_context.EduProgramPodg, "EduProgramPodgId", "EduProgramPodgName", eduPlan.EduProgramPodgId); ViewData["EduSrokId"] = new SelectList(_context.EduSrok, "EduSrokId", "EduSrokName", eduPlan.EduSrokId); ViewData["StructKafId"] = new SelectList(_context.StructKafs.Include(k => k.StructSubvision), "StructKafId", "StructSubvision.StructSubvisionName", eduPlan.StructKafId); List <EduVidDeyat> eduVidDeyats = _context.EduVidDeyat.ToList(); ViewData["EduVidDeyats"] = eduVidDeyats; List <EduYearBeginningTraining> eduYearBeginningTrainings = _context.EduYearBeginningTrainings.ToList(); ViewData["EduYearBeginningTrainings"] = eduYearBeginningTrainings; List <EduYear> eduYears = _context.EduYears.ToList(); ViewData["EduYears"] = eduYears; return(View(eduPlan)); }