Пример #1
0
        public async Task <DisciplineVO> UpdateTaskAync(DisciplineVO newDiscipline)
        {
            if (!(await _disciplineRepository.FindByDisciplineIdTaskAsync(newDiscipline.DisciplineId) is DisciplineModel discipline))
            {
                return(null);
            }

            return(_disciplineConverter.Parse(await _disciplineRepository.UpdateTaskAsync(discipline, _disciplineConverter.Parse(newDiscipline))));
        }
Пример #2
0
        public async Task <DisciplineVO> AddTaskAsync(DisciplineVO discipline)
        {
            if (!(await _disciplineRepository.AddTaskAsync(_disciplineConverter.Parse(discipline)) is DisciplineModel addedDisci))
            {
                return(null);
            }

            return(_disciplineConverter.Parse(addedDisci));
        }
Пример #3
0
        public async Task <IActionResult> UpdateTaskAsync([FromBody] DisciplineVO newDiscipline)
        {
            if (ModelState.IsValid)
            {
                if (!(await _disciplineBusiness.FindByDisciplineIdTaskAsync(newDiscipline.DisciplineId) is DisciplineVO currentDiscipline))
                {
                    return(NotFound("Não existe uma disciplina com esse Id"));
                }

                CourseVO course = await _courseBusiness.FindByCourseIdTaskAsync(currentDiscipline.CourseId);

                if (course.CoordinatorId != Guid.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
                {
                    return(Unauthorized("Você não tem autorizaçao para alterar uma disciplina de outro curso!"));
                }

                newDiscipline.CourseId = course.CourseId;

                if (await _disciplineBusiness.ExistsByNameAndCourseIdTaskAsync(newDiscipline.Name, newDiscipline.CourseId))
                {
                    if (newDiscipline.Name != currentDiscipline.Name)
                    {
                        return(Conflict("Ja existe uma disciplina com esse nome"));
                    }
                }

                if (string.IsNullOrEmpty(newDiscipline.Name))
                {
                    return(BadRequest("É necessario informar o nome da disciplina!"));
                }

                if (string.IsNullOrEmpty(newDiscipline.Teacher))
                {
                    return(BadRequest("É necessario informar o nome do professor!"));
                }

                if (newDiscipline.Period <= 0)
                {
                    return(BadRequest("O periodo precisa ser maior que zero!"));
                }

                if (newDiscipline.ClassId == Guid.Empty)
                {
                    return(BadRequest("É necessario informar a sala!"));
                }

                if (await _disciplineBusiness.UpdateTaskAync(newDiscipline) is DisciplineVO disciplineUpdated)
                {
                    return(Created($"/Disciplines/{disciplineUpdated.DisciplineId}", disciplineUpdated));
                }
            }

            return(BadRequest());
        }
Пример #4
0
        public async Task <IActionResult> AddTaskAsync([FromBody] DisciplineVO newDiscipline)
        {
            if (ModelState.IsValid)
            {
                if (await _disciplineBusiness.ExistsByNameAndCourseIdTaskAsync(newDiscipline.Name, newDiscipline.CourseId))
                {
                    return(Conflict("Ja existe uma disciplina com esse nome"));
                }

                var coordId = Guid.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

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

                if (string.IsNullOrEmpty(newDiscipline.Name))
                {
                    return(BadRequest("É necessario informar o nome da disciplina!"));
                }

                if (string.IsNullOrEmpty(newDiscipline.Teacher))
                {
                    return(BadRequest("É necessario informar o nome do professor!"));
                }

                if (newDiscipline.Period <= 0)
                {
                    return(BadRequest("O periodo precisa ser maior que zero!"));
                }

                if (newDiscipline.ClassId == Guid.Empty)
                {
                    return(BadRequest("É necessario informar a sala!"));
                }

                if (await _disciplineBusiness.AddTaskAsync(newDiscipline) is DisciplineVO addedDiscipline)
                {
                    return(Created("/disciplines", addedDiscipline));
                }

                return(BadRequest("Algo deu errado, verifique os valores e tente novamente"));
            }

            return(BadRequest());
        }
Пример #5
0
        public async Task <ResultModel <DisciplineVO> > AddDisciplineTaskAsync(DisciplineVO newDiscipline, string token)
        {
            IRestResponse response = await SendRequestTaskAsync();

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

                _ => new ResultModel <DisciplineVO>
                {
                    Message = response.Content.Replace("\"", string.Empty),
                    StatusCode = response.StatusCode
                }
            });