public async void GetChatByRoomId(int roomId) { var chats = new List <RoomChat>(); //Arrange chats.Add(new RoomChat() { Id = 1, RoomId = 1, UserId = "testUser", Date = DateTime.Now, Content = "testChat", Type = 1, }); chats.Add(new RoomChat() { Id = 2, RoomId = 1, UserId = "testUser", Date = DateTime.Now, Content = "testChat", Type = 1, }); chats.Add(new RoomChat() { Id = 3, RoomId = 1, UserId = "testUser", Date = DateTime.Now, Content = "testChat", Type = 1, }); // Act foreach (var chat in chats) { await RoomChatDAO.Create(roomContext, chat); } var result = RoomChatDAO.GetChatByRoomId(roomContext, roomId); if (roomId == 1) { Assert.Equal(3, result.Count); } else { Assert.Empty(result); } }
public async void DeleteChat_FAIL(int roomId) { var now = DateTime.Now; var chats = new List <RoomChat>(); var chats2 = new List <RoomChat>(); //Arrange chats.Add(new RoomChat() { Id = 1, RoomId = roomId, UserId = "testUser", Date = now, Content = "testChat", Type = 1, }); chats.Add(new RoomChat() { Id = 2, RoomId = roomId, UserId = "testUser", Date = now, Content = "testChat", Type = 1, }); chats2.Add(new RoomChat() { Id = 3, RoomId = roomId, UserId = "testUser", Date = now, Content = "testChat", Type = 1, }); // Act foreach (var chat in chats) { await RoomChatDAO.Create(roomContext, chat); } var result = RoomChatDAO.DeleteRoomChat(roomContext, chats2); var resultChat = RoomChatDAO.GetChatByRoomId(roomContext, roomId); Assert.NotEmpty(resultChat); }
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 static Task <IActionResult> ResetGroup(RoomDBContext context, int groupId, IWebHostEnvironment env) { var roomUserLinks = RoomUserLinkDAO.GetRoomLink(context, groupId); var roomChats = RoomChatDAO.GetChatByRoomId(context, groupId); var result = await RoomUserLinkDAO.Delete(context, roomUserLinks); result = await RoomChatDAO.DeleteRoomChat(context, roomChats); var path = Path.Combine(env.ContentRootPath, $"Files/{groupId}"); if (Directory.Exists(path)) { Directory.Delete(path, true); } var group = RoomDAO.Get(context, groupId); var now = DateTime.Now; group.EndDate = now; group.StartDate = now; RoomDAO.UpdateRoom(context, group); return(result); }
public static List <RoomChat> GetChatByRoomId(RoomDBContext context, int roomId) { return(RoomChatDAO.GetChatByRoomId(context, roomId)); }