/// <summary>
        /// Инициализация таблицы "Учебные планы"
        /// </summary>
        /// <param name="serviceProvider"></param>
        /// <param name="configuration"></param>
        /// <returns></returns>
        public static async Task CreateEduPlans(IServiceProvider serviceProvider, IConfiguration configuration)
        {
            using (var serviceScope = serviceProvider.GetRequiredService <IServiceScopeFactory>().CreateScope())
            {
                AppIdentityDBContext context = serviceScope.ServiceProvider.GetService <AppIdentityDBContext>();

                #region Инициализация таблицы "Учебные планы"
                if (!await context.EduPlans.AnyAsync())
                {
                    EduPlan EduPlan1 = new EduPlan
                    {
                        ProtokolNumber   = "4",
                        ProtokolDate     = new DateTime(2017, 09, 21),
                        UtverjdDate      = new DateTime(2017, 09, 30),
                        EduFormId        = 1,
                        EduProfileId     = 1,
                        EduProgramPodgId = 1,
                        EduSrokId        = 1,
                        StructKafId      = 1
                    };

                    await context.EduPlans.AddRangeAsync(
                        EduPlan1

                        );

                    await context.SaveChangesAsync();
                }
                #endregion
            }
        }
        public async Task <IActionResult> EduPlanCreateOrEdit(EduPlan eduPlan,
                                                              int EduProgramId,
                                                              IFormFile uploadedFile,
                                                              int[] EduVidDeyatIds,
                                                              int[] EduYearBeginningTrainingIds,
                                                              int[] EduPlanEduYearIds)
        {
            if (ModelState.IsValid)
            {
                EduPlan eduPlanRepositoryEntry = await _metodKomissiyaRepository
                                                 .CreateEduPlanByUserNameAsync(EduProgramId,
                                                                               eduPlan, uploadedFile, EduVidDeyatIds,
                                                                               EduYearBeginningTrainingIds, EduPlanEduYearIds,
                                                                               User.Identity.Name);

                return(RedirectToAction(nameof(EduPrograms)));
            }

            var eduProgram = await _metodKomissiyaRepository.GetEduProgramByUserNameAsync(EduProgramId, User.Identity.Name);

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

            ViewData["EduFormId"]        = _selectListRepository.GetSelectListEduForms();
            ViewData["EduProfileId"]     = eduProgram.EduProfileId;
            ViewData["EduProgramPodgId"] = eduProgram.EduProgramPodgId;
            ViewData["EduSrokId"]        = _selectListRepository.GetSelectListEduSrok();
            ViewData["StructKafId"]      = _selectListRepository.GetSelectListStructKaf();

            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));
        }
        public async Task <IActionResult> EduPlanCreateOrEdit(int EduProgramId, int?EduPlanId)
        {
            var eduProgram = await _metodKomissiyaRepository.GetEduProgramByUserNameAsync(EduProgramId, User.Identity.Name);

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

            var eduPlan = new EduPlan();

            if (EduPlanId != null)
            {
                eduPlan = await _metodKomissiyaRepository.GetEduPlanByUserNameAsync((int)EduPlanId, User.Identity.Name);

                ViewData["EduPlanId"] = EduPlanId;
            }

            ViewData["EduFormId"]        = _selectListRepository.GetSelectListEduForms();
            ViewData["EduProfileId"]     = eduProgram.EduProfileId;
            ViewData["EduProgramId"]     = eduProgram.EduProgramId;
            ViewData["EduProgramPodgId"] = eduProgram.EduProgramPodgId;
            ViewData["EduSrokId"]        = _selectListRepository.GetSelectListEduSrok();
            ViewData["StructKafId"]      = _selectListRepository.GetSelectListStructKaf();

            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("EduPlanCreateOrEdit", eduPlan));
        }
        /// <summary>
        /// Возвращает учебный план, если он доступен пользователю
        /// </summary>
        /// <param name="eduPlanId"></param>
        /// <param name="userName"></param>
        /// <returns></returns>
        public async Task <EduPlan> GetEduPlanByUserNameAsync(int eduPlanId, string userName)
        {
            var appUser = await GetAppUserAsync(userName);

            var eduPlansOfUser = new List <EduPlan>();

            appUser.Teachers
            .ForEach(t => t.TeacherMetodKomissii
                     .ForEach(tm => tm.MetodKomissiya.MetodKomissiyaEduProfiles
                              .ForEach(mp => mp.EduProfile.EduPlans
                                       .ForEach(ep => eduPlansOfUser.Add(ep)))));
            var eduPlan = eduPlansOfUser.SingleOrDefault(ep => ep.EduPlanId == eduPlanId);

            if (eduPlan == null)
            {
                return(null);
            }

            EduPlan eduPlanWithFullData = await _eduPlanRepository.GetEduPlanAsync(eduPlan.EduPlanId);

            return(eduPlanWithFullData);
        }
        /// <summary>
        /// Добавление нового или обновление существующего учебного плана,
        /// если образовательная программа доступна пользователю
        /// </summary>
        /// <param name="eduProgramId"></param>
        /// <param name="eduPlan"></param>
        /// <param name="uploadedFile"></param>
        /// <param name="eduVidDeyatIds"></param>
        /// <param name="eduYearBeginningTrainingIds"></param>
        /// <param name="eduPlanEduYearIds"></param>
        /// <param name="userName"></param>
        /// <returns></returns>
        public async Task <EduPlan> CreateEduPlanByUserNameAsync(int eduProgramId,
                                                                 EduPlan eduPlan,
                                                                 IFormFile uploadedFile,
                                                                 int[] eduVidDeyatIds,
                                                                 int[] eduYearBeginningTrainingIds,
                                                                 int[] eduPlanEduYearIds,
                                                                 string userName)
        {
            var eduProgram = await GetEduProgramByUserNameAsync(eduProgramId, userName);

            if (eduProgram == null)
            {
                return(null);
            }

            EduPlan eduPlanDbEntry = await _eduPlanRepository.CreateEduPlan(eduPlan,
                                                                            uploadedFile,
                                                                            eduVidDeyatIds,
                                                                            eduYearBeginningTrainingIds,
                                                                            eduPlanEduYearIds);

            return(eduPlanDbEntry);
        }
Ejemplo n.º 6
0
        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));
        }
Ejemplo n.º 7
0
        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));
        }