//public CACCCheckInDb.ClassMember UpdateClassMember(CACCCheckInDb.ClassMember updatedClassMember) //{ // logger.Debug("Opening DataContext to CACCCheckIn DB."); // CACCCheckInDb.CACCCheckInDbDataContext db = new CACCCheckInDb.CACCCheckInDbDataContext(); // db.Log = logwriter; // logger.DebugFormat("Querying CACCCheckIn DB for ClassMember with ClassId=[{0}] and PersonId=[{1}].", // updatedClassMember.ClassId.ToString("B"), updatedClassMember.PersonId.ToString("B")); // CACCCheckInDb.ClassMember currentClassMember = (from cm in db.ClassMembers // where cm.ClassId.Equals(updatedClassMember.ClassId) && // cm.PersonId.Equals(updatedClassMember.PersonId) // select cm).SingleOrDefault<CACCCheckInDb.ClassMember>(); // logger.Debug("Updating ClassMember."); // currentClassMember.ClassRole = updatedClassMember.ClassRole; // db.SubmitChanges(); // return db.ClassMembers.Where(cm => // cm.ClassId.Equals(updatedClassMember.ClassId) && // cm.PersonId.Equals(updatedClassMember.PersonId)).Single<CACCCheckInDb.ClassMember>(); //} public void DeleteClassMember(CACCCheckInDb.ClassMember classMember) { logger.Debug("Opening DataContext to CACCCheckIn DB."); CACCCheckInDb.CACCCheckInDbDataContext db = new CACCCheckInDb.CACCCheckInDbDataContext(); db.Log = logwriter; try { logger.DebugFormat("Querying CACCCheckIn DB for ClassMember with ClassId=[{0}] and PersonId=[{1}].", classMember.ClassId.ToString("B"), classMember.PersonId.ToString("B")); CACCCheckInDb.ClassMember classMemberToDelete = (from cm in db.ClassMembers where cm.ClassId.Equals(classMember.ClassId) && cm.PersonId.Equals(classMember.PersonId) select cm).Single <CACCCheckInDb.ClassMember>(); logger.Debug("Deleting ClassMember."); db.ClassMembers.DeleteOnSubmit(classMemberToDelete); db.SubmitChanges(); } catch (ChangeConflictException ex) { logger.Error("ChangeConflictException:", ex); foreach (ObjectChangeConflict occ in db.ChangeConflicts) { occ.Resolve(RefreshMode.OverwriteCurrentValues); } } }
/// <summary> /// Whenever a Person in the collection has had its EndEdit /// </summary> /// <param name="sender"></param> private void PeopleItemEndEdit(IEditableObject sender) { try { // Get the Person that has been edited. This could be a new // class or an edit to existing Person. CACCCheckInDb.Person updatedPerson = sender as CACCCheckInDb.Person; // If the RowTimestamp is null, this must be brand new Person // that hasn't been added to the database yet. If not, this // must be an update to existing Person if (updatedPerson.RowTimestamp == null) { logger.DebugFormat("Adding person [{0} {1}]", updatedPerson.FirstName, updatedPerson.LastName); updatedPerson = CACCCheckInDb.People.InsertPerson(updatedPerson); View.ViewDispatcher.BeginInvoke(DispatcherPriority.DataBind, new DispatcherOperationCallback( delegate(object arg) { View.PersonInsertCompleted(updatedPerson); return(null); }), null); CACCCheckInDb.ClassMember newClassMember = new CACCCheckInDb.ClassMember(); newClassMember.ClassId = View.CurrentClass.Id; newClassMember.PersonId = updatedPerson.Id; newClassMember.ClassRole = ClassRoles.Member; InsertClassMember(newClassMember); logger.DebugFormat("Person [{0} {1}] was added.", updatedPerson.FirstName, updatedPerson.LastName); } else { logger.Debug("Person is being updated."); CACCCheckInDb.People.UpdatePerson(updatedPerson); logger.DebugFormat("Person [{0} {1}] was updated.", updatedPerson.FirstName, updatedPerson.LastName); } } catch (Exception ex) { Debug.Assert(View != null); View.ViewDispatcher.BeginInvoke(DispatcherPriority.DataBind, new DispatcherOperationCallback( delegate(object arg) { View.DisplayExceptionDetail(ex); return(null); }), null); } }
/// <summary> /// /// </summary> /// <param name="classMember"></param> public void InsertClassMember(CACCCheckInDb.ClassMember classMember) { using (CACCCheckInServiceProxy proxy = new CACCCheckInServiceProxy()) { proxy.Open(); proxy.InsertClassMember(classMember); } }
//public CACCCheckInDb.ClassMember UpdateClassMember(CACCCheckInDb.ClassMember updatedClassMember) //{ // Stopwatch sw = new Stopwatch(); // try // { // sw.Start(); // return Channel.UpdateClassMember(updatedClassMember); // } // finally // { // sw.Stop(); // logger.DebugFormat("Call to CACCCheckInService.UpdateClassMember took [{0}] ms", // sw.ElapsedMilliseconds); // } //} public void DeleteClassMember(CACCCheckInDb.ClassMember classMember) { Stopwatch sw = new Stopwatch(); try { sw.Start(); Channel.DeleteClassMember(classMember); } finally { sw.Stop(); logger.DebugFormat("Call to CACCCheckInService.DeleteClassMember took [{0}] ms", sw.ElapsedMilliseconds); } }
//public List<CACCCheckInDb.ClassMember> GetAllFromClassMember() //{ // logger.Debug("Opening DataContext to CACCCheckIn DB."); // CACCCheckInDb.CACCCheckInDbDataContext db = new CACCCheckInDb.CACCCheckInDbDataContext(); // db.Log = logwriter; // DataLoadOptions dlo = new DataLoadOptions(); // dlo.LoadWith<CACCCheckInDb.ClassMember>(cm => cm.Class); // dlo.LoadWith<CACCCheckInDb.ClassMember>(cm => cm.Person); // dlo.LoadWith<CACCCheckInDb.Class>(c => c.Department); // db.LoadOptions = dlo; // logger.Debug("Querying CACCCheckIn DB for ALL ClassMember records."); // List<CACCCheckInDb.ClassMember> members = (from cm in db.ClassMembers // select cm).ToList(); // return members; //} //public List<CACCCheckInDb.ClassMember> GetClassMembersByClassId(Guid classId) //{ // logger.Debug("Opening DataContext to CACCCheckIn DB."); // CACCCheckInDb.CACCCheckInDbDataContext db = new CACCCheckInDb.CACCCheckInDbDataContext(); // db.Log = logwriter; // DataLoadOptions dlo = new DataLoadOptions(); // dlo.LoadWith<CACCCheckInDb.ClassMember>(cm => cm.Class); // dlo.LoadWith<CACCCheckInDb.ClassMember>(cm => cm.Person); // dlo.LoadWith<CACCCheckInDb.Class>(c => c.Department); // db.LoadOptions = dlo; // logger.DebugFormat("Querying CACCCheckIn DB for ClassMember with ClassId=[{0}].", // classId.ToString("B")); // List<CACCCheckInDb.ClassMember> members = (from cm in db.ClassMembers // where cm.ClassId.Equals(classId) // select cm).ToList(); // return members; //} //public List<CACCCheckInDb.ClassMember> GetClassMembersByClassIdAndClassRole(Guid classId, // CACCCheckInDb.ClassRole role) //{ // logger.Debug("Opening DataContext to CACCCheckIn DB."); // CACCCheckInDb.CACCCheckInDbDataContext db = new CACCCheckInDb.CACCCheckInDbDataContext(); // db.Log = logwriter; // DataLoadOptions dlo = new DataLoadOptions(); // dlo.LoadWith<CACCCheckInDb.ClassMember>(cm => cm.Class); // dlo.LoadWith<CACCCheckInDb.ClassMember>(cm => cm.Person); // dlo.LoadWith<CACCCheckInDb.Class>(c => c.Department); // db.LoadOptions = dlo; // logger.DebugFormat("Querying CACCCheckIn DB for ClassMember with ClassId=[{0}] and ClassRole=[{1}].", // classId.ToString("B"), role.Role); // List<CACCCheckInDb.ClassMember> members = (from cm in db.ClassMembers // where cm.ClassId.Equals(classId) && // cm.ClassRole.Equals(role.Role) // select cm).ToList(); // return members; //} //public List<CACCCheckInDb.ClassMember> GetClassMembersByClassRole(CACCCheckInDb.ClassRole role) //{ // logger.Debug("Opening DataContext to CACCCheckIn DB."); // CACCCheckInDb.CACCCheckInDbDataContext db = new CACCCheckInDb.CACCCheckInDbDataContext(); // db.Log = logwriter; // DataLoadOptions dlo = new DataLoadOptions(); // dlo.LoadWith<CACCCheckInDb.ClassMember>(cm => cm.Class); // dlo.LoadWith<CACCCheckInDb.ClassMember>(cm => cm.Person); // dlo.LoadWith<CACCCheckInDb.Class>(c => c.Department); // db.LoadOptions = dlo; // logger.DebugFormat("Querying CACCCheckIn DB for ClassMember with ClassRole=[{0}].", // role.Role); // List<CACCCheckInDb.ClassMember> members = (from cm in db.ClassMembers // where cm.ClassRole.Equals(role.Role) // select cm).ToList(); // return members; //} //public List<CACCCheckInDb.ClassMember> GetClassMembersByDepartmentId(Guid departmentId) //{ // logger.Debug("Opening DataContext to CACCCheckIn DB."); // CACCCheckInDb.CACCCheckInDbDataContext db = new CACCCheckInDb.CACCCheckInDbDataContext(); // db.Log = logwriter; // DataLoadOptions dlo = new DataLoadOptions(); // dlo.LoadWith<CACCCheckInDb.ClassMember>(cm => cm.Class); // dlo.LoadWith<CACCCheckInDb.ClassMember>(cm => cm.Person); // dlo.LoadWith<CACCCheckInDb.Class>(c => c.Department); // db.LoadOptions = dlo; // logger.DebugFormat("Querying CACCCheckIn DB for ClassMember with DepartmentId=[{0}].", // departmentId.ToString("B")); // List<CACCCheckInDb.ClassMember> members = (from cm in db.ClassMembers // where cm.Class.DeptId.Equals(departmentId) // select cm).ToList(); // return members; //} //public List<CACCCheckInDb.ClassMember> GetClassMembersByDepartmentIdAndClassId(Guid departmentId, // Guid classId) //{ // logger.Debug("Opening DataContext to CACCCheckIn DB."); // CACCCheckInDb.CACCCheckInDbDataContext db = new CACCCheckInDb.CACCCheckInDbDataContext(); // db.Log = logwriter; // DataLoadOptions dlo = new DataLoadOptions(); // dlo.LoadWith<CACCCheckInDb.ClassMember>(cm => cm.Class); // dlo.LoadWith<CACCCheckInDb.ClassMember>(cm => cm.Person); // dlo.LoadWith<CACCCheckInDb.Class>(c => c.Department); // db.LoadOptions = dlo; // logger.DebugFormat("Querying CACCCheckIn DB for ClassMember with DepartmentId=[{0}] and ClassId=[{1}].", // departmentId.ToString("B"), classId.ToString("B")); // List<CACCCheckInDb.ClassMember> members = (from cm in db.ClassMembers // where cm.ClassId.Equals(classId) && // cm.Class.DeptId.Equals(departmentId) // select cm).ToList(); // return members; //} public CACCCheckInDb.ClassMember InsertClassMember(CACCCheckInDb.ClassMember classMember) { logger.Debug("Opening DataContext to CACCCheckIn DB."); CACCCheckInDb.CACCCheckInDbDataContext db = new CACCCheckInDb.CACCCheckInDbDataContext(); db.Log = logwriter; logger.DebugFormat("Inserting ClassMember with PersonId=[{0}].", classMember.PersonId.ToString("B")); db.ClassMembers.InsertOnSubmit(classMember); db.SubmitChanges(); return(db.ClassMembers.Where(cm => cm.ClassId.Equals(classMember.ClassId) && cm.PersonId.Equals(classMember.PersonId)).Single <CACCCheckInDb.ClassMember>()); }
/// <summary> /// Will add a person to class /// </summary> /// <param name="person"></param> private void AddPersonClassMembership(CACCCheckInDb.PeopleWithDepartmentAndClassView person) { logger.DebugFormat("Adding class membership for [{0} {1}]", person.FirstName, person.LastName); // Get a reference to ClassMember record for current person CACCCheckInDb.ClassMember newClassMember = (CACCCheckInDb.ClassMember)person; using (CACCCheckInServiceProxy proxy = new CACCCheckInServiceProxy()) { proxy.Open(); logger.Debug("Calling InsertClassMember in CACCCheckInService"); proxy.InsertClassMember(newClassMember); } }
/// <summary> /// Will move a person from current class to new class /// </summary> /// <param name="person"></param> /// <param name="newClass"></param> public void UpdatePersonClassMembership(CACCCheckInDb.PeopleWithDepartmentAndClassView person, CACCCheckInDb.Class newClass) { try { logger.DebugFormat("Updating class membership for [{0} {1}]", person.FirstName, person.LastName); // Get a reference to ClassMember record for current person CACCCheckInDb.ClassMember oldClassMember = (CACCCheckInDb.ClassMember)person; // Create a new ClassMember record to move current person to new class CACCCheckInDb.ClassMember newClassMember = new CACCCheckInDb.ClassMember(); // The new ClassId is used along with current ClassRole and PersonId newClassMember.ClassId = newClass.Id; newClassMember.ClassRole = oldClassMember.ClassRole; newClassMember.PersonId = oldClassMember.PersonId; using (CACCCheckInServiceProxy proxy = new CACCCheckInServiceProxy()) { proxy.Open(); logger.Debug("Calling DeleteClassMember in CACCCheckInService"); proxy.DeleteClassMember(oldClassMember); logger.Debug("Calling InsertClassMember in CACCCheckInService"); proxy.InsertClassMember(newClassMember); } } catch (Exception ex) { Debug.Assert(View != null); View.ViewDispatcher.BeginInvoke(DispatcherPriority.DataBind, new DispatcherOperationCallback( delegate(object arg) { View.DisplayExceptionDetail(ex); return(null); }), null); } }
/// <summary> /// Will add a person as teacher to specified class /// </summary> /// <param name="person"></param> /// <param name="newClass"></param> public void AddPersonAsTeacherToClass(CACCCheckInDb.PeopleWithDepartmentAndClassView person, CACCCheckInDb.Class theClass) { try { logger.DebugFormat("Updating class membership for [{0} {1}]", person.FirstName, person.LastName); // Get a reference to ClassMember record for current person CACCCheckInDb.ClassMember classMember = (CACCCheckInDb.ClassMember)person; // The ClassId is used along with ClassRole to update ClassMember record classMember.ClassId = theClass.Id; classMember.ClassRole = ClassRoles.Teacher; using (CACCCheckInServiceProxy proxy = new CACCCheckInServiceProxy()) { proxy.Open(); logger.Debug("Calling InsertClassMember in CACCCheckInService"); proxy.InsertClassMember(classMember); } } catch (Exception ex) { Debug.Assert(View != null); View.ViewDispatcher.BeginInvoke(DispatcherPriority.DataBind, new DispatcherOperationCallback( delegate(object arg) { View.DisplayExceptionDetail(ex); return(null); }), null); } }