コード例 #1
0
        /// <summary>
        /// Удаляет учебный план
        /// </summary>
        /// <param name="eduPlan"></param>
        /// <returns></returns>
        public async Task RemoveEduPlanAsync(EduPlan eduPlan)
        {
            if (eduPlan != null)
            {
                await _fileModelRepository.RemoveFileAsync(eduPlan.EduPlanPdfId);

                _context.EduPlans.Remove(eduPlan);
                await _context.SaveChangesAsync();
            }
        }
コード例 #2
0
        /// <summary>
        /// Возвращает объект дисциплины из учебного плана
        /// </summary>
        /// <param name="eduPlan"></param>
        /// <param name="disciplineId"></param>
        /// <returns></returns>
        public Discipline GetDiscipline(EduPlan eduPlan, int disciplineId)
        {
            Discipline discipline = null;

            eduPlan.BlokDiscipl
            .ForEach(b => b.BlokDisciplChast
                     .ForEach(c => c.Disciplines
                              .ForEach(d => { if (d.DisciplineId == disciplineId)
                                              {
                                                  discipline = d;
                                              }
                                       })));
            return(discipline);
        }
コード例 #3
0
        /// <summary>
        /// Добавление нового или обновление существующего учебного плана
        /// </summary>
        /// <param name="eduPlan"></param>
        /// <param name="uploadedFile"></param>
        /// <param name="eduVidDeyatIds"></param>
        /// <param name="eduYearBeginningTrainingIds"></param>
        /// <param name="eduPlanEduYearIds"></param>
        /// <returns></returns>
        public async Task <EduPlan> CreateEduPlan(EduPlan eduPlan,
                                                  IFormFile uploadedFile,
                                                  int[] eduVidDeyatIds,
                                                  int[] eduYearBeginningTrainingIds,
                                                  int[] eduPlanEduYearIds)
        {
            if (eduPlan.EduPlanId == 0)
            {
                _context.Add(eduPlan);
            }
            else
            {
                EduPlan eduPlanDbEntry = await GetEduPlanAsync(eduPlan.EduPlanId);

                eduPlanDbEntry.EduFormId      = eduPlan.EduFormId;
                eduPlanDbEntry.EduSrokId      = eduPlan.EduSrokId;
                eduPlanDbEntry.StructKafId    = eduPlan.StructKafId;
                eduPlanDbEntry.ProtokolNumber = eduPlan.ProtokolNumber;
                eduPlanDbEntry.ProtokolDate   = eduPlan.ProtokolDate;
                eduPlanDbEntry.UtverjdDate    = eduPlan.UtverjdDate;
                _context.Update(eduPlanDbEntry);
                eduPlan = eduPlanDbEntry;
            }

            await _context.SaveChangesAsync();

            if (uploadedFile != null)
            {
                FileModel fileModel = await Files.Files.LoadFile(_context, _appEnvironment, uploadedFile, "Учебный план", FileDataTypeEnum.UchebniyPlan);

                await _context.SaveChangesAsync();

                int?fileToRemoveId = eduPlan.EduPlanPdfId;
                eduPlan.EduPlanPdfId = fileModel.Id;
                await _context.SaveChangesAsync();

                Files.Files.RemoveFile(_context, _appEnvironment, fileToRemoveId);
            }

            try
            {
                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)
                {
                    if (eduPlan.EduPlanEduYears == null)
                    {
                        eduPlan.EduPlanEduYears = new List <EduPlanEduYear>();
                    }

                    foreach (var eduYearIdByUser in eduPlanEduYearIds)
                    {
                        bool isNeedAdd = true;
                        foreach (var item in eduPlan.EduPlanEduYears)
                        {
                            if (item.EduYearId == eduYearIdByUser)
                            {
                                isNeedAdd = false;
                            }
                        }

                        if (isNeedAdd)
                        {
                            eduPlan.EduPlanEduYears.Add(new EduPlanEduYear {
                                EduYearId = eduYearIdByUser, EduPlanId = eduPlan.EduPlanId
                            });
                            await _context.SaveChangesAsync();
                        }
                    }

                    var eduPlanEduYearEntriesToRemove = new List <EduPlanEduYear>();
                    foreach (var eduPlanEduYearEntry in eduPlan.EduPlanEduYears)
                    {
                        bool isNeedRemove = true;
                        foreach (var eduYearIdByUser in eduPlanEduYearIds)
                        {
                            if (eduYearIdByUser == eduPlanEduYearEntry.EduYearId)
                            {
                                isNeedRemove = false;
                            }
                        }

                        if (isNeedRemove)
                        {
                            eduPlanEduYearEntriesToRemove.Add(eduPlanEduYearEntry);
                        }
                    }
                    foreach (var removingItem in eduPlanEduYearEntriesToRemove)
                    {
                        eduPlan.EduPlanEduYears.Remove(removingItem);
                    }
                    await _context.SaveChangesAsync();
                }
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }

            return(eduPlan);
        }
コード例 #4
0
        /// <summary>
        /// Создаёт структуру учебного плана
        /// </summary>
        /// <param name="eduPlan"></param>
        /// <returns></returns>
        public async Task CreateEduPlanStructureAsync(EduPlan eduPlan)
        {
            int eduLevelId = eduPlan.EduProfile.EduNapravl.EduUgs.EduLevelId;

            // Создаём список, содержащий блоки дисциплин
            if (eduPlan.BlokDiscipl == null)
            {
                eduPlan.BlokDiscipl = new List <BlokDiscipl>();
                await _context.SaveChangesAsync();
            }

            // Заполняем блоки дисциплин
            if (eduPlan.BlokDiscipl.Count == 0)
            {
                foreach (var blokDisciplName in _context.BlokDisciplName.OrderBy(b => b.BlokDisciplNameName))
                {
                    BlokDiscipl blokDiscipl = new BlokDiscipl();
                    blokDiscipl.BlokDisciplNameId = blokDisciplName.BlokDisciplNameId;

                    bool isAddBlockDisc = false;
                    if (blokDiscipl.BlokDisciplNameId == 1)
                    {
                        isAddBlockDisc = true;
                    }
                    if (blokDiscipl.BlokDisciplNameId == 2)
                    {
                        isAddBlockDisc = true;
                    }
                    if (eduLevelId == 2)
                    {
                        if (blokDiscipl.BlokDisciplNameId == 3)
                        {
                            isAddBlockDisc = true;
                        }
                    }
                    if (eduLevelId == 3 || eduLevelId == 4 || eduLevelId == 5)
                    {
                        if (blokDiscipl.BlokDisciplNameId == 3)
                        {
                            isAddBlockDisc = true;
                        }
                        if (blokDiscipl.BlokDisciplNameId == 4)
                        {
                            isAddBlockDisc = true;
                        }
                    }
                    else if (eduLevelId == 6)
                    {
                        if (blokDiscipl.BlokDisciplNameId == 9)
                        {
                            isAddBlockDisc = true;
                        }
                        if (blokDiscipl.BlokDisciplNameId == 10)
                        {
                            isAddBlockDisc = true;
                        }
                        if (blokDiscipl.BlokDisciplNameId == 11)
                        {
                            isAddBlockDisc = true;
                        }
                    }

                    if (isAddBlockDisc)
                    {
                        eduPlan.BlokDiscipl.Add(blokDiscipl);
                    }
                }

                await _context.SaveChangesAsync();
            }

            foreach (var blokDiscipl in eduPlan.BlokDiscipl)
            {
                if (blokDiscipl.BlokDisciplChast == null)
                {
                    blokDiscipl.BlokDisciplChast = new List <BlokDisciplChast>();
                    await _context.SaveChangesAsync();
                }

                if (blokDiscipl.BlokDisciplChast.Count == 0)
                {
                    foreach (var blokDisciplChastName in _context.BlokDisciplChastName)
                    {
                        BlokDisciplChast blokDisciplChast = new BlokDisciplChast();
                        blokDisciplChast.BlokDisciplId          = blokDiscipl.BlokDisciplId;
                        blokDisciplChast.BlokDisciplChastNameId = blokDisciplChastName.BlokDisciplChastNameId;

                        blokDiscipl.BlokDisciplChast.Add(blokDisciplChast);
                    }
                }
            }
            await _context.SaveChangesAsync();



            return;
        }