public ActionResult PuzzleList()
        {
            Session["Class"]      = Session["Class"];
            Session["LecID"]      = Session["LecID"];
            TempData["Class"]     = TempData["Class"];
            TempData["StartDate"] = TempData["StartDate"];
            TempData["EndDate"]   = TempData["EndDate"];
            String LecID = Session["LecID"].ToString();

            LecID = LecID.ToUpper();

            string connectionString = @"Data Source=msi;Initial Catalog=SEFASSIGNMENT;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";

            System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(connectionString);

            sqlConnection.Open();

            System.Data.SqlClient.SqlCommand sqlCommand = new System.Data.SqlClient.SqlCommand("SELECT Puzzle_ID FROM [SEFASSIGNMENT].[dbo].[Puzzle] WHERE LEC_ID='" + LecID + "'");
            sqlCommand.Connection = sqlConnection;
            SqlDataReader myreader     = sqlCommand.ExecuteReader();
            List <String> PuzzleIDList = new List <String>();

            while (myreader.Read())
            {
                PuzzleIDList.Add(myreader[0].ToString());
            }

            myreader.Close();

            sqlCommand            = new System.Data.SqlClient.SqlCommand("SELECT Puzzle_Name FROM [SEFASSIGNMENT].[dbo].[Puzzle] WHERE LEC_ID='" + LecID + "'");
            sqlCommand.Connection = sqlConnection;

            SqlDataReader newmyreader    = sqlCommand.ExecuteReader();
            List <String> PuzzleNameList = new List <String>();

            while (newmyreader.Read())
            {
                PuzzleNameList.Add(newmyreader[0].ToString());
            }
            newmyreader.Close();

            List <PuzzleList> Puzzle = new List <PuzzleList>();

            for (int i = 0; i < PuzzleIDList.Count; i++)
            {
                Puzzle.Add(new PuzzleList()
                {
                    PuzzleID = PuzzleIDList[i], PuzzleName = PuzzleNameList[i], IsCheck = false
                });
            }

            PuzzlesList CL = new PuzzlesList();

            CL.ViewPuzzleList = Puzzle;
            return(View(CL));
        }
        public ActionResult PuzzleList(PuzzlesList cl, string action)
        {
            Session["Class"] = Session["Class"];
            if (action.Equals("home"))
            {
                return(RedirectToAction("HomeLec", "HomeLec"));
            }

            else if (action.Equals("back"))
            {
                return(RedirectToAction("ManageClass"));
            }

            else if (action.Equals("genattendane"))
            {
                StringBuilder sb      = new StringBuilder();
                int           counter = 0;
                foreach (var item in cl.ViewPuzzleList)
                {
                    if (item.IsCheck)
                    {
                        sb.Append(item.PuzzleID);
                        counter++;
                    }
                }

                String content = sb.ToString();

                if (counter > 1)
                {
                    TempData["AlertMessage"] = "Please only insert one boxes! Returning to main menu.";
                    return(RedirectToAction("ManageClass"));
                }

                TempData["Puzzle"]    = content;
                TempData["Class"]     = TempData["Class"];
                Session["Class"]      = Session["Class"];
                TempData["StartDate"] = TempData["StartDate"];
                TempData["EndDate"]   = TempData["EndDate"];
                return(RedirectToAction("AttendanceList"));
            }

            return(View());
        }
        public ActionResult PuzzleStu(PuzzlesList cl, string action)
        {
            Session["StuID"]   = Session["StuID"];
            Session["ClassID"] = Session["ClassID"];
            Session["LecID"]   = Session["LecID"];

            if (action.Equals("home"))
            {
                return(RedirectToAction("HomeStu"));
            }

            else if (action.Equals("back"))
            {
                return(RedirectToAction("HomeStu"));
            }

            else if (action.Equals("play"))
            {
                StringBuilder sb      = new StringBuilder();
                int           counter = 0;
                foreach (var item in cl.ViewPuzzleList)
                {
                    if (item.IsCheck)
                    {
                        sb.Append(item.PuzzleID);
                        counter++;
                    }
                }

                String content = sb.ToString();

                if (counter > 1)
                {
                    TempData["AlertMessage"] = "Please only insert one boxes! Returning to main menu.";
                    return(RedirectToAction("HomeStu"));
                }

                Session["PuzzleID"] = content;
                return(RedirectToAction("PlayPuzzle"));
            }

            return(View());
        }
Exemple #4
0
        public ActionResult RemovePuz(PuzzlesList cl, string action)
        {
            Session["LecID"] = Session["LecID"];

            if (action.Equals("home"))
            {
                return(RedirectToAction("HomeLec", "HomeLec"));
            }

            else if (action.Equals("back"))
            {
                return(RedirectToAction("ManagePuzzleLec"));
            }

            else if (action.Equals("remove"))
            {
                List <String> removelistid   = new List <String>();
                List <String> removelistname = new List <string>();
                int           counter        = 0;
                foreach (var item in cl.ViewPuzzleList)
                {
                    if (item.IsCheck)
                    {
                        removelistname.Add(item.PuzzleName);
                        removelistid.Add(item.PuzzleID);
                        counter++;
                    }
                }

                if (counter == 0)
                {
                    TempData["AlertMessage"] = "You selected none puzzle to be removed!";
                    return(RedirectToAction("HomeLec"));
                }

                TempData["RemovalPuzzleID"]   = removelistid;
                TempData["RemovalPuzzleName"] = removelistname;
                return(RedirectToAction("ConfirmRemove"));
            }

            return(View());
        }