public async Task RemoveDistrict(int districtId) { VerifyPermission(Permission.ManageSchools); var district = await _schoolDistrictRepository.GetByIdAsync(districtId); if (district.SiteId != GetCurrentSiteId()) { throw new GraException($"Permission denied - district belongs to site id {district.SiteId}"); } var schools = await _schoolRepository.GetAllAsync(GetCurrentSiteId(), districtId); if (schools.Count > 0) { throw new GraException($"Could not delete district - there are {schools.Count} associated schools"); } await _schoolDistrictRepository.RemoveSaveAsync(GetActiveUserId(), districtId); }
public async Task <EnteredSchool> AddEnteredSchool(string schoolName, int districtId) { var district = await _schoolDistrictRepository.GetByIdAsync(districtId); if (district == null) { throw new GraException("Please select a school district."); } var enteredSchool = new EnteredSchool { SiteId = district.SiteId, Name = schoolName, SchoolDistrictId = districtId }; return(await _enteredSchoolRepository.AddSaveNoAuditAsync(enteredSchool)); }
public async Task <School> AddSchool(string schoolName, int districtId, int?typeId) { VerifyPermission(Permission.ManageSchools); var district = await _schoolDistrictRepository.GetByIdAsync(districtId); if (district.IsCharter || district.IsPrivate) { typeId = null; } else if (typeId.HasValue == false) { throw new GraException("No school type selected."); } return(await _schoolRepository.AddSaveAsync(GetClaimId(ClaimType.UserId), new School { SiteId = GetCurrentSiteId(), Name = schoolName, SchoolDistrictId = districtId, SchoolTypeId = typeId })); }