コード例 #1
0
 public ActionResult Create(InstituteCampuses_ newDatas) // This will create new data to data set in model
 {
     try
     {
         ////Made an object variable as collegeInput to model UnversitiesEntities
         using (UniversitiesEntities collegeInput = new UniversitiesEntities())
         {
             //We will add new datas by using .Add()
             collegeInput.InstituteCampuses_.Add(newDatas);
             collegeInput.SaveChanges(); //This will allow to save data that was entered on previous parameter.
         }
         //When we hit the submit botton, it will redirect us to the Index page.
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
コード例 #2
0
 public ActionResult Edit(InstituteCampuses_ newDatas)
 {
     try
     {
         using (UniversitiesEntities collegeEdit = new UniversitiesEntities())
         {
             //Modifying the data
             collegeEdit.Entry(newDatas).State = EntityState.Modified;
             // This will allow to save edited data.
             collegeEdit.SaveChanges();
         }
         //When we hit the submit botton, it will redirect us to the Index page.
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
コード例 #3
0
 public ActionResult Delete(int id, InstituteCampuses_ newDatas)
 {
     try
     {
         using (UniversitiesEntities collegeDelete = new UniversitiesEntities())
         {
             InstituteCampuses_ everyEntry = collegeDelete.InstituteCampuses_.Where(a => a.CollegeID == id).FirstOrDefault();
             //This will remove the entry
             collegeDelete.InstituteCampuses_.Remove(everyEntry);
             // This will save the changes
             collegeDelete.SaveChanges();
         }
         //When we hit the submit botton, it will redirect us to the Index page.
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }