private void PrepareSchoolData(IServiceLocatorSchool schoolL, User user, int?schoolYearId, int[] acdaIds , out Data.School.Model.SchoolYear schoolYear, out SchoolUser schoolUser) { if (schoolYearId.HasValue) { schoolYear = schoolL.SchoolYearService.GetSchoolYearById(schoolYearId.Value); } else { var schoolYears = schoolL.SchoolYearService.GetDescSortedYearsByIds(acdaIds.ToList()); if (schoolYears.Count == 0) { throw new ChalkableException("Current user doesn't have access to acada sessions in current school"); } schoolYear = (schoolYears.FirstOrDefault(x => (x.EndDate >= DateTime.Now && x.StartDate <= DateTime.Now)) ?? schoolYears.FirstOrDefault(x => x.EndDate <= DateTime.Now)) ?? schoolYears.Last(); } var schoolId = schoolYear.SchoolRef; schoolUser = user.SchoolUsers.FirstOrDefault(x => x.School.LocalId == schoolId); if (schoolUser == null) { throw new ChalkableException($"There is no school in current District with such schoolYearId : {schoolYear.Id}"); } }
private static UserContext CreateUserContext(SchoolUser schoolUser, Data.School.Model.SchoolYear schoolYear = null) { int roleId; int personId = schoolUser.User.IsDemoUser ? DemoPersonService.GetPersonDataForLogin(schoolUser.User, out roleId) : PersonDataAccess.GetPersonDataForLogin(schoolUser.User.District.ServerUrl, schoolUser.DistrictRef, schoolUser.UserRef, out roleId); var user = schoolUser.User; var school = schoolUser.School; var role = CoreRoles.GetById(roleId); Guid?developerId = null; if (schoolUser.User.IsDemoUser) { var developer = CreateMasterSysAdmin().UserService.GetById(user.District.Id); if (developer != null) { developerId = developer.Id; } } return(new UserContext(user, role, user.District, school, developerId, personId, null, schoolYear)); }
public static IServiceLocatorSchool CreateSchoolLocator(SchoolUser schoolUser, Data.School.Model.SchoolYear schoolYear = null) { var context = CreateUserContext(schoolUser, schoolYear); return(CreateSchoolLocator(context)); }