Example #1
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!" }));
        }
Example #2
0
        public static GroupResponse GroupUpdate(RoomDBContext context, HttpRequest request)
        {
            var groupId     = Convert.ToInt32(request.Form["groupId"]);
            var listUserIds = (IEnumerable <string>)JsonConvert.DeserializeObject <List <string> >(request.Form["userIds"]);
            var existLinks  = (IEnumerable <string>)context.RoomUserLink.Where(link => link.RoomId == groupId).Select(link => link.UserId).ToList();

            var group = RoomDAO.Get(context, groupId);

            if (group != null)
            {
                var deleteUserIds = existLinks.Except(listUserIds).ToList();
                var addUserIds    = listUserIds.Except(existLinks).ToList();

                var deleteLinks = deleteUserIds.Select(item => RoomUserLinkDAO.GetRoomUserLink(context, groupId, item)).ToList();

                var addLinks = addUserIds.Select(item => new RoomUserLink
                {
                    UserId = item,
                    RoomId = group.RoomId
                }).ToList();

                var result = RoomUserLinkDAO.Create(context, addLinks);
                result = RoomUserLinkDAO.Delete(context, deleteLinks);

                return(new GroupResponse
                {
                    GroupId = group.RoomId,
                    Name = group.Subject,
                    UserIds = RoomUserLinkDAO.GetRoomLink(context, group.RoomId).Select(item => item.UserId).ToList(),
                    StartTime = group.StartDate.ToUniversalTime(),
                    EndTime = group.EndDate.ToUniversalTime()
                });
            }
            return(null);
        }
Example #3
0
        public async void DeleteListLinkSuccessfully()
        {
            //Arrange
            var links = new List <RoomUserLink>();

            links.Add(new RoomUserLink()
            {
                RoomId = 1, RoomUserId = 1, UserId = "testUser"
            });
            links.Add(new RoomUserLink()
            {
                RoomId = 1, RoomUserId = 2, UserId = "testUser1"
            });
            links.Add(new RoomUserLink()
            {
                RoomId = 1, RoomUserId = 3, UserId = "testUser2"
            });

            var result = await RoomUserLinkDAO.Create(roomContext, links);

            Assert.Equal((int)HttpStatusCode.OK, ((ObjectResult)result).StatusCode);

            var resultLinks = RoomUserLinkDAO.GetRoomLink(roomContext, 1);

            Assert.Equal(3, resultLinks.Count);

            result = await RoomUserLinkDAO.Delete(roomContext, links);

            Assert.Equal((int)HttpStatusCode.OK, ((ObjectResult)result).StatusCode);

            resultLinks = RoomUserLinkDAO.GetRoomLink(roomContext, 1);

            Assert.Empty(resultLinks);
        }
Example #4
0
        public async void DeleteLinkFail(int roomId)
        {
            //Arrange
            var links = new List <RoomUserLink>();

            links.Add(new RoomUserLink()
            {
                RoomId = roomId, RoomUserId = 1, UserId = "testUser"
            });
            links.Add(new RoomUserLink()
            {
                RoomId = roomId, RoomUserId = 2, UserId = "testUser1"
            });
            links.Add(new RoomUserLink()
            {
                RoomId = roomId, RoomUserId = 3, UserId = "testUser2"
            });

            var result = await RoomUserLinkDAO.Create(roomContext, links);

            Assert.Equal((int)HttpStatusCode.OK, ((ObjectResult)result).StatusCode);

            var resultLinks = RoomUserLinkDAO.GetRoomLink(roomContext, roomId);

            Assert.Equal(3, resultLinks.Count);

            result = await RoomUserLinkDAO.Delete(roomContext, new RoomUserLink()
            {
                RoomId = roomId, RoomUserId = 1, UserId = "testUser12"
            });

            Assert.Equal((int)HttpStatusCode.InternalServerError, ((ObjectResult)result).StatusCode);
        }
Example #5
0
        public static async Task <IActionResult> KickFromRoom(RoomDBContext context, int roomId, string userId)
        {
            var roomUserLink = RoomUserLinkDAO.GetRoomUserLink(context, roomId, userId);

            if (roomUserLink != null)
            {
                return(await RoomUserLinkDAO.Delete(context, roomUserLink));
            }
            else
            {
                return(new ObjectResult(new { type = 1, message = "user not in the room" })
                {
                    StatusCode = 200,
                });
            }
        }
Example #6
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);
        }