public static bool Delete(Entities.TourMember person) { bool res = true; try { using (TransactionScope ts = new TransactionScope()) { foreach (Entities.Contact contact in person.Contacts) { if (!(res = contacts.Delete(contact))) { break; } } if (res) { res = persons.Delete(person); } if (res) { res = members.Delete(person); } if (res) { ts.Complete(); } } if (res) { cache.Remove(person); } } catch (Exception ex) { res = false; try { DomainModel.Application.Status.Update( StatusController.Abstract.StatusTypes.Error, "", ex.Message); } catch { } } return(res); }
// Provide group for inserts public static bool Save(Entities.TourMember member, Entities.TourGroup group = null) { bool res = true; try { using (TransactionScope ts = new TransactionScope()) { // Save changes to member if (member.IsDirty) { if (member.Id < 0) { if (!(res = members.Insert(member))) { return(res); } } else { if (!(res = members.Update(member))) { return(res); } } } // Save member-tour relation if (group != null) { if (!(res = groupMembers.Insert(group, member))) { return(res); } } // Save contacts foreach (Entities.Contact contact in member.Contacts) { if (contact.IsDirty) { if (contact.Id < 0) { if (!(res = contacts.Insert(member, contact))) { return(res); } } else { if (!(res = contacts.Update(member, contact))) { return(res); } } } } // Save deleted contacts foreach (Entities.Contact contact in member.DeletedContacts) { if (!(res = contacts.Delete(contact))) { return(res); } } // Update cache if (group != null && !group.Members.Contains(member)) { group.Members.Add(member); } ts.Complete(); } } catch (Exception ex) { try { DomainModel.Application.Status.Update( StatusController.Abstract.StatusTypes.Error, "", ex.Message); } catch { } } return(res); }