Example #1
0
 public IActionResult JoinRoom(string roomId, string roomPass)
 {
     if (string.IsNullOrEmpty(HttpContext.Session.GetString("userEmail")))
     {
         TempData["msg"] = "Please login to proceed.";
         return(RedirectToAction("Index", "Login"));
     }
     else
     {
         var roomName = _roomDB.GetRoom(roomId);
         if (!string.IsNullOrEmpty(roomName))
         {
             if (roomPass.Equals(_roomDB.getRoomPassword(roomId)))
             {
                 HttpContext.Session.SetString("roomId", roomId);
                 HttpContext.Session.SetString("roomName", roomName);
                 HttpContext.Session.SetString("roomPass", _roomDB.getRoomPassword(roomId));
                 _userDB.updateUserLastRoom(HttpContext.Session.GetString("userEmail"), roomName);
                 _roomUserDB.insertRoomUsers(roomId, HttpContext.Session.GetString("userEmail"));
                 logActivity("Join room", roomName);
                 return(RedirectToAction("Index", "Room"));
             }
             else
             {
                 TempData["msg"] = "Invalid room password.";
                 return(RedirectToAction("Index", "Main"));
             }
         }
         else
         {
             TempData["msg"] = "Invalid room id.";
             return(RedirectToAction("Index", "Main"));
         }
     }
 }
        public IActionResult CreateRoom([Bind] RoomModel obj)
        {
            string roomName = obj.room_name.ToString();

            if (_roomDB.isRoomExists(roomName))
            {
                TempData["msg"] = "Room Name Existed.";
                return(View("~/Views/Main/Index.cshtml"));
            }
            else
            {
                obj.room_id    = Guid.NewGuid().ToString("N").Substring(0, 12); //auto generate id
                obj.user_email = HttpContext.Session.GetString("userEmail");
                _roomDB.createRoom(obj);
                _roomUserDB.insertRoomUsers(obj.room_id, obj.user_email);
                HttpContext.Session.SetString("roomId", obj.room_id);
                HttpContext.Session.SetString("roomName", obj.room_name);
                HttpContext.Session.SetString("roomPass", _roomDB.getRoomPassword(obj.room_id));
                logActivity("Create room", obj.room_name);
                return(RedirectToAction("Index", "Room"));
            }
        }