예제 #1
0
        public IActionResult Register(User user)
        {
            _db.Users.Add(user);
            _db.SaveChanges();

            Response.Cookies.Append("userId", user.Id, new Microsoft.AspNetCore.Http.CookieOptions()
            {
                Expires = DateTime.Now.AddHours(1)
            });
            return(Redirect("Index"));
        }
예제 #2
0
        public string CreateOrJoinRoom(string roomName, bool isCreate)
        {
            string connectionId = Context.ConnectionId;
            User   user         = GetCurrentUser(connectionId);

            if (user == null)
            {
                return("user is null error");
            }

            Room room = _db.Rooms.Include(s => s.UserRooms).FirstOrDefault(x => x.RoomName.ToLower().Trim() == roomName.ToLower().Trim());

            if (room != null)
            {
                if (isCreate == true)
                {
                    return("roomName has Taken");
                }
                else
                {
                    if (room.UserRooms.Any(x => x.UserId == user.Id && x.RoomId == room.Id) == false)
                    {
                        room.AddUser(user);
                        _db.SaveChanges();
                    }
                    Groups.AddToGroupAsync(connectionId, roomName);
                    return("Joined " + roomName);
                }
            }
            room = new Room {
                RoomName = roomName
            };
            room.AddUser(user);
            _db.Rooms.Add(room);
            _db.SaveChanges();
            Groups.AddToGroupAsync(connectionId, roomName);
            return("Room Created Successfully");
        }