コード例 #1
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);
        }
コード例 #2
0
        public async void GetRoomUserLink()
        {
            //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 resultLink = RoomUserLinkDAO.GetRoomUserLink(roomContext, 1, "testUser");

            Assert.Equal(1, resultLink.RoomId);
            Assert.Equal(1, resultLink.RoomUserId);
            Assert.Equal("testUser", resultLink.UserId);

            resultLink = RoomUserLinkDAO.GetRoomUserLink(roomContext, 1, "testUser0");

            Assert.Null(resultLink);
        }
コード例 #3
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,
                });
            }
        }