Ejemplo n.º 1
0
        private IQueryable <CmsData.Contact> ApplySearch()
        {
            var query = from c in Db.Contacts select c;

            if (ContacteeName.HasValue())
            {
                query = from c in query
                        where c.contactees.Any(p => p.person.Name.Contains(ContacteeName))
                        select c;
            }
            if (ContactorName.HasValue())
            {
                query = from c in query
                        where c.contactsMakers.Any(p => p.person.Name.Contains(ContactorName))
                        select c;
            }
            if (StartDate.HasValue)
            {
                query = query.Where(c => c.ContactDate >= StartDate);
                if (EndDate.HasValue)
                {
                    EndDate = EndDate.Value.AddHours(+24);
                }
                else
                {
                    EndDate = StartDate.Value.AddHours(+24);
                }
                query = query.Where(c => c.ContactDate < EndDate);
            }
            else if (EndDate.HasValue)
            {
                EndDate = EndDate.Value.AddHours(+24);
                query   = query.Where(c => c.ContactDate < EndDate);
            }
            if (ReasonCode.HasValue && ReasonCode > 0)
            {
                query = query.Where(c => c.ContactReasonId == ReasonCode);
            }
            if (TypeCode.HasValue && TypeCode > 0)
            {
                query = query.Where(c => c.ContactTypeId == TypeCode);
            }
            if (MinistryCode.HasValue && MinistryCode > 0)
            {
                query = query.Where(c => c.MinistryId == MinistryCode);
            }
            return(query);
        }
Ejemplo n.º 2
0
        private IQueryable <CmsData.Contact> FetchContacts()
        {
            if (contacts != null)
            {
                return(contacts);
            }

            var db = DbUtil.Db;

            IQueryable <int> ppl = null;

            if (Util2.OrgMembersOnly)
            {
                ppl = db.OrgMembersOnlyTag2().People(db).Select(pp => pp.PeopleId);
            }
            else if (Util2.OrgLeadersOnly)
            {
                ppl = db.OrgLeadersOnlyTag2().People(db).Select(pp => pp.PeopleId);
            }

            contacts = DbUtil.Db.Contacts.AsQueryable();

            if (ppl != null && Util.UserPeopleId != null)
            {
                contacts = from c in contacts
                           where c.contactsMakers.Any(cm => cm.PeopleId == Util.UserPeopleId.Value)
                           select c;
            }

            if (ContacteeName.HasValue())
            {
                contacts = from c in contacts
                           where c.contactsMakers.Any(p => p.person.Name.Contains(ContacteeName))
                           select c;
            }

            if (ContactorName.HasValue())
            {
                contacts = from c in contacts
                           where c.contactsMakers.Any(p => p.person.Name.Contains(ContactorName))
                           select c;
            }

            if (CreatedBy.HasValue())
            {
                var pid = CreatedBy.ToInt();
                if (pid > 0)
                {
                    contacts = from c in contacts
                               where DbUtil.Db.Users.Any(uu => c.CreatedBy == uu.UserId && uu.Person.PeopleId == pid)
                               select c;
                }
                else
                {
                    contacts = from c in contacts
                               where DbUtil.Db.Users.Any(uu => c.CreatedBy == uu.UserId && uu.Username == CreatedBy)
                               select c;
                }
            }

            DateTime startDateRange;
            DateTime endDateRange;

            if (StartDate.HasValue)
            {
                startDateRange = StartDate.Value;
                if (EndDate.HasValue)
                {
                    endDateRange = EndDate.Value.AddHours(+24);
                }
                else
                {
                    endDateRange = DateTime.Today;
                }
            }
            else if (EndDate.HasValue)
            {
                startDateRange = DateTime.Parse("01/01/1800");
                endDateRange   = EndDate.Value.AddHours(+24);
            }
            else
            {
                startDateRange = DateTime.Parse("01/01/1800");
                endDateRange   = Util.Now.Date.AddHours(+24);
            }

            contacts = from c in contacts
                       where c.ContactDate >= startDateRange && c.ContactDate < endDateRange
                       select c;

            if ((ContactReason ?? 0) != 0)
            {
                contacts = from c in contacts
                           where c.ContactReasonId == ContactReason
                           select c;
            }

            if ((ContactType ?? 0) != 0)
            {
                contacts = from c in contacts
                           where c.ContactTypeId == ContactType
                           select c;
            }

            if ((Ministry ?? 0) != 0)
            {
                contacts = from c in contacts
                           where c.MinistryId == Ministry
                           select c;
            }

            switch (Result)
            {
            case "Gospel Shared":
                contacts = from c in contacts
                           where c.GospelShared == true
                           select c;
                break;

            case "Attempted/Not Available":
                contacts = from c in contacts
                           where c.NotAtHome == true
                           select c;
                break;

            case "Left Note Card":
                contacts = from c in contacts
                           where c.LeftDoorHanger == true
                           select c;
                break;

            case "Left Message":
                contacts = from c in contacts
                           where c.LeftMessage == true
                           select c;
                break;

            case "Contact Made":
                contacts = from c in contacts
                           where c.ContactMade == true
                           select c;
                break;

            case "Prayer Request Received":
                contacts = from c in contacts
                           where c.PrayerRequest == true
                           select c;
                break;

            case "Gift Bag Given":
                contacts = from c in contacts
                           where c.GiftBagGiven == true
                           select c;
                break;
            }

            return(contacts);
        }