public async void ScheduleDeleteList() { 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); schedules.RemoveAt(2); result = await TimetableDAO.DeleteTimeTable(roomContext, schedules); Assert.Equal((int)HttpStatusCode.OK, ((ObjectResult)result).StatusCode); var resultSchedule = TimetableDAO.GetById(roomContext, 1); Assert.Null(resultSchedule); resultSchedule = TimetableDAO.GetById(roomContext, 3); Assert.NotNull(resultSchedule); }
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!" })); }