Exemplo n.º 1
0
        public async Task <ActionResult> GetTaskTypeView(string lessonId, string sectionId, string taskId)
        {
            LessonTaskModel task   = new LessonTaskModel();
            Guid?           taskID = String.IsNullOrWhiteSpace(taskId) ? Guid.Empty : new Guid(taskId.ToSafeStringWithTrim());

            if (taskID != Guid.Empty)
            {
                task.LessonId  = String.IsNullOrWhiteSpace(lessonId) ? new Guid() : new Guid(lessonId.ToSafeStringWithTrim());
                task.SectionId = String.IsNullOrWhiteSpace(sectionId) ? new Guid() : task.SectionId = new Guid(sectionId.ToSafeStringWithTrim());

                LessonModel lesson  = lessonRepository.Value.LoadLesson(task.LessonId);
                Section     section = lesson.Sections.FirstOrDefault(a => a.SectionId == task.SectionId);
                if (section != null)
                {
                    task = section.Tasks.FirstOrDefault(t => t.TaskId == taskID);
                }
            }
            else
            {
                task.Type = TypeOfExpectedAnswer.Text.ToString();
            }
            return(PartialView("_CreateTask", task));
        }
Exemplo n.º 2
0
        public async Task <JsonResult> CreateTask(LessonTaskModel task)
        {
            LessonModel lesson    = lessonRepository.Value.LoadLesson(task.LessonId);
            Boolean     isSuccess = false;
            bool        isAdd     = false;

            try
            {
                if (lesson != null)
                {
                    Section section = lesson.Sections.Where(i => i != null).FirstOrDefault(a => a.SectionId == task.SectionId);
                    if ((task.TaskId == Guid.Empty) && (section != null))
                    {
                        task.TaskId = Guid.NewGuid();
                        isAdd       = true;
                    }

                    if (task.TaskType.ToSafeStringWithTrim().ToLower() != TaskType.Assignment.ToSafeStringWithTrim().ToLower())
                    {
                        task.XPPoints     = 0;
                        task.Language     = null;
                        task.Instructions = null;
                        task.Type         = null;
                        task.YouTubeLink  = task.YouTubeLink.ToSafeStringWithTrim();
                    }
                    else if (task.TaskType.ToSafeStringWithTrim().ToLower() != TaskType.Content.ToSafeStringWithTrim().ToLower())
                    {
                        task.YouTubeLink  = null;
                        task.Instructions = task.Instructions.ToSafeStringWithTrim();
                    }

                    if (isAdd)
                    {
                        if (section.Tasks == null)// Create new in case no task exist.
                        {
                            section.Tasks = new List <LessonTaskModel>();
                        }
                        section.Tasks.Add(task);
                    }
                    else
                    {
                        int updatedIndex = section.Tasks.FindLastIndex(t => t.TaskId == task.TaskId);
                        section.Tasks[updatedIndex] = task;
                    }
                    task.Name = task.Name.ToSafeStringWithTrim();
                    task.Text = task.Text.ToSafeStringWithTrim();

                    await lessonRepository.Value.AddUpdateLesson(lesson);

                    isSuccess = true;
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
            }

            return(Json(new
            {
                success = isSuccess,
                isAdd = isAdd,
                SectionId = task.SectionId.ToSafeStringWithTrim(),
                TaskId = task.TaskId.ToSafeStringWithTrim(),
                Title = task.Name.ToSafeStringWithTrim()
            }
                        ));
        }