Esempio n. 1
0
        public ActionResult Index()
        {
            if (!IsAdmin)
            {
                Log.Info("Intent d'acces a pagina principal d'Admin sense estar loggejat. Redirigint a Login...");
                return RedirectToAction("Login");
            }

            Log.Info("Pagina principal d'Admin (Moderar documents)");
            ViewBag.Action = "Moderar";

            using (var connection = new MySqlConnection(ConnectionString))
            {
                connection.Open();
                var cmd = new MySqlCommand("SELECT Id, Nom FROM Carreres ORDER BY Id ASC", connection);
                MySqlDataReader reader = cmd.ExecuteReader();

                var r = new List<Carrera>();

                while (reader.Read())
                {
                    var c = new Carrera()
                    {
                        Id = reader.GetInt32(reader.GetOrdinal("Id")),
                        Nom = reader.GetString(reader.GetOrdinal("Nom"))
                    };

                    r.Add(c);
                }

                return View(r);
            }
        }
Esempio n. 2
0
        public ActionResult LlistatCarreres(int IdFacultat)
        {
            using (MySqlConnection connection = new MySqlConnection(ConnectionString))
            {
                connection.Open();
                MySqlCommand command = new MySqlCommand("SELECT Id, Nom FROM Carreres WHERE IdFacultat = @IdFacultat ORDER BY Nom ASC", connection);
                command.Parameters.AddWithValue("@IdFacultat", IdFacultat);

                MySqlDataReader reader = command.ExecuteReader();

                List<Carrera> resultat = new List<Carrera>();

                while (reader.Read())
                {
                    Carrera c = new Carrera();

                    c.Id = reader.GetInt32(reader.GetOrdinal("Id"));
                    c.Nom = reader.GetString(reader.GetOrdinal("Nom"));

                    resultat.Add(c);
                }

                return Json(resultat, JsonRequestBehavior.AllowGet);
            }
        }