Example #1
0
        public void ShouldGetTheRightPersonWhoMadeTheComment()
        {
            const int personId = 1;
            const int roleId = 1;
            var commentsToDelete = Context.Comments.Where(c => c.AboutPersonId == personId).ToList();
            foreach (var commentToDelete in commentsToDelete)
                Context.DeleteObject(commentToDelete);

            ICommentRepository commentsRepo = new CommentRepository(Context);
            var currentPerson = new Person { PersonId = personId, RoleId = roleId };

            const string testComment = "Test Comment";

            var newComment = new CommentDto
            {
                Comment       = testComment,
                AboutPersonId = personId,
                CommentDate   = DateTime.Now
            };

            var commentId = commentsRepo.SaveItem(currentPerson, newComment);
            var sut       = commentsRepo.GetListOfComments(currentPerson, personId).ToList();

            Assert.That(sut[0].CreatedByPerson, Is.EqualTo("Peter Munnings"));
        }
Example #2
0
        public void CanGetListOfPersonEventsForAGroup()
        {
            var eventRepository = MockRepository.GenerateStub<IEventRepository>();
            var eventList = new List<PersonEventDto> { new PersonEventDto(), new PersonEventDto(), new PersonEventDto() };
            var currentPerson = new Person {Permissions = new List<int> {57}};
            eventRepository
                .Expect(e => e.GetPersonEventsForGroup(1, currentPerson))
                .Return(eventList);

            var permissionRepository = new PermissionRepository();
            var personRepository = new PersonRepository(permissionRepository, new ChurchRepository());
            var usernamePasswordRepository = new UsernamePasswordRepository(permissionRepository);
            var groupRepository = new GroupRepository();
            var messageRepository = new MessageRepository();
            var messageRecepientRepository = new MessageRecepientRepository();
            var messageAttachmentRepository = new MessageAttachmentRepository();
            var emailSender = new EmailSender(messageRepository, messageRecepientRepository, messageAttachmentRepository, personRepository);
            var churchEmailTemplatesRepository = new ChurchEmailTemplatesRepository();
            var emailContentRepository = new EmailContentRepository();
            var emailContentService = new EmailContentService(emailContentRepository);
            var emailService = new EmailService(usernamePasswordRepository, personRepository, groupRepository, emailSender, emailContentService, churchEmailTemplatesRepository, permissionRepository);
            IEventService eventService = new EventService(eventRepository, emailService, new BirthdayAndAniversaryRepository());

            var sut = eventService.GetPersonEventsForGroup(1, currentPerson);

            Assert.That(sut.Count(), Is.EqualTo(3));
        }
 public string UpdatePassword(Person person)
 {
     var password = RandomPasswordGenerator.Generate(RandomPasswordOptions.AlphaNumeric);
     person.PasswordHash = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "sha1");
     Context.SaveChanges();
     return password;
 }
        public void UpdateRelationships(PersonViewModel person, Person personToSave, bool anniversaryHasChanged)
        {
            if (person.FamilyMembers == null) return;
            foreach (var familyMember in person.FamilyMembers)
            {
                if (familyMember.Relationship == null) continue;
                var relationship = (Relationships)Enum.Parse(typeof(Relationships), familyMember.Relationship);
                if (anniversaryHasChanged && (relationship == Relationships.Husband || relationship == Relationships.Wife))
                {
                    var spouse = (from p in Context.People
                                  where p.PersonId == familyMember.PersonId
                                  select p).FirstOrDefault();

                    if (spouse != null)
                    {
                        spouse.Anniversary = personToSave.Anniversary;
                    }
                }

                AddPersonRelationship(personToSave.PersonId, familyMember.PersonId, (int)relationship, personToSave);

                //Check the opposite relationship
                UpdateOtherRelationships(familyMember, person);
            }
            Context.SaveChanges();
        }
        public JqGridData FetchGroupsPersonIsNotInJQGrid(Person currentPerson, int personId, JqGridRequest request)
        {
            var groups = _personGroupRepository.GetPersonGroupViewModels(personId, currentPerson);
            var groupsPersonIsNotIn = groups.Where(g => g.IsInGroup==false);

            return CreateGridFromData(request, groupsPersonIsNotIn);
        }
 public void CheckThatChurchIdsMatch(int personId, Person currentPerson)
 {
     if (currentPerson.HasPermission(Permissions.SystemAdministrator))
         return;
     if (!Context.People.First(p => p.PersonId == personId).PersonChurches.Select(c => c.ChurchId).ToList().Contains(currentPerson.ChurchId))
         throw new ApplicationException("ChurchId does not match currentPerson ChurchId");
 }
        public void Save(Person currentPerson, HomeGroupEventViewModel hgEvent)
        {
            if (hgEvent == null) return;
            var didAttend = 0;
            var didNotAttend = 0;
            foreach (var personEvents in hgEvent.Events)
            {
                var person = _personRepository.FetchPerson(personEvents.PersonId);
                foreach (var personEvent in personEvents.Events)
                {
                    var pe = EventDataAccessor.SavePersonEvent(Context, personEvents, currentPerson, personEvent);
                    EventDataAccessor.CheckToSeeIfEventAlreadyExists(personEvents, Context, personEvent, pe);

                    if (!person.HasPermission(Permissions.IncludeInGroupAttendanceStats)) continue;
                    if (personEvent.Name == EventNames.DidNotAttendGroup)
                        didNotAttend++;
                    if (personEvent.Name == EventNames.AttendedGroup)
                        didAttend++;
                }
            }

            //Add the attended and did not attend group events
            EventDataAccessor.AddAttendanceEvents(hgEvent, Context, didAttend, "Members attended", currentPerson);
            EventDataAccessor.AddAttendanceEvents(hgEvent, Context, didNotAttend, "Members did not attend", currentPerson);

            Context.SaveChanges();
        }
        public IEnumerable<ChildReportDto> GetListOfChildrenForAChurch(Person personRunningReport, IEnumerable<int> roles)
        {
            if (!personRunningReport.HasPermission(Permissions.ViewAdminReports))
                return new List<ChildReportDto>();

            var list = Context.PersonChurches
                .Where(pc => pc.ChurchId == personRunningReport.ChurchId && roles.Contains(pc.RoleId))
                .Select(pc => new ChildReportDto
                {
                    PersonId = pc.PersonId,
                    Firstname = pc.Person.Firstname,
                    Surname = pc.Person.Family.FamilyName,
                    HomePhone = pc.Person.Family.HomePhone,
                    DateOfBirth = pc.Person.DateOfBirth,
                    CellNo = pc.Person.PersonOptionalFields.FirstOrDefault(o => o.OptionalFieldId == (int) OptionalFields.CellPhone).Value,
                    AddressLine1 = pc.Person.Family.Address.Line1,
                    AddressLine2 = pc.Person.Family.Address.Line2,
                    AddressLine3 = pc.Person.Family.Address.Line3,
                    AddressLine4 = pc.Person.Family.Address.Line4,
                    Father = pc.Person.PersonRelationships.FirstOrDefault(r => r.RelationshipId == (int) Relationships.Father).Person1.Firstname,
                    FatherEmail = pc.Person.PersonRelationships.FirstOrDefault(r => r.RelationshipId == (int)Relationships.Father).Person1.Email,
                    FatherCell = pc.Person.PersonRelationships.FirstOrDefault(r => r.RelationshipId == (int)Relationships.Father).Person1==null ? null :
                                 pc.Person.PersonRelationships.FirstOrDefault(r => r.RelationshipId == (int)Relationships.Father).Person1.PersonOptionalFields.FirstOrDefault(o => o.OptionalFieldId == (int)OptionalFields.CellPhone).Value,
                    Mother = pc.Person.PersonRelationships.FirstOrDefault(r => r.RelationshipId == (int) Relationships.Mother).Person1.Firstname,
                    MotherEmail = pc.Person.PersonRelationships.FirstOrDefault(r => r.RelationshipId == (int)Relationships.Mother).Person1.Email,
                    MotherCell = pc.Person.PersonRelationships.FirstOrDefault(r => r.RelationshipId == (int)Relationships.Mother).Person1 == null ? null :
                                 pc.Person.PersonRelationships.FirstOrDefault(r => r.RelationshipId == (int)Relationships.Mother).Person1.PersonOptionalFields.FirstOrDefault(o => o.OptionalFieldId == (int)OptionalFields.CellPhone).Value,
                    GroupName = pc.Person.PersonGroups.FirstOrDefault(g=>g.PrimaryGroup).Group.Name

                })
                .Where(c=>c.Father != null || c.Mother !=null);

            return list.ToList().Where(c=>c.Age <= 21);
        }
        public IEnumerable<Child> GetListOfChildren(Person currentPerson)
        {
            //            -- get a list of children (son's or daughters)
            //            -- add their father's details (name, email and cell no)
            //            -- add their mother's details (name, email and cell no)
            //            -- add the age and connect group address and cell no
            //            -- put it in a report

            return new List<Child>
            {
                new Child
                {
                    Firstname = "Gavin",
                    Father = "Peter",
                    Mother = "Nicola"
                },
                new Child
                {
                    Firstname = "Ruth",
                    Mother = "Ang",
                    Father = "Stuart"
                },
                new Child
                {
                    Firstname = "Daniel",
                    Mother = "Ang",
                    Father = "Stuart"
                }
            };
        }
Example #10
0
        public void ShouldGetTheRightNumberOfComments()
        {
            const int personId   = 1;
            const int roleId     = 4;
            var commentsToDelete = _context.Comments.Where(c => c.AboutPersonId == personId).ToList();
            foreach(var commentToDelete in commentsToDelete)
                _context.DeleteObject(commentToDelete);

            _context.SaveChanges();

            ICommentRepository commentsRepo = new CommentRepository();
            var currentPerson = new Person {PersonId = personId, RoleId = roleId};

            const string testComment = "Test Comment";

            var newComment = new CommentDto
            {
                Comment       = testComment,
                AboutPersonId = personId,
                CommentDate   = DateTime.Now
            };

            var commentId = commentsRepo.SaveItem(currentPerson, newComment);

            var sut = commentsRepo.GetListOfComments(currentPerson, personId);

            Assert.That(sut.Count(), Is.EqualTo(1));
        }
        public JqGridData FetchListOfChildren(Person currentPerson, JqGridRequest request, string[] selectedRoles)
        {
            IEnumerable<ChildReportDto> listOfChildren = new List<ChildReportDto>();
            try
            {
                listOfChildren = _childrenReportsRepository.GetListOfChildrenForAChurch(currentPerson, ConversionService.ConvertSelectedRolesToListOfInts(selectedRoles));
            }
            catch (Exception ex)
            {
                _emailService.SendExceptionEmail(ex);
            }

            var totalRecords = listOfChildren.Count();

            switch (request.sidx)
            {
                case "Age":
                    {
                        listOfChildren = request.sord.ToLower() == "asc" ? listOfChildren.OrderBy(p => p.Age).Skip((request.page - 1) * request.rows).Take(request.rows) : listOfChildren.OrderByDescending(p => p.Age).Skip((request.page - 1) * request.rows).Take(request.rows);
                        break;
                    }
                case "Surname":
                    {
                        listOfChildren = request.sord.ToLower() == "asc" ? listOfChildren.OrderBy(p => p.Surname).Skip((request.page - 1) * request.rows).Take(request.rows) : listOfChildren.OrderByDescending(p => p.Surname).Skip((request.page - 1) * request.rows).Take(request.rows);
                        break;
                    }
                case "Firstname":
                    {
                        listOfChildren = request.sord.ToLower() == "asc" ? listOfChildren.OrderBy(p => p.Firstname).Skip((request.page - 1) * request.rows).Take(request.rows) : listOfChildren.OrderByDescending(p => p.Firstname).Skip((request.page - 1) * request.rows).Take(request.rows);
                        break;
                    }
            }

            var childrenGridData = new JqGridData()
            {
                total = (int) Math.Ceiling((float) totalRecords/request.rows),
                page = request.page,
                records = totalRecords,
                rows = (from p in listOfChildren.AsEnumerable()
                    select new JqGridRow()
                    {
                        id = p.PersonId.ToString(),
                        cell = new[]
                        {
                            p.PersonId.ToString(),
                            p.Age.ToString(),
                            p.Firstname,
                            p.Surname,
                            p.CellNo,
                            p.GroupName,
                            p.Father,
                            p.Mother

                        }
                    }).ToArray()
            };

            return childrenGridData;
        }
 IEnumerable<CommentDto> ICommentRepository.GetListOfComments(Person currentPerson, int personId)
 {
     var comments = (from c in Context.Comments
                     from r in c.Role.CanBeReadByRoles
                     where c.AboutPersonId == personId
                     && r.RoleId == currentPerson.RoleId
                     select c);
     return Mapper.Map<IEnumerable<Comment>, IEnumerable<CommentDto>>(comments);
 }
        public IEnumerable<PersonGroupViewModel> GetPersonGroupViewModels(int personId, Person currentPerson)
        {
            var allGroupsInChurch = Context.Groups.Where(g => g.ChurchId == currentPerson.ChurchId);
            var groupsPersonIsIn = GetPersonGroups(personId, currentPerson.ChurchId);
            var primaryGroup = GetPrimaryGroup(personId, currentPerson);

            var returnItems = PopulatePersonGroupViewModels(allGroupsInChurch, primaryGroup, groupsPersonIsIn);
            return returnItems;
        }
 public int SaveItem(Person currentPerson, CommentDto newCommentDto)
 {
     var newComment            = new Comment();
     Mapper.Map(newCommentDto, newComment);
     newComment.MadeByPersonId = currentPerson.PersonId;
     newComment.MadeByRoleId   = currentPerson.RoleId;
     Context.AddToComments(newComment);
     Context.SaveChanges();
     return newComment.CommentId;
 }
 public Church SetNewChurch(Person currentPerson, int churchId)
 {
     if (currentPerson.HasPermission(Permissions.SystemAdministrator))
     {
         var church = _churchRepository.GetChurch(churchId);
         _permissionRepository.SetupPermissions(currentPerson, church, true);
         return church;
     }
     return null;
 }
 public void SavePrimaryGroup(int personId, int groupId, Person currentPerson)
 {
     var personGroup = Context.PersonGroups.FirstOrDefault(pg => pg.PersonId == personId && pg.GroupId == groupId);
     if (personGroup == null) return;
     var allGroups = Context.PersonGroups.Where(pg => pg.PersonId == personId && pg.Group.ChurchId == currentPerson.ChurchId).ToList();
     foreach (var pg in allGroups)
     {
         pg.PrimaryGroup = pg.GroupId == groupId;
     }
     Context.SaveChanges();
 }
 public void GivenAPerson_WhenGettingListOfChildren_ShouldGetChildrenForThatChurch()
 {
     var childReportRepo = new ChildrenReportsRepository();
     var personRunningReport = new Person
     {
         ChurchId = 1,
         PersonId = 1,
         Permissions = new List<int>{4, 40}
     };
     var roles = new List<int> {1, 2, 3, 4, 5};
     var results = childReportRepo.GetListOfChildrenForAChurch(personRunningReport, roles);
 }
 public void SaveOptionalFields(PersonViewModel person, Person personToSave)
 {
     personToSave.Family.HomePhone = person.HomePhone;
     UpdatePersonOptionalField(personToSave, OptionalFields.CellPhone, person.CellPhone);
     UpdatePersonOptionalField(personToSave, OptionalFields.Skype, person.Skype);
     UpdatePersonOptionalField(personToSave, OptionalFields.Twitter, person.Twitter);
     UpdatePersonOptionalField(personToSave, OptionalFields.WorkPhone, person.WorkPhone);
     UpdatePersonOptionalField(personToSave, OptionalFields.HeardAbout, person.HeardAbout);
     UpdatePersonOptionalField(personToSave, OptionalFields.Gender, person.Gender);
     UpdatePersonOptionalField(personToSave, OptionalFields.Occupation, person.Occupation);
     UpdatePersonOptionalField(personToSave, OptionalFields.MaritalStatus, person.MaritalStatus);
     Context.SaveChanges();
 }
 public void RemovePersonFromGroup(Person currentPerson, int personId, int groupId)
 {
     if (!currentPerson.HasPermission(Permissions.RemovePersonFromGroup)) return;
     //Fetch the record
     var personToRemove = (from pg in Context.PersonGroups
                           where pg.PersonId == personId
                                 && pg.GroupId == groupId
                           select pg).FirstOrDefault();
     if (personToRemove == null) return;
     //Remove them
     Context.PersonGroups.DeleteObject(personToRemove);
     Context.SaveChanges();
 }
        public EventDisplayModel FetchEventsToDisplay(Person currentPerson)
        {
            //TODO there must be a better way to do this - on the database
            var events = new EventDisplayModel();
            using (var context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
            {
                var upcomingChurchEvents = (from e in context.OldEvents
                                            join c in context.Churches
                                                on e.Reference equals c.ChurchId
                                            where e.EventDate >= DateTime.Today
                                            && e.TableId == (int)Tables.Church
                                            && c.ChurchId == currentPerson.ChurchId
                                            && (e.EventVisibilityId == (int)EventVisibilities.Church ||
                                                e.EventVisibilityId == (int)EventVisibilities.Public)
                                            select new EventListModel
                                            {
                                                EntityName = c.Name,
                                                Description = e.Description,
                                                Date = e.EventDate
                                            }).ToList();

                var upcomingBirthdays = _birthdayAndAnniversaryRepository.GetBirthdays(currentPerson);

                var upcomingAnniversaries = (from p in context.People
                                             join c in context.PersonChurches
                                                 on p.PersonId equals c.PersonId
                                             join permissions in context.PermissionRoles
                                                 on c.RoleId equals permissions.RoleId
                                             where p.Anniversary.HasValue
                                                   && c.ChurchId == currentPerson.ChurchId
                                                   && (permissions.PermissionId == (int)Permissions.ShowEvents)
                                             select new EventListModel
                                             {
                                                 EntityName = p.Firstname + " " + p.Family.FamilyName,
                                                 Description = "Anniversary",
                                                 Date = p.Anniversary.Value
                                             }).ToList();

                AddBirthdays(upcomingBirthdays);
                AddAnniversaries(upcomingAnniversaries);

                var upcomingEvents = new List<EventListModel>(upcomingChurchEvents);
                upcomingEvents.AddRange(upcomingBirthdays);
                upcomingEvents.AddRange(upcomingAnniversaries);

                events.UpcomingEvents = SortAndLimitTo20(upcomingEvents);
                events.PastEvents = null;
                return events;

            }
        }
        public void GivenAnSmsLongerThan160Characters_WhenSendSmsesIsCalled_MultipleSmsesAreSent()
        {
            var messageRepository = MockRepository.GenerateStub<IMessageRepository>();
            var messageRecepientRepository = MockRepository.GenerateStub<IMessageRecepientRepository>();
            var personRepository = MockRepository.GenerateStub<IPersonRepository>();
            var httpPostService = MockRepository.GenerateStub<IHttpPostService>();
            httpPostService.Expect(h => h.HttpSend(string.Empty)).IgnoreArguments().Return("success").Repeat.Any();
            var sut = new SmsSender(messageRepository, messageRecepientRepository, personRepository, httpPostService);
            var currentPerson = new Person {Church = new Church {Country = "South Africa"}};

            var cellNos = new List<string> {"0826527871"};
            var longSms = "012345789012345789012345789012345789012345789012345789012345789012345789012345789012345789012345789012345789012345789012345789012345789012345789012345789012345789012345789012345789";
            sut.SendSmses(longSms, cellNos, "petermunnings", "sandton2000", currentPerson);
            httpPostService.AssertWasCalled(x => x.HttpSend(Arg<string>.Is.Anything), options => options.Repeat.Once());
        }
 public IEnumerable<RoleViewModel> FetchSecurityRoles(Person currentPerson)
 {
     List<RoleViewModel> roles;
     if (currentPerson.HasPermission(common.Permissions.SystemAdministrator))
         roles = (from r in Context.Roles
                  where r.ChurchId == currentPerson.ChurchId
                  select new RoleViewModel { RoleId = r.RoleId, Name = r.Name }).ToList();
     else
         roles = (from r in Context.Roles
                  from canSetRole in r.CanBeSetByRoles
                  where r.ChurchId == currentPerson.ChurchId
                        && canSetRole.RoleId == currentPerson.RoleId
                  select new RoleViewModel { RoleId = r.RoleId, Name = r.Name }).ToList();
     return roles;
 }
        public JqGridData FetchPeopleToBeRemindedJQGrid(Person currentPerson, string reminderType, JqGridRequest request)
        {
            var people = _reminderRepository.FetchPeopleToBeReminded(currentPerson.ChurchId, reminderType);
            var totalRecords = people.Count();
            var sort = "Surname";
            var sortList = request.sidx.Split(',');
            if (sortList.Count() > 1)
                sort = sortList[1].Trim();
            switch (sort)
            {
                case "Firstname":
                    {
                        people = request.sord.ToLower() == "asc" ? people.OrderBy(p => p.Firstname) : people.OrderByDescending(p => p.Firstname);
                        break;
                    }
                case "Surname":
                    {
                        people = request.sord.ToLower() == "asc" ? people.OrderBy(p => p.Surname) : people.OrderByDescending(p => p.Surname);
                        break;
                    }
            }

            if (request.rows > 0)
                people = people.Skip((request.page - 1) * request.rows).Take(request.rows);
            else
                request.page = 1;

            var peopleGridData = new JqGridData()
            {
                total = request.rows > 0 ? (int) Math.Ceiling((float) totalRecords/(float) request.rows) : 1,
                page = request.page,
                records = totalRecords,
                rows = (from p in people.AsEnumerable()
                    select new JqGridRow()
                    {
                        id = p.PersonId.ToString(),
                        cell = new[]
                        {
                            p.PersonId.ToString(),
                            p.Firstname,
                            p.Surname,
                            p.Email
                        }
                    }).ToArray()
            };

            return peopleGridData;
        }
Example #24
0
        public void CanSaveNewComment()
        {
            var commentRepository = MockRepository.GenerateStub<ICommentRepository>();

            ICommentService commentService = new CommentService(commentRepository);
            var currentPerson = new Person();
            var newCommentDto = new CommentDto();
            const int commentId = 1;
            commentRepository
                .Expect(c => c.SaveItem(currentPerson, newCommentDto))
                .Return(commentId);

            var sut = commentService.SaveComment(currentPerson, newCommentDto);

            Assert.That(sut, Is.EqualTo(commentId));
        }
Example #25
0
        public void ShouldGetRightNoOfCommentsWithMaxCommentsSet()
        {
            var commentRepository = MockRepository.GenerateStub<ICommentRepository>();

            ICommentService commentService = new CommentService(commentRepository);
            const int personId = 1;
            var currentPerson = new Person();
            var listOfComments = new List<CommentDto> { new CommentDto(), new CommentDto(), new CommentDto(), new CommentDto() };
            commentRepository
                .Expect(c => c.GetListOfComments(currentPerson, personId))
                .Return(listOfComments);

            var sut = commentService.GetListOfComments(currentPerson, personId, 2);

            Assert.That(sut.Count(), Is.EqualTo(2));
        }
 public IList<EventListModel> GetBirthdays(Person currentPerson)
 {
     return (from p in Context.People
         join c in Context.PersonChurches
             on p.PersonId equals c.PersonId
         join permissions in Context.PermissionRoles
             on c.RoleId equals permissions.RoleId
         where p.DateOfBirth.HasValue
               && c.ChurchId == currentPerson.ChurchId
               && (permissions.PermissionId == (int)Permissions.ShowEvents)
         select new EventListModel
         {
             EntityName = p.Firstname + " " + p.Family.FamilyName,
             Description = "Birthday",
             Date = p.DateOfBirth.Value
         }).ToList();
 }
 private void UpdatePersonOptionalField(Person person, OptionalFields optionalField, string value)
 {
     var personOptionalField = person.PersonOptionalFields.FirstOrDefault(c => c.OptionalFieldId == (int)optionalField);
     if (personOptionalField == null)
     {
         personOptionalField = new PersonOptionalField
         {
             OptionalFieldId = (int)optionalField,
             Created = DateTime.Now,
             Changed = DateTime.Now
         };
         person.PersonOptionalFields.Add(personOptionalField);
     }
     if (personOptionalField.Value != (value ?? string.Empty))
         personOptionalField.Changed = DateTime.Now;
     personOptionalField.Value = value ?? string.Empty;
 }
Example #28
0
        public string SendSmses(string smsText, IEnumerable<string> cellPhoneNos, string username, string password, Person currentPerson)
        {
            //Must remove the &
            smsText = smsText.Replace("&", "and");
            var intCellPhoneNos = ConvertCellNosToInternationalFormat(cellPhoneNos, currentPerson.Church.Country);

            var returnText = string.Empty;
            var completedNos = 0;
            const int reasonableNo = 20;
            while (completedNos < intCellPhoneNos.Count)
            {
                var shortListOfInternationalFormattedNos = intCellPhoneNos.Skip(completedNos).Take(reasonableNo);
                returnText += string.Format(" Batch {0}: {1}    ---", (completedNos/reasonableNo)+1, SendToListOfNumbers(smsText, username, password, shortListOfInternationalFormattedNos, currentPerson.PersonId, currentPerson.ChurchId));
                completedNos += reasonableNo;
            }
            return returnText;
        }
        public void SavePersonChurchRole(PersonViewModel person, Person currentPerson, Person personToSave)
        {
            if (person.RoleId == 0)
                return;

            var personRole = Context.PersonChurches.FirstOrDefault(pr => (pr.Role.ChurchId == currentPerson.ChurchId) && (pr.PersonId == personToSave.PersonId));
            if (personRole == null)
            {
                SavePersonRole(personToSave, person.RoleId);
                return;
            }

            if (personRole.RoleId == person.RoleId)
                return;

            Context.DeleteObject(personRole);
            SavePersonRole(personToSave, person.RoleId);
        }
        public static List<string> FetchGroupAddresses(Person currentPerson, int groupId, List<int> selectedIds, bool selectedOnly)
        {
            List<string> addresses = new List<string>();
            using (oikonomosEntities context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
            {
                List<PersonViewModel> people = selectedOnly ? FetchPeopleInGroup(currentPerson, groupId, context, selectedIds).ToList() : FetchPeopleInGroup(currentPerson, groupId, context).ToList();

                foreach (PersonViewModel person in people)
                {
                    if (person.Email != null && person.Email != string.Empty)
                    {
                        addresses.Add(person.Email);
                    }
                }
            }

            return addresses;
        }