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 Student(StudentViewModel model) { Id = model.Id; FirstName = model.FirstName; LastName = model.LastName; GPA = model.GPA; IsEnrolled = model.IsEnrolled; Version = Convert.FromBase64String(model.Version); }
public StatusTransport<StudentViewModel> Save(StudentViewModel model) { return _studentService.SaveStudent(model); }
public JsonResult Save(StudentViewModel model) { return new JsonResult { Data = _studentService.SaveStudent(model) }; }