Example #1
0
        public async Task <IActionResult> AddStudentDetailAsync([FromBody] AddStudentManagementAc addStudent)
        {
            var loggedInUser = await _userManager.FindByNameAsync(User.Identity.Name);

            var loggedInUserInstituteId = await GetUserCurrentSelectedInstituteIdAsync();

            if (!await _iMSDbContext.InstituteClasses.AnyAsync(x => x.Id == addStudent.AdmissionClassId && x.InstituteId == loggedInUserInstituteId))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "Class not found", HasError = true, ErrorType = StudentManagementResponseType.AdmissionClassId
                }));
            }
            else if (!await _iMSDbContext.InstituteClasses.AnyAsync(x => x.Id == addStudent.AdmissionClassId && x.InstituteId == loggedInUserInstituteId))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "Class not found", HasError = true, ErrorType = StudentManagementResponseType.CurrentClassId
                }));
            }
            else if (!await _iMSDbContext.InstituteAcademicYears.AnyAsync(x => x.Id == addStudent.CurrentAcademicYearId && x.InstituteId == loggedInUserInstituteId))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "Academic year not found", HasError = true, ErrorType = StudentManagementResponseType.CurrentAcademicYearId
                }));
            }
            else if (!await _iMSDbContext.InstituteLanguageMasters.AnyAsync(x => x.Id == addStudent.FirstLanguageId && x.InstituteId == loggedInUserInstituteId))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "Language not found", HasError = true, ErrorType = StudentManagementResponseType.FirstLanguageId
                }));
            }
            else if (!await _iMSDbContext.InstituteLanguageMasters.AnyAsync(x => x.Id == addStudent.SecondLanguageId && x.InstituteId == loggedInUserInstituteId))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "Language not found", HasError = true, ErrorType = StudentManagementResponseType.SecondLanguageId
                }));
            }
            else if (!await _iMSDbContext.Genders.AnyAsync(x => x.Id == addStudent.GenderId && x.InstituteId == loggedInUserInstituteId))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "Gender not found", HasError = true, ErrorType = StudentManagementResponseType.GenderId
                }));
            }
            else if (addStudent.NationalityId.HasValue && !await _iMSDbContext.InstituteNationalities.AnyAsync(x => x.Id == addStudent.NationalityId.Value && x.InstituteId == loggedInUserInstituteId))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "Nationality not found", HasError = true, ErrorType = StudentManagementResponseType.NationalityId
                }));
            }
            else if (addStudent.MotherTongueId.HasValue && !await _iMSDbContext.MotherTongues.AnyAsync(x => x.Id == addStudent.MotherTongueId.Value && x.InstituteId == loggedInUserInstituteId))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "Mother tongue not found", HasError = true, ErrorType = StudentManagementResponseType.MotherTongueId
                }));
            }
            else if (addStudent.ReligionId.HasValue && !await _iMSDbContext.Religions.AnyAsync(x => x.Id == addStudent.ReligionId.Value && x.InstituteId == loggedInUserInstituteId))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "Religion not found", HasError = true, ErrorType = StudentManagementResponseType.ReligionId
                }));
            }
            else if (addStudent.CasteId.HasValue && !await _iMSDbContext.Castes.AnyAsync(x => x.Id == addStudent.CasteId.Value && x.InstituteId == loggedInUserInstituteId))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "Caste not found", HasError = true, ErrorType = StudentManagementResponseType.CasteId
                }));
            }
            else if (addStudent.BloodGroupId.HasValue && !await _iMSDbContext.BloodGroups.AnyAsync(x => x.Id == addStudent.BloodGroupId.Value && x.InstituteId == loggedInUserInstituteId))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "Blood group not found", HasError = true, ErrorType = StudentManagementResponseType.BloodGroupId
                }));
            }
            else if (addStudent.PassportIssuedCountryId.HasValue && !await _iMSDbContext.AdministrationCountries.AnyAsync(x => x.Id == addStudent.PassportIssuedCountryId.Value && x.InstituteId == loggedInUserInstituteId))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "Country group not found", HasError = true, ErrorType = StudentManagementResponseType.PassportIssuedCountryId
                }));
            }
            else if (addStudent.RelievingClassId.HasValue && !await _iMSDbContext.InstituteClasses.AnyAsync(x => x.Id == addStudent.RelievingClassId.Value && x.InstituteId == loggedInUserInstituteId))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "Class not found", HasError = true, ErrorType = StudentManagementResponseType.RelievingClassId
                }));
            }
            else if (addStudent.FamilyRelationOccupationId.HasValue && !await _iMSDbContext.Occupations.AnyAsync(x => x.Id == addStudent.FamilyRelationOccupationId.Value && x.InstituteId == loggedInUserInstituteId))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "Occupation not found", HasError = true, ErrorType = StudentManagementResponseType.FamilyRelationOccupationId
                }));
            }
            else if (!await _iMSDbContext.AdministrationCities.AnyAsync(x => x.Id == addStudent.PermanentCityId && x.State.Country.InstituteId == loggedInUserInstituteId))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "City not found", HasError = true, ErrorType = StudentManagementResponseType.PermanentCityId
                }));
            }
            else if (!await _iMSDbContext.AdministrationCities.AnyAsync(x => x.Id == addStudent.PresentCityId && x.State.Country.InstituteId == loggedInUserInstituteId))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "City not found", HasError = true, ErrorType = StudentManagementResponseType.PresentCityId
                }));
            }
            else if (CheckIfListOfStudentPriorEducations(addStudent.StudentPriorEducations))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "Prior educations must have institute name", HasError = true, ErrorType = StudentManagementResponseType.StudentPriorEducations
                }));
            }
            else if (CheckIfListOfStudentDisciplines(addStudent.StudentDisciplines))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "Student disciplines must have description and subject", HasError = true, ErrorType = StudentManagementResponseType.StudentDisciplines
                }));
            }
            else if (!await CheckIfListOfStudentStudentSportIdAsync(addStudent.StudentSports, loggedInUserInstituteId))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "Sport not found", HasError = true, ErrorType = StudentManagementResponseType.StudentSportId
                }));
            }
            else if (!await CheckIfListOfStudentStudentLevelIdAsync(addStudent.StudentSports, loggedInUserInstituteId))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "Level not found", HasError = true, ErrorType = StudentManagementResponseType.StudentLevelId
                }));
            }
            else if (CheckIfListOfStudentAwardAwardName(addStudent.StudentAwards))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "Student awards must have name", HasError = true, ErrorType = StudentManagementResponseType.StudentAwardName
                }));
            }
            else if (CheckIfListOfStudentAwardInstituteName(addStudent.StudentAwards))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "Student awards must have institute name", HasError = true, ErrorType = StudentManagementResponseType.StudentAwardInstituteName
                }));
            }
            else if (!await _iMSDbContext.MaritalStatuses.AnyAsync(x => x.Id == addStudent.MaritalStatusId && x.InstituteId == loggedInUserInstituteId))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "Marital status not found", HasError = true, ErrorType = StudentManagementResponseType.MaritalStatusId
                }));
            }
            else if (!await _iMSDbContext.Sections.AnyAsync(x => x.Id == addStudent.SectionId && x.InstituteId == loggedInUserInstituteId))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "Section not found", HasError = true, ErrorType = StudentManagementResponseType.SectionId
                }));
            }
            else
            {
                return(Ok(await _studentManagementRepository.AddStudentAsync(addStudent, loggedInUser)));
            }
        }