Example #1
0
        public async Task <IActionResult> CreateGrade(GradeToCreateDto newGrade)
        {
            var AcademicYear = _academicYearRepo.GetActiveYear();

            if (AcademicYear == null)
            {
                return(BadRequest("No Active Years Available"));
            }

            if (await _gradeRepo.GradeExist(newGrade.Name))
            {
                return(BadRequest("Grade with same name already exists"));
            }

            // Check if newGrade.AssistantPrincipalId is assistant principal

            var gradeToCreate = new Grade {
                Name                 = newGrade.Name,
                AcademicYearId       = AcademicYear.Id,
                AssistantPrincipalId = newGrade.AssistantPrincipalId,
                Created              = DateTime.Now,
                LastUpdated          = DateTime.Now
            };

            return((await _gradeRepo.CreateGrade(gradeToCreate) != null) ? StatusCode(201) : BadRequest());
        }