//make a new action that will search the DB for my result public IActionResult Search(string result) { // Use my context class to pull in my DataBase data TestEFCoreContext db = new TestEFCoreContext(); // make an indiviodual Person object to store my result in Person foundResult = new Person(); // make a TempData object and set it to false // this allows me to later set it to true if I find a match TempData["Registered"] = false; // i need to find my result in my DB foreach (Person person in db.Person) { // as i iterate through the collection, I want to find the correct result if (person.Name == result) { // if you find a match, assign that value to your temp Person object foundResult = person; // You found a match, set your TempData to true // this allows us to display certain HTML TempData["Registered"] = true; } } // pass the object with the data to the view to be displayed return(View(foundResult)); }
public void Save(userDTO dto) { using (TestEFCoreContext db = new TestEFCoreContext()) { db.User.Add(Mapper.Map <userDTO, User>(dto)); db.SaveChanges(); } }
public IActionResult Index() { // Use my context class to pull in my DataBase data TestEFCoreContext db = new TestEFCoreContext(); //we use TempData to hold temporary global values //TempData is dictionary of Key Value pairs //flip this value TempData["bool"] = false; //pass the model to view to display the data return(View(db)); }