public ActionResult Create(Student student)
        {
            try
            {
                if (ModelState.IsValid)

                {
                    db.Students.Add(student);
                    db.SaveChanges();
                    return RedirectToAction("Index");
                }
                return View(student);
            }
            catch
            {
                return View();
            }
        }
        public ActionResult Delete(int? id,Student st)
        {
            try
            {
                Student student=new Student();
                if (ModelState.IsValid)
                {
                    if (id == null)
                        return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
                     student = db.Students.Find(id);
                    if (student == null)
                        return HttpNotFound();

                    db.Students.Remove(student);
                    db.SaveChanges();
                    return RedirectToAction("Index");
                }
                return View(student);
            }
            catch
            {
                return View();
            }
        }
示例#3
0
        public static void SaveStudent(Student newStudent)
        {
            ArrayOfStudent students = XmlFileUtil.Deserialize();
            Student oldStudent = students.studentsList.Find(delegate(Student s)
            {
                return (s.StudentID == newStudent.StudentID);
            });
            students.studentsList.Remove(oldStudent);
            students.studentsList.Add(newStudent);

            XmlSerializer serializer = new XmlSerializer(typeof(ArrayOfStudent));

            using (StreamWriter writer = new StreamWriter(xmlpath))
            {
                serializer.Serialize(writer, students);
            }
        }
 public ActionResult Edit(int id, Student student)
 {
     try
     {
         if (ModelState.IsValid)
         {
             db.Entry(student).State = System.Data.Entity.EntityState.Modified;
             db.SaveChanges();
             return RedirectToAction("Index");
         }
         return View(student);
     }
     catch
     {
         return View();
     }
 }
 partial void DeleteStudent(Student instance);
 partial void UpdateStudent(Student instance);
 partial void InsertStudent(Student instance);