Beispiel #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!" }));
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #5
0
        public static List <GroupResponse> GetGroupByRoomId(RoomDBContext context, int roomId)
        {
            var groups    = RoomDAO.GetGroupByRoom(context, roomId);
            var responses = new List <GroupResponse>();

            foreach (var group in groups)
            {
                var response = 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()
                };
                responses.Add(response);
            }
            return(responses);
        }
Beispiel #6
0
        public static GroupResponse CreateGroup(RoomDBContext context, HttpRequest request)
        {
            var now = DateTime.Now;

            Room room = new Room
            {
                Subject    = request.Form["name"],
                CreatorId  = request.Form["teacherId"],
                MainRoomId = Convert.ToInt32(request.Form["roomId"]),
                Group      = true,
                StartDate  = now,
                EndDate    = now
            };

            var result = RoomDAO.Create(context, room);
            var group  = RoomDAO.GetLastRoom(context);

            var listUserIds   = JsonConvert.DeserializeObject <List <string> >(request.Form["userIds"]);
            var roomUserLinks = listUserIds.Select(userId => new RoomUserLink
            {
                RoomId = group.RoomId,
                UserId = userId
            }).ToList();
            var existLink = context.RoomUserLink.Where(link => link.RoomId == group.RoomId).ToList();

            if (existLink.Count != 0)
            {
                roomUserLinks = roomUserLinks.Where(link => !existLink.Any(x => x.UserId == link.UserId)).ToList();
            }
            result = RoomUserLinkDAO.Create(context, roomUserLinks);

            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()
            });
        }
Beispiel #7
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);
        }