示例#1
0
        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>();
            }
        }
示例#2
0
 public void Save(Member member)
 {
     if (member.Id == 0)
         this.Insert(member);
     else
         this.Update(member);
 }
示例#3
0
        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;
        }
示例#4
0
        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;
        }
示例#5
0
 public Member Insert(Member member)
 {
     if (member.PhoneNumbers != null && member.PhoneNumbers.Count > 0)
     {
         return InsertWithPhoneNumbers(member);
     }
     return databaseProvider.GetDatabase().Members.Insert(member);
 }
示例#6
0
 public Member Insert(Member member)
 {
     if (member.PhoneNumbers != null && member.PhoneNumbers.Count > 0)
     {
         return InsertWithPhoneNumbers(member);
     }
     return db.Members.Insert(member);
 }
示例#7
0
 public void Save(Member member)
 {
     if (member.Id == 0)
     {
         Insert(member);
     }
     else
     {
         Update(member);
     }
 }
示例#8
0
        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);
        }
示例#9
0
        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
                };
        }
示例#10
0
        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);
                }
            }
        }
示例#11
0
        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;
        }
示例#12
0
        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;
        }
示例#13
0
        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;
        }
示例#14
0
 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
     };
 }
示例#15
0
        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;
                }
            }
        }
示例#16
0
 private bool NameSearch(Member member, string criteria)
 {
     return GetForenameSurname(member).Contains(criteria) || GetSurnameForename(member).Contains(criteria) || GetInitialSurname(member).Contains(criteria);
 }
示例#17
0
 private string GetSurnameForename(Member member)
 {
     return string.Format("{0} {1} {2}", member.Salutation, member.LastName, member.FirstName).ToLower();
 }
示例#18
0
 private string GetInitialSurname(Member member)
 {
     return string.Format("{0} {1} {2}", member.Salutation, member.FirstName.Substring(0, 1), member.LastName).ToLower();
 }
示例#19
0
 public void Update(Member member)
 {
     _membersDb.Update(member);
 }
示例#20
0
 public void Insert(Member member)
 {
     _membersDb.Insert(member);
 }
示例#21
0
 private string NextReference(Member member)
 {
     lastReferenceNumber++;
     string namePrefix = member.FirstName.Substring(0, 1) + member.LastName.Substring(0, 1);
     return namePrefix + lastReferenceNumber.ToString("000000");
 }
示例#22
0
 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;
 }
示例#23
0
        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()
                                            });
            }
        }
示例#24
0
 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;
 }
示例#25
0
 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;
 }
示例#26
0
 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;
 }
示例#27
0
        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;
        }
示例#28
0
 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));
         }
     }
 }
示例#29
0
 private string FirstTelephoneNumber(Member member, PhoneNumberType phoneNumberType)
 {
     PhoneNumber phoneNumber = member.PhoneNumbers.FirstOrDefault(number => number.PhoneNumberType == phoneNumberType);
     return phoneNumber != null ? phoneNumber.Number : string.Empty;
 }
示例#30
0
 public void Insert(Member member)
 {
     memberRepository.Insert(member);
 }