public static ChatroomRepository GetChatroomRepository() { var repository = new ChatroomRepository(); repository.UnitOfWork = GetUnitOfWork(); return(repository); }
public static ChatroomRepository GetChatroomRepository(IUnitOfWork unitOfWork) { var repository = new ChatroomRepository(); repository.UnitOfWork = unitOfWork; return(repository); }
// 查詢某筆聊天室資料 GET: api/Chatroom/聊天室1 public APIResult Get(string roomName) { var chatroom = db.Chatroom.FirstOrDefault(x => x.ChatroomName == roomName.Trim()); if (chatroom != null) { fooResult.Success = true; fooResult.Message = $""; fooResult.TokenFail = false; fooResult.Payload = chatroom; } else { chatroom = new Chatroom(); chatroom.ChatroomName = roomName; chatroom.ChatroomType = "S"; ChatroomRepository repoChatroom = RepositoryHelper.GetChatroomRepository(); repoChatroom.SaveChanges(chatroom); fooResult.Success = true; fooResult.Message = $""; fooResult.TokenFail = false; fooResult.Payload = chatroom; } return(fooResult); }
//移除聊天室 public void RemoveChatroom(string roomName) { ChatroomRepository repoChatroom = RepositoryHelper.GetChatroomRepository(); Chatroom chatroom = repoChatroom.Find(roomName); if (chatroom != null) { repoChatroom.RemoveRoom(chatroom); } }
public ChatroomRepositoryTest() { var options = new DbContextOptionsBuilder <FlyItContext>() .UseInMemoryDatabase(databaseName: "FlyIt-Chatroom") .Options; flyItContext = new FlyItContext(options); chatroomRepsitory = new ChatroomRepository(flyItContext); }