// Creating an option to edit the data set //This will run as GET: CollegeList/Edit/1 in mainpage public ActionResult Edit(int id) { using (UniversitiesEntities collegeEdit = new UniversitiesEntities()) { return(View(collegeEdit.InstituteCampuses_.Where(a => a.CollegeID == id).FirstOrDefault())); } }
//This is to display detail of data based onid. //This is to GET: CollegeList/Details/5 public ActionResult Details(int id) { //Made an object variable as collegeDetails to model UnversitiesEntities using (UniversitiesEntities collegeDetails = new UniversitiesEntities()) { //Details method takes id as an input. //So, we are assigning collegeID == id return(View(collegeDetails.InstituteCampuses_.Where(a => a.CollegeID == id).FirstOrDefault())); } }
// I have created index.cshtml page for this action in order to display the list of // datas on the index page. public ActionResult Index() { //Made an object variable as universities to model UnversitiesEntities using (UniversitiesEntities universities = new UniversitiesEntities()) { //This will allow to view all the list of available colleges from table //Converting the data to list var listOfUniversities = universities.InstituteCampuses_.ToList(); var universitiesInAscendingOrder = listOfUniversities.OrderBy(a => a.Name); return(View(universitiesInAscendingOrder)); } }
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()); } }
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()); } }
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()); } }