public async Task PopulateWithClassRooms() { string filePath = "./classRooms.json"; using (StreamReader sr = new StreamReader(filePath)) { string json = await sr.ReadToEndAsync(); JObject parseJson = JObject.Parse(json); JArray classRooms = (JArray)parseJson["Classrooms"]; List <ClassRoom> rooms = classRooms.ToObject <List <ClassRoom> >(); for (int i = 0; i < rooms.Count; i += 1) { ClassRoom room = new ClassRoom( rooms[i].OriginX, rooms[i].OriginY, rooms[i].EndPositionX, rooms[i].EndPositionY, rooms[i].Name ); ClassRooms.Add(room); } } }
/// <summary> /// /// </summary> /// <param name="classRoom"></param> /// <returns></returns> public async Task <bool> CreateAsync(ClassRoom classRoom) { if (classRoom == null) { throw new ArgumentNullException(nameof(classRoom)); } ClassRooms.Add(classRoom); try { await SaveChanges(); } catch (DbUpdateConcurrencyException) { return(false); } return(true); }
internal void addClassroom(ClassRoom classRoom) { ClassRooms.Add(classRoom); }