public ViewSchoolPage() { InitializeComponent(); GridLayout.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) }); GridLayout.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) }); SchoolAdminModel schoolAdmin = new SchoolAdminModel(); List <SchoolAdminModel> admins = new SchoolAdminsService().GetAll(); List <TeacherModel> teachers = new List <TeacherModel>(); string email = "" + Application.Current.Properties["Email"]; foreach (var admin in admins) { UserModel user = new UsersService().GetById(admin.UserId); if (user.Email.Equals(email)) { schoolAdmin = admin; break; } } Parallel.ForEach(schoolAdmin.TeachersId, (teacher) => { teachers.Add(new TeachersService().GetById(teacher)); }); Parallel.For(0, teachers.Count, (i) => { UserModel user = new UsersService().GetById(teachers[i].UserId); Label fullNameLabel = new Label { Text = user.FullName }; Label emaiLabel = new Label { Text = "" + user.Email }; // GridLayout.RowDefinitions.Add(new RowDefinition{Height = new GridLength(1,GridUnitType.Auto)}); GridLayout.Children.Add(fullNameLabel, 0, i); GridLayout.Children.Add(emaiLabel, 1, i); }); /* foreach (var teacher in schoolAdmin.TeachersId) * { * teachers.Add(new TeachersService().GetById(teacher)); * * } * * for (int i = 0; i < teachers.Count; i++) * { * UserModel user = new UsersService().GetById(teachers[i].UserId); * Label fullNameLabel = new Label { Text = user.FullName }; * Label emaiLabel = new Label { Text = "" + user.Email }; * // GridLayout.RowDefinitions.Add(new RowDefinition{Height = new GridLength(1,GridUnitType.Auto)}); * GridLayout.Children.Add(fullNameLabel,0,i); * GridLayout.Children.Add(emaiLabel,1,i); * } */ //Application.Current.Properties["Email"]; }
public SchoolAdminModel GetById(string id) { try { var client = new RestClient(); var request = new RestRequest(url + id, Method.GET); request.RequestFormat = DataFormat.Json; request.AddHeader("Content-Type", "application/json"); IRestResponse <SchoolAdminModel> response = client.Execute <SchoolAdminModel>(request); SchoolAdminModel schoolAdmin = response.Data; return(schoolAdmin); } catch (Exception e) { return(null); } }
public bool Put(string id, SchoolAdminModel SchoolAdmin) { try { var client = new RestClient(); var request = new RestRequest(url + id, Method.PUT); request.RequestFormat = DataFormat.Json; request.AddHeader("Content-Type", "application/json"); request.AddJsonBody(SchoolAdmin); client.Execute(request); return(true); } catch (Exception e) { return(false); } }
public async Task AddSchoolAdmin(SchoolAdminModel schoolAdminModel) { var admin = Mapper.Map <SchoolAdminModel, SchoolAdmin>(schoolAdminModel); var school = Repositories.Schools.GetById(schoolAdminModel.SchoolId); if (school == null) { throw new TargetException("School not found"); } admin.School = school; var account = await _accountService.RegisterSchoolUser(admin); if (account == null) { return; } admin.User = account; admin.Id = account.Id; Repositories.SchoolAdmins.Create(admin); }
public async Task Create([FromBody] SchoolAdminModel schoolAdminModel) { await _schoolAdminService.AddSchoolAdmin(schoolAdminModel); }