示例#1
0
        public ActionResult Create([Bind(Include = "ClassId,ClassName,ClassDate,ClassDescription")] Class @class)
        {
            if (ModelState.IsValid)
            {
                db.Classes.Add(@class);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(@class));
        }
示例#2
0
        public ActionResult Create([Bind(Include = "StudentId,StudentName,StudentEmail,StudentLogin,StudentPassword")] Student student)
        {
            if (ModelState.IsValid)
            {
                db.Students.Add(student);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(student));
        }
示例#3
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));
 }
示例#4
0
 public ActionResult Create(vClass theClass)
 {
     try
     {
         if (ModelState.IsValid)
         {
             db.vClasses.Add(theClass);
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     catch (Exception)
     {
         ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
     }
     return(View(theClass));
 }
示例#5
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));
 }
示例#6
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));
 }