I have a C# code that will perform CRUD operations on data into a grid view. I need to make it work with the lambda expressions. Please find the below code and help me further. I have no prior knowledge of regular expressions. I have given all the methods that need to be converted to Regular expressions and made better if possible at all angles. Please help me with this.
- public IQueryable<Student> studentsGrid_GetData()
- {
- SchoolContext db = new SchoolContext();
- var query = db.Students.Include(s => s.Enrollments.Select(e => e.Course));
- return query;
- }
-
-
- public void studentsGrid_UpdateItem(int id)
- {
- ContosoUniversityModelBinding.Models.Student item = null;
-
- if (item == null)
- {
-
- ModelState.AddModelError("", String.Format("Item with id {0} was not found", id));
- return;
- }
- TryUpdateModel(item);
- if (ModelState.IsValid)
- {
-
-
- }
- }
-
- public void studentsGrid_UpdateItem(int studentID)
- {
- using (SchoolContext db = new SchoolContext())
- {
- Student item = null;
- item = db.Students.Find(studentID);
- if (item == null)
- {
- ModelState.AddModelError("",
- String.Format("Item with id {0} was not found", studentID));
- return;
- }
-
- TryUpdateModel(item);
- if (ModelState.IsValid)
- {
- db.SaveChanges();
- }
- }
- }
-
- public void studentsGrid_DeleteItem(int studentID)
- {
- using (SchoolContext db = new SchoolContext())
- {
- var item = new Student { StudentID = studentID };
- db.Entry(item).State = EntityState.Deleted;
- try
- {
- db.SaveChanges();
- }
- catch (DbUpdateConcurrencyException)
- {
- ModelState.AddModelError("",
- String.Format("Item with id {0} no longer exists in the database.", studentID));
- }
- }
- }