예제 #1
0
        public async Task <LessonVO> GetRecordingInfoTaskAsync(LessonVO lesson)
        {
            string[] parts = lesson.URI.Split('/');
            if (parts.Length <= 4)
            {
                return(null);
            }

            IRestResponse response = await SendRequestTaskAsync();

            if (response.StatusCode == HttpStatusCode.OK)
            {
                LessonVO lessonCollab = JsonSerializer.Deserialize <LessonVO>(response.Content, new JsonSerializerOptions {
                    PropertyNameCaseInsensitive = true
                });

                lesson.RecordName = lessonCollab.RecordName;
                lesson.Duration   = lessonCollab.Duration;
                lesson.Date       = lessonCollab.Date;

                return(lesson);
            }

            return(null);

            async Task <IRestResponse> SendRequestTaskAsync()
            {
                return(await new RequestService()
                {
                    Method = Method.GET,
                    URL = "https://us.bbcollab.com",
                    URN = $"collab/api/csa/recordings/{parts[4]}/data",
                }.ExecuteTaskAsync());
            }
        }
예제 #2
0
        public async Task <LessonVO> AddTaskAsync(LessonVO lessonCollab)
        {
            if (!(await _lessonRepository.AddTaskAsync(_lessonConverter.Parse(lessonCollab)) is LessonModel lessonModel))
            {
                return(null);
            }

            return(_lessonConverter.Parse(lessonModel));
        }
예제 #3
0
        public async Task <LessonVO> UpdateTaskAsync(LessonVO newLesson)
        {
            if (!(await _lessonRepository.FindByIdTaskAsync(newLesson.LessonId) is LessonModel oldLesson))
            {
                return(null);
            }

            return(_lessonConverter.Parse(await _lessonRepository.UpdateTaskAsync(oldLesson, _lessonConverter.Parse(newLesson))));
        }
예제 #4
0
        public async Task <IActionResult> AddClassTaskAsync([FromBody] LessonVO lesson)
        {
            if (ModelState.IsValid)
            {
                var coordId = Guid.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

                if (await _courseBusiness.FindByCoordIdTaskAsync(coordId) is CourseVO course)
                {
                    if (course.CourseId != lesson.CourseId)
                    {
                        return(Unauthorized("Você não tem permissão para adicionar aulas em outro curso!"));
                    }
                }

                if (await _lessonBusiness.FindByURITaskAsync(lesson.URI) is LessonVO)
                {
                    return(Conflict("A aula informada ja existe, verifique se o link está correto"));
                }

                if (lesson.DisciplineId == Guid.Empty)
                {
                    return(BadRequest("É necessario informar a disciplina!"));
                }

                if (!await _disciplineBusiness.ExistsByDisciplineIdTaskAsync(lesson.DisciplineId))
                {
                    return(NotFound("Não existe a disciplina com o Id informado"));
                }

                if (!(await _lessonBusiness.GetRecordingInfoTaskAsync(lesson) is LessonVO lessonCollab))
                {
                    return(NotFound("Não foi possivel encontrar as informações da aula informada, verifique se o link está correto!"));
                }

                if (await _lessonBusiness.AddTaskAsync(lessonCollab) is LessonVO addedClass)
                {
                    return(Created($"/lessons/{addedClass.LessonId}", addedClass));
                }
            }

            return(BadRequest());
        }
예제 #5
0
        public async Task <ResultModel <LessonVO> > AddLessonTaskAsync(LessonVO lesson, string token)
        {
            IRestResponse response = await SendRequestTaskAsync();

            return(response.StatusCode switch
            {
                HttpStatusCode.Created => new ResultModel <LessonVO>
                {
                    Object = JsonSerializer.Deserialize <LessonVO>(response.Content, new JsonSerializerOptions {
                        PropertyNameCaseInsensitive = true
                    }),
                    StatusCode = response.StatusCode,
                    Message = "Aula adicionada com Sucessso!"
                },

                _ => new ResultModel <LessonVO>
                {
                    StatusCode = response.StatusCode,
                    Message = response.Content.Replace("\"", string.Empty)
                }
            });
예제 #6
0
 public async Task <LessonVO> GetRecordingInfoTaskAsync(LessonVO lesson) =>
 await _collabAPIService.GetRecordingInfoTaskAsync(lesson);
예제 #7
0
 public async Task <LessonVO> AddTaskAsync(LessonVO lessonCollab)
 {
     return(_lessonConverter.Parse(await _lessonRepository.AddTaskAsync(_lessonConverter.Parse(lessonCollab))));
 }