public void Update(Member member) { bool refetchPhoneNumbers = false; using (var transaction = db.BeginTransaction()) { try { transaction.Members.UpdateById(member); refetchPhoneNumbers = UpdatePhoneNumbers(member, transaction); transaction.Commit(); } catch { transaction.Rollback(); throw; } } if (refetchPhoneNumbers) { var newNos = db.PhoneNumbers.FindAllByMemberId(member.Id); member.PhoneNumbers = newNos.ToList<PhoneNumber>(); } }
public void Save(Member member) { if (member.Id == 0) this.Insert(member); else this.Update(member); }
private string GenerateEmailAddress(Member member) { string sep = random.PickFromList(EmailData.Separators); if (random.Percent(30)) { sep += random.Letter() + random.PickFromList(EmailData.Separators); } string name; if (random.Percent(30)) { name = member.LastName + sep + member.FirstName; } else { name = member.FirstName + sep + member.LastName; } if (random.Bool()) { name += this.random.Next(100).ToString(); } string domain = random.PickFromList(EmailData.Domains); return name + "@" + domain; }
private Member GenerateMember() { bool isFemale = random.Bool(); string familyName = random.PickFromList(FamilyNames.Data); // make first name different from Family name, ie.g. no "Scott Scott" or "Major Major" string firstName; do { firstName = isFemale ? RandomFemaleFirstName() : RandomMaleFirstName(); } while(firstName == familyName); TitleDataItem titleSalutation = MakeTitleSalutation(isFemale); var newMember = new Member { FirstName = firstName, LastName = familyName, Title = titleSalutation.Title, Salutation = titleSalutation.Salutation, }; newMember.Reference = this.NextReference(newMember); MakeEmailAddress(newMember); MakeStreetAddress(newMember); MakePhoneNumbers(newMember); return newMember; }
public Member Insert(Member member) { if (member.PhoneNumbers != null && member.PhoneNumbers.Count > 0) { return InsertWithPhoneNumbers(member); } return databaseProvider.GetDatabase().Members.Insert(member); }
public Member Insert(Member member) { if (member.PhoneNumbers != null && member.PhoneNumbers.Count > 0) { return InsertWithPhoneNumbers(member); } return db.Members.Insert(member); }
public void Save(Member member) { if (member.Id == 0) { Insert(member); } else { Update(member); } }
public void Delete(Member member) { member.AddressLine1 = "deleted"; member.AddressLine2 = "deleted"; member.EmailAddress = "deleted"; member.FirstName = "deleted"; member.LastName = "deleted"; member.Archived = true; _membersDb.Update(member); }
private Donation DonationForMember(Member member, int minAmount, int maxAmount) { DateTime backDate = DateTime.Today.AddDays(-1 * random.Next(100)); int amountInt = random.Next(minAmount, maxAmount + 1); decimal donationAmount = amountInt; if (donationAmount < maxAmount) { donationAmount += RandomFaction(); } return new Donation { CampaignId = campaign.Id, MemberId = member.Id, Date = backDate, Amount = donationAmount }; }
private void GenerateCampaignDonationsForMember(Donations donationsRepo, Campaign campaign, Member member) { int numberOfDonations = random.NextInt(0, 3); for (int i = 0; i < numberOfDonations; i++) { // don't generate donations each time to simulate a miss if (this.random.Percent(donationRate)) { decimal amount = GenerateAmount(); Donation donation = new Donation { CampaignId = campaign.Id, MemberId = member.Id, Amount = amount, Date = random.NextDateTime(), }; donationsRepo.Insert(donation); } } }
private Member GenerateMember() { bool isFemale = random.Bool(); string familyName = random.PickFromList(FamilyNames.Data); // make first name different from Family name, ie.g. no "Scott Scott" or "Major Major" string firstName; do { var namesList = isFemale ? FemaleNames.Data : MaleNames.Data; firstName = random.PickFromList(namesList); } while (firstName == familyName); TitleDataItem titleSalutation = isFemale ? titleGenerator.GenerateFemaleTitle() : titleGenerator.GenerateMaleTitle(); var member = new Member { FirstName = firstName, LastName = familyName, Title = titleSalutation.Title, Salutation = titleSalutation.Salutation, }; member.Reference = this.NextReference(member); member.EmailAddress = emailGenerator.GenerateEmailAddress(member.FirstName, member.LastName); var addressData = addressGenerator.GenerateStreetAddress(); member.AddressLine1 = addressData.Address; member.City = addressData.City; member.Region = addressData.Region; member.PostalCode = addressData.PostalCode; member.Country = addressData.Country; MakePhoneNumbers(member); return member; }
private void MakeStreetAddress(Member member) { string streetAddress = GenerateStreetAddress(); while (generatedPostalAddresses.ContainsKey(streetAddress)) { // duplicate! try again streetAddress = GenerateStreetAddress(); } generatedPostalAddresses.Add(streetAddress, true); member.AddressLine1 = streetAddress; TownDataItem townData = random.PickFromList(TownData.Data); string postCodePrefix = random.PickFromList(townData.PostalCodePrefixes); member.PostalCode = RandomPostalCode(postCodePrefix); member.City = townData.Town; member.Region = townData.Region; member.Country = townData.Country; }
private void MakeEmailAddress(Member member) { string newEmailAddress = GenerateEmailAddress(member); while (generatedEmails.ContainsKey(newEmailAddress)) { // duplicate! regenerate it. newEmailAddress = GenerateEmailAddress(member); } generatedEmails.Add(newEmailAddress, true); member.EmailAddress = newEmailAddress; }
public static MemberEditViewModel ToViewModel(Member member) { return new MemberEditViewModel { Id = member.Id, Reference = member.Reference, Title = member.Title, FirstName = member.FirstName, LastName = member.LastName, Salutation = member.Salutation, EmailAddress = member.EmailAddress, AddressLine1 = member.AddressLine1, AddressLine2 = member.AddressLine2, City = member.City, Region = member.Region, PostalCode = member.PostalCode, Country = member.Country, PhoneNumbers = member.PhoneNumbers }; }
private Member InsertWithPhoneNumbers(Member member) { using (var transaction = db.BeginTransaction()) { try { Member inserted = transaction.Members.Insert(member); foreach (var phoneNumber in member.PhoneNumbers) { phoneNumber.MemberId = inserted.Id; } inserted.PhoneNumbers = transaction.PhoneNumbers.Insert(member.PhoneNumbers).ToList<PhoneNumber>(); transaction.Commit(); return inserted; } catch { transaction.Rollback(); throw; } } }
private bool NameSearch(Member member, string criteria) { return GetForenameSurname(member).Contains(criteria) || GetSurnameForename(member).Contains(criteria) || GetInitialSurname(member).Contains(criteria); }
private string GetSurnameForename(Member member) { return string.Format("{0} {1} {2}", member.Salutation, member.LastName, member.FirstName).ToLower(); }
private string GetInitialSurname(Member member) { return string.Format("{0} {1} {2}", member.Salutation, member.FirstName.Substring(0, 1), member.LastName).ToLower(); }
public void Update(Member member) { _membersDb.Update(member); }
public void Insert(Member member) { _membersDb.Insert(member); }
private string NextReference(Member member) { lastReferenceNumber++; string namePrefix = member.FirstName.Substring(0, 1) + member.LastName.Substring(0, 1); return namePrefix + lastReferenceNumber.ToString("000000"); }
private static MemberFacetFreeText CreateFreeTextMemberFacet(Member member, Facet textFacet) { var facet = new MemberFacetFreeText { FacetId = textFacet.Id, MemberId = member.Id, FreeTextValue = "Aardvark" }; facet = new MemberFacets().Insert(facet); return facet; }
private void MakePhoneNumbers(Member member) { member.PhoneNumbers = new List<PhoneNumber>(); if (random.Percent(10)) { // 10% have no phone numbers return; } if (random.Percent(60)) { member.PhoneNumbers.Add(new PhoneNumber { PhoneNumberType = PhoneNumberType.Home, Number = random.PhoneDigits() }); } if (random.Percent(60)) { member.PhoneNumbers.Add(new PhoneNumber { PhoneNumberType = PhoneNumberType.Work, Number = random.PhoneDigits() }); } if (random.Percent(60)) { member.PhoneNumbers.Add(new PhoneNumber { PhoneNumberType = PhoneNumberType.Mobile, Number = random.PhoneDigits() }); } }
private static MemberFacetList CreateListMemberFacet(Member member, Facet listFacet) { var facet = new MemberFacetList { FacetId = listFacet.Id, MemberId = member.Id, Values = new List<MemberFacetValue> { new MemberFacetValue {FacetValueId = listFacet.Values.First().Id}, new MemberFacetValue {FacetValueId = listFacet.Values.Last().Id}, } }; facet = new MemberFacets().Insert(facet); return facet; }
private static Member CreateAlice() { var member = new Member { Reference = "ABC", Title = "Ms", FirstName = "Alice", LastName = "Krige", Salutation = "Alice", EmailAddress = "*****@*****.**", AddressLine1 = "Dunassimilatin", AddressLine2 = "Sector 4", City = "Nexus One", Region = "Delta Quadrant", Country = "Wales", PostalCode = "CA1 0PP", }; return member; }
private static Member CreateBob() { var member = new Member { Reference = "ABC123", Title = "Mr", FirstName = "Bob", LastName = "Along", Salutation = "Bob", EmailAddress = "*****@*****.**" }; member = new Members().Insert(member); return member; }
private bool UpdatePhoneNumbers(Member member, dynamic transaction) { bool refetchPhoneNumbers = false; foreach (var phoneNumber in member.PhoneNumbers) { if (phoneNumber.MemberId == 0) { phoneNumber.MemberId = member.Id; transaction.PhoneNumbers.Insert(phoneNumber); refetchPhoneNumbers = true; } else { transaction.PhoneNumbers.UpdateById(phoneNumber); } } return refetchPhoneNumbers; }
private void GenerateDonationsForMember(int minAmount, int maxAmount, int donationCountMax, Member member, List<Donation> donations) { for (int donationsForMember = 0; donationsForMember < donationCountMax; donationsForMember++) { if (this.random.Percent(this.donationRate)) { donations.Add(this.DonationForMember(member, minAmount, maxAmount)); } } }
private string FirstTelephoneNumber(Member member, PhoneNumberType phoneNumberType) { PhoneNumber phoneNumber = member.PhoneNumbers.FirstOrDefault(number => number.PhoneNumberType == phoneNumberType); return phoneNumber != null ? phoneNumber.Number : string.Empty; }
public void Insert(Member member) { memberRepository.Insert(member); }