public async void GetByRoomId() { var schedules = new List <Timetable>(); //Arrange schedules.Add(new Timetable() { Id = 1, RoomId = 1, Date = DateTime.Now.Date, StartTime = TimeSpan.Parse("8:00"), EndTime = TimeSpan.Parse("10:00"), }); schedules.Add(new Timetable() { Id = 2, RoomId = 1, Date = DateTime.Now.Date, StartTime = TimeSpan.Parse("8:00"), EndTime = TimeSpan.Parse("10:00"), }); schedules.Add(new Timetable() { Id = 3, RoomId = 1, Date = DateTime.Now.Date, StartTime = TimeSpan.Parse("8:00"), EndTime = TimeSpan.Parse("10:00"), }); // Act var result = await TimetableDAO.Create(roomContext, schedules); // Assert Assert.Equal((int)HttpStatusCode.OK, ((ObjectResult)result).StatusCode); var resultList = TimetableDAO.GetByRoomId(roomContext, 1); Assert.Equal(3, resultList.Count); }
public async static Task <IActionResult> DeleteRoom(RoomDBContext context, int roomId, IWebHostEnvironment env) { var room = RoomDAO.Get(context, roomId); if (room != null) { var roomUserLinks = RoomUserLinkDAO.GetRoomLink(context, roomId); var roomChats = RoomChatDAO.GetChatByRoomId(context, roomId); var roomTimetables = TimetableDAO.GetByRoomId(context, roomId); var groups = RoomDAO.GetGroupByRoom(context, roomId); var result = await RoomUserLinkDAO.Delete(context, roomUserLinks); result = await RoomChatDAO.DeleteRoomChat(context, roomChats); result = await TimetableDAO.DeleteTimeTable(context, roomTimetables); foreach (var group in groups) { result = await DeleteRoom(context, group.RoomId, env); } var path = Path.Combine(env.ContentRootPath, $"Files/{roomId}"); if (Directory.Exists(path)) { Directory.Delete(path, true); } result = await RoomDAO.Delete(context, room); return(result); } return(new BadRequestObjectResult(new { message = "Class now exist!" })); }
public async Task <IActionResult> GetTimeTable(TimetableRequest model) { var appUser = await _userManager.FindByIdAsync(_userAccessor.GetCurrentUserId()); var userLinks = (from userRooms in _roomDbContext.RoomUserLink where userRooms.UserId == appUser.Id select userRooms.RoomId).ToList(); //Toàn bộ room người dùng này tham gia vào var rooms = new List <Room>(); foreach (var roomId in userLinks) { //get room var room = await _roomDbContext.Room.Where(r => r.RoomId == roomId && !r.Group).FirstOrDefaultAsync(); if (room != null) { rooms.Add(room); } } var resultList = new List <TimetableResponse>(); foreach (var room in rooms) { var roomTimetables = TimetableDAO.GetByRoomId(_roomDbContext, room.RoomId); foreach (var timetable in roomTimetables) { if (timetable.Date >= model.StartDate && timetable.Date <= model.EndDate) { resultList.Add(new TimetableResponse { RoomId = room.RoomId.ToString(), EventType = 0, Title = room.Subject + "-" + room.ClassName, TeacherId = room.CreatorId, StartDate = timetable.Date.ToString("yyyy-MM-dd") + "T" + timetable.StartTime, EndDate = timetable.Date.ToString("yyyy-MM-dd") + "T" + timetable.EndTime, }); } } } return(new OkObjectResult(resultList)); }
public async Task <IActionResult> GetAttendanceByRoom(int id) { var timetables = TimetableDAO.GetByRoomId(_roomContext, id); var attendanceList = new List <AttendanceTeacherResponse>(); foreach (var timetable in timetables) { var room = await _roomContext.Room.FirstOrDefaultAsync(x => x.RoomId == timetable.RoomId); if (room == null) { break; } var listStudent = new List <AttendanceStudent>(); var listStudentId = await(from attendances in _userContext.AttendanceReports where attendances.TimeTableId == timetable.Id select new AttendanceStudent { Id = attendances.UserId, Status = attendances.Status }).ToListAsync(); foreach (var student in listStudentId) { student.Id = _userManager.FindByIdAsync(student.Id).Result.UserName; } listStudent.AddRange(listStudentId); attendanceList.Add(new AttendanceTeacherResponse { Id = timetable.Id.ToString(), Class = room.ClassName, Subject = room.Subject, Date = String.Format("{0:yyyy-MM-dd}", timetable.Date), StartTime = timetable.StartTime.ToString(@"hh\:mm"), EndTime = timetable.EndTime.ToString(@"hh\:mm"), Teacher = _userManager.FindByIdAsync(room.CreatorId).Result.UserName, Students = listStudent }); } return(new OkObjectResult(attendanceList)); }