public StatusTransport<StudentViewModel> SaveStudent(StudentViewModel model) { var transport = new StatusTransport<StudentViewModel>(); var student = new Student(model); _context.Students.Attach(student, true); try { _context.SubmitChanges(); // Retrieve most recent version. _context.Refresh(RefreshMode.OverwriteCurrentValues, student); transport.ViewModel = new StudentViewModel(student) { ClientId = model.ClientId }; transport.SetSuccess(); // Update all connected clients. Comment this line out to test // normal conflict resolution. BroadcastStudent(transport); } catch (ChangeConflictException exConflict) { // Retrieve most recent version. _context.Refresh(RefreshMode.OverwriteCurrentValues, student); transport.ViewModel = new StudentViewModel(student); // Mark result as stale. transport.SetStale(exConflict); } return transport; }
public StudentViewModel(Student student) { Id = student.Id; FirstName = student.FirstName; LastName = student.LastName; GPA = student.GPA; IsEnrolled = student.IsEnrolled; Version = Convert.ToBase64String((student.Version ?? new byte[] { }).ToArray()); }
partial void DeleteStudent(Student instance);
partial void UpdateStudent(Student instance);
partial void InsertStudent(Student instance);