예제 #1
0
        /// <summary>
        /// Обновляет задание СДО
        /// </summary>
        /// <param name="lmsTask"></param>
        /// <param name="uploadedFile"></param>
        /// <returns></returns>
        public async Task UpdateLmsTaskAsync(LmsTask lmsTask, IFormFile uploadedFile)
        {
            if (lmsTask == null)
            {
                return;
            }

            if (uploadedFile != null)
            {
                if (lmsTask.LmsTaskJpgId != null)
                {
                    if (lmsTask.LmsTaskJpg == null)
                    {
                        lmsTask.LmsTaskJpg = await _fileModelRepository.GetFileModelAsync(lmsTask.LmsTaskJpgId);
                    }

                    await _fileModelRepository.ReloadFileAsync(lmsTask.LmsTaskJpg, uploadedFile);
                }
                else
                {
                    FileModel newFileModel = await _fileModelRepository.UploadLmsTaskJpg(uploadedFile);

                    if (newFileModel == null)
                    {
                        return;
                    }
                    lmsTask.LmsTaskJpgId = newFileModel.Id;
                }
            }

            _context.LmsTasks.Update(lmsTask);
            await _context.SaveChangesAsync();
        }
예제 #2
0
        /// <summary>
        /// Добавляет к заданию СДО дисциплину
        /// </summary>
        /// <param name="lmsTask"></param>
        /// <param name="disciplineNameId"></param>
        /// <returns></returns>
        public async Task AddLmsTaskDisciplineName(LmsTask lmsTask, int disciplineNameId)
        {
            foreach (var lmsTaskDisciplineName in lmsTask.LmsTaskDisciplineNames)
            {
                if (lmsTaskDisciplineName.DisciplineNameId == disciplineNameId)
                {
                    return;
                }
            }

            var newLmsTaskDisciplineName = new LmsTaskDisciplineName
            {
                DisciplineNameId = disciplineNameId
            };

            newLmsTaskDisciplineName.DisciplineName = await _context.DisciplineNames.SingleOrDefaultAsync(dn => dn.DisciplineNameId == disciplineNameId);

            lmsTask.LmsTaskDisciplineNames.Add(newLmsTaskDisciplineName);
            await _context.SaveChangesAsync();
        }
예제 #3
0
        /// <summary>
        /// Добавляет новое задание в базу заданий СДО
        /// </summary>
        /// <param name="lmsTask"></param>
        /// <param name="uploadedFile"></param>
        /// <returns></returns>
        public async Task AddLmsTask(LmsTask lmsTask, IFormFile uploadedFile)
        {
            if (lmsTask == null)
            {
                return;
            }

            if (uploadedFile != null)
            {
                FileModel newFileModel = await _fileModelRepository.UploadLmsTaskJpg(uploadedFile);

                if (newFileModel == null)
                {
                    return;
                }
                lmsTask.LmsTaskJpgId = newFileModel.Id;
            }

            _context.LmsTasks.Add(lmsTask);
            await _context.SaveChangesAsync();
        }
예제 #4
0
        /// <summary>
        /// Удаляет задание СДО
        /// </summary>
        /// <param name="lmsTask"></param>
        /// <returns></returns>
        public async Task RemoveLmsTaskAsync(LmsTask lmsTask)
        {
            if (lmsTask.LmsTaskAnswers != null)
            {
                foreach (var lmsTaskAnswer in lmsTask.LmsTaskAnswers)
                {
                    if (lmsTaskAnswer.FileModelId != null)
                    {
                        if (lmsTaskAnswer.FileModel != null)
                        {
                            await _fileModelRepository.RemoveFileModelAsync(lmsTaskAnswer.FileModel);
                        }
                        else
                        {
                            await _fileModelRepository.RemoveFileAsync(lmsTaskAnswer.FileModelId);
                        }
                    }
                }
            }


            if (lmsTask.LmsTaskJpgId != null)
            {
                if (lmsTask.LmsTaskJpg != null)
                {
                    await _fileModelRepository.RemoveFileModelAsync(lmsTask.LmsTaskJpg);
                }
                else
                {
                    await _fileModelRepository.RemoveFileAsync(lmsTask.LmsTaskJpgId);
                }
            }

            _context.LmsTasks.Remove(lmsTask);
            await _context.SaveChangesAsync();
        }