コード例 #1
0
        //
        // GET: /Course/Details/5

        public ViewResult Details(int id)
        {
            Course course = db.Courses.Find(id);

            return(View(course));
        }
コード例 #2
0
        public ActionResult Edit(Course course)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        string          ConnectionString = "Server = localhost; Port = 3306; Database = contosouniversity; Uid = root; Pwd = 1234";
                        MySqlDataReader read;
                        using (MySqlConnection conn = new MySqlConnection(ConnectionString))
                        {
                            conn.Open();

                            using (MySqlCommand cmd = new MySqlCommand("EditCourse", conn))
                            {
                                cmd.CommandType = System.Data.CommandType.StoredProcedure;

                                cmd.Parameters.AddWithValue("@_Tittle", course.Tittle);
                                cmd.Parameters.AddWithValue("@_Credits", course.Credits);
                                cmd.Parameters.AddWithValue("@_Departament", course.DepartamentId);
                                cmd.Parameters.AddWithValue("@_Id", course.Id);

                                read = cmd.ExecuteReader();
                            }
                            while (read.Read())
                            {
                                course.Tittle        = read["Tittle"].ToString();
                                course.Credits       = Convert.ToInt32(read["Credits"]);
                                course.DepartamentId = Convert.ToInt32(read["DepartamentId"]);
                            }
                            if (read == null)
                            {
                                return(HttpNotFound());
                            }

                            conn.Close();
                        }
                    }//End secod try
                    catch (DbEntityValidationException e)
                    {
                        foreach (var eve in e.EntityValidationErrors)
                        {
                            Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors: ",
                                              eve.Entry.Entity.GetType().Name, eve.Entry.State);

                            foreach (var ve in eve.ValidationErrors)
                            {
                                Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                                  ve.PropertyName, ve.ErrorMessage);
                            } //End second foreach
                        }     //End Firts foreach
                        throw;
                    }         //End firts Catch
                }             //End If

                return(RedirectToAction("Index"));
            }//End Try
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(View());
            }
        }//Fin Method
コード例 #3
0
        //
        // GET: /Course/Delete/5

        public ActionResult Delete(int id)
        {
            Course course = db.Courses.Find(id);

            return(View(course));
        }