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

            var loggedInUserInstituteId = await GetUserCurrentSelectedInstituteIdAsync();

            if (!await _iMSDbContext.StudentBasicInformation.AnyAsync(x => x.Id == updateStudent.Id && x.InstituteId == loggedInUserInstituteId))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "Student not found", HasError = true
                }));
            }
            if (!await _iMSDbContext.InstituteClasses.AnyAsync(x => x.Id == updateStudent.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 == updateStudent.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 == updateStudent.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 == updateStudent.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 == updateStudent.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 == updateStudent.GenderId && x.InstituteId == loggedInUserInstituteId))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "Gender not found", HasError = true, ErrorType = StudentManagementResponseType.GenderId
                }));
            }
            else if (updateStudent.NationalityId.HasValue && !await _iMSDbContext.InstituteNationalities.AnyAsync(x => x.Id == updateStudent.NationalityId.Value && x.InstituteId == loggedInUserInstituteId))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "Nationality not found", HasError = true, ErrorType = StudentManagementResponseType.NationalityId
                }));
            }
            else if (updateStudent.MotherTongueId.HasValue && !await _iMSDbContext.MotherTongues.AnyAsync(x => x.Id == updateStudent.MotherTongueId.Value && x.InstituteId == loggedInUserInstituteId))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "Mother tongue not found", HasError = true, ErrorType = StudentManagementResponseType.MotherTongueId
                }));
            }
            else if (updateStudent.ReligionId.HasValue && !await _iMSDbContext.Religions.AnyAsync(x => x.Id == updateStudent.ReligionId.Value && x.InstituteId == loggedInUserInstituteId))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "Religion not found", HasError = true, ErrorType = StudentManagementResponseType.ReligionId
                }));
            }
            else if (updateStudent.CasteId.HasValue && !await _iMSDbContext.Castes.AnyAsync(x => x.Id == updateStudent.CasteId.Value && x.InstituteId == loggedInUserInstituteId))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "Caste not found", HasError = true, ErrorType = StudentManagementResponseType.CasteId
                }));
            }
            else if (updateStudent.BloodGroupId.HasValue && !await _iMSDbContext.BloodGroups.AnyAsync(x => x.Id == updateStudent.BloodGroupId.Value && x.InstituteId == loggedInUserInstituteId))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "Blood group not found", HasError = true, ErrorType = StudentManagementResponseType.BloodGroupId
                }));
            }
            else if (updateStudent.PassportIssuedCountryId.HasValue && !await _iMSDbContext.AdministrationCountries.AnyAsync(x => x.Id == updateStudent.PassportIssuedCountryId.Value && x.InstituteId == loggedInUserInstituteId))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "Country group not found", HasError = true, ErrorType = StudentManagementResponseType.PassportIssuedCountryId
                }));
            }
            else if (updateStudent.RelievingClassId.HasValue && !await _iMSDbContext.InstituteClasses.AnyAsync(x => x.Id == updateStudent.RelievingClassId.Value && x.InstituteId == loggedInUserInstituteId))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "Class not found", HasError = true, ErrorType = StudentManagementResponseType.RelievingClassId
                }));
            }
            else if (updateStudent.FamilyRelationOccupationId.HasValue && !await _iMSDbContext.Occupations.AnyAsync(x => x.Id == updateStudent.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 == updateStudent.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 == updateStudent.PresentCityId && x.State.Country.InstituteId == loggedInUserInstituteId))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "City not found", HasError = true, ErrorType = StudentManagementResponseType.PresentCityId
                }));
            }
            else if (CheckIfListOfStudentPriorEducations(updateStudent.StudentPriorEducations))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "Prior educations must have institute name", HasError = true, ErrorType = StudentManagementResponseType.StudentPriorEducations
                }));
            }
            else if (CheckIfListOfStudentDisciplines(updateStudent.StudentDisciplines))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "Student disciplines must have description and subject", HasError = true, ErrorType = StudentManagementResponseType.StudentDisciplines
                }));
            }
            else if (!await CheckIfListOfStudentStudentSportIdAsync(updateStudent.StudentSports, loggedInUserInstituteId))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "Sport not found", HasError = true, ErrorType = StudentManagementResponseType.StudentSportId
                }));
            }
            else if (!await CheckIfListOfStudentStudentLevelIdAsync(updateStudent.StudentSports, loggedInUserInstituteId))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "Level not found", HasError = true, ErrorType = StudentManagementResponseType.StudentLevelId
                }));
            }
            else if (CheckIfListOfStudentAwardAwardName(updateStudent.StudentAwards))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "Student awards must have name", HasError = true, ErrorType = StudentManagementResponseType.StudentAwardName
                }));
            }
            else if (CheckIfListOfStudentAwardInstituteName(updateStudent.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 == updateStudent.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 == updateStudent.SectionId && x.InstituteId == loggedInUserInstituteId))
            {
                return(Ok(new StudentManagementResponse()
                {
                    Message = "Section not found", HasError = true, ErrorType = StudentManagementResponseType.SectionId
                }));
            }
            else
            {
                return(Ok(await _studentManagementRepository.UpdateStudentAsync(updateStudent, loggedInUser)));
            }
        }