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 JoinRoom([Bind] RoomModel obj) { //check room id if (!_roomDB.isRoomExists(obj.room_name)) { TempData["msg"] = "Room does not exists."; return(View("~/Views/Main/Index.cshtml")); } else { //check password if (_roomDB.validateRoomWithPass(obj.room_name, obj.room_password)) //if same pass { var roomId = _roomDB.GetRoomId(obj.room_name); _userDB.updateUserLastRoom(HttpContext.Session.GetString("userEmail"), obj.room_name); _roomUserDB.insertRoomUsers(roomId, HttpContext.Session.GetString("userEmail")); HttpContext.Session.SetString("roomId", roomId); HttpContext.Session.SetString("roomName", obj.room_name); HttpContext.Session.SetString("roomPass", _roomDB.getRoomPassword(obj.room_id)); logActivity("Join room", obj.room_name); return(RedirectToAction("Index", "Room")); } else { TempData["msg"] = "Invalid Pass."; return(View("~/Views/Main/Index.cshtml")); } } }