Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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!" }));
        }
Exemplo n.º 3
0
        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);
        }