示例#1
0
 public ActionResult Delete(vStudent theStudent)
 {
     using (var db = new AdvWebDevProjectEntities())
     {
         if (ModelState.IsValid)
         {
             try
             {
                 db.Entry(theStudent).State = System.Data.Entity.EntityState.Deleted;
                 db.vStudents.Remove(theStudent);
                 db.SaveChanges();
                 return(RedirectToAction("Index"));
             }
             catch (Exception ex)
             {
                 ModelState.AddModelError("",
                                          $"An error occurred: {ex.Message}");
             }
         }
         else
         {
             ModelState.AddModelError("", "Model state was invalid.");
         }
     }
     return(View(theStudent));
 }
示例#2
0
        // GET: Student/Edit/5
        public ActionResult Edit(int id)
        {
            var      db         = new AdvWebDevProjectEntities();
            vStudent theStudent = db.vStudents.Find(id);

            if (theStudent == null)
            {
                return(HttpNotFound());
            }
            return(View(theStudent));
        }
示例#3
0
 public ActionResult Create(vStudent theStudent)
 {
     using (var db = new AdvWebDevProjectEntities())
     {
         try
         {
             if (ModelState.IsValid)
             {
                 db.vStudents.Add(theStudent);
                 db.SaveChanges();
                 return(RedirectToAction("Index"));
             }
         }
         catch (Exception ex)
         {
             ModelState.AddModelError("",
                                      $"An error occurred: {ex.Message}");
         }
     }
     return(View(theStudent));
 }
示例#4
0
 public ActionResult Edit(vStudent theStudent)
 {
     using (var db = new AdvWebDevProjectEntities())
     {
         if (ModelState.IsValid) //verifies that the data submitted in the form can be used to modify (edit or update)
         {
             if (TryUpdateModel(theStudent))
             {
                 try
                 {
                     db.SaveChanges();
                     return(RedirectToAction("Index"));
                 }
                 catch (Exception ex)
                 {
                     ModelState.AddModelError("",
                                              $"An error occurred: {ex.Message}");
                 }
             }
         }
     }
     return(View(theStudent));
 }
示例#5
0
        // GET: Student
        public ActionResult Index()
        {
            var db = new AdvWebDevProjectEntities();

            return(View(db.vStudents.ToList()));
        }