Ejemplo n.º 1
0
 private IQueryable<contact> SearchContacts(ContactSearch search)
 {
     return dbContext.contacts.Where(x => ((string.IsNullOrEmpty(search.LastName) && string.IsNullOrEmpty(search.FirstName) && string.IsNullOrEmpty(search.Organization) && string.IsNullOrEmpty(search.City) && string.IsNullOrEmpty(search.Zip) &&
                     string.IsNullOrEmpty(search.Address) && string.IsNullOrEmpty(search.Notes)) ||
                     x.lastname.StartsWith(search.LastName) || x.firstname.StartsWith(search.FirstName) || x.organization.StartsWith(search.Organization) || x.organization_alt.StartsWith(search.Organization) ||
                     x.city.StartsWith(search.City) || x.city_alt.StartsWith(search.City) || x.zip.StartsWith(search.Zip) || x.zip_alt.StartsWith(search.Zip) || x.addressline1.Contains(search.Address) ||
                     x.addressline1_alt.Contains(search.Address) || x.notes.Contains(search.Notes))
         // Cat search
                     && (search.SelectedCats.Count() == 0 || x.contact_contact_category.Where(c => search.SelectedCats.Contains(c.contact_category_id)).Count() > 0)
         // Follow up search
                     && (!search.NeedsFollowUp || x.contact_shipment.Where(s => s.should_followup).Count() > 0)
         // Sub end search
                     && (!search.Sub_enddate.HasValue || x.sub_enddate == search.Sub_enddate.Value)
         // Always Search
                     && (string.IsNullOrEmpty(search.TypeAlways) || ((search.TypeAlways != "Galleys" || x.galley_all) &&
                         (search.TypeAlways != "Review" || x.review_all) &&
                         (search.TypeAlways != "Desk" || x.desk_all) &&
                         (search.TypeAlways != "Comp" || x.comp_all)))
         // Possible Search
                     && (string.IsNullOrEmpty(search.TypePossible) || ((search.TypePossible != "Galleys" || x.galley_pos) &&
                         (search.TypePossible != "Review" || x.review_pos) &&
                         (search.TypePossible != "Desk" || x.desk_pos) &&
                         (search.TypePossible != "Comp" || x.comp_pos))));
 }
Ejemplo n.º 2
0
        public List<ContactCsvLine> SearchCsv(ContactSearch search)
        {
            if (!search.HasCriteria())
                return new List<ContactCsvLine>();

            var contacts = SearchContacts(search)
               .Select(c => new ContactCsvLine
               {
                   Id = c.id,
                   FirstName = c.firstname,
                   LastName = c.lastname,
                   AddressLine1 = c.is_primary ? c.addressline1 : c.addressline1_alt,
                   AddressLine2 = c.is_primary ? c.addressline2 : c.addressline2_alt,
                   State = c.is_primary ? c.state : c.state_alt,
                   Zip = c.is_primary ? c.zip : c.zip_alt,
                   Country = c.is_primary ? c.country : c.country_alt,
                   Title = c.is_primary ? c.title : c.title_alt,
                   City = c.is_primary ? c.city : c.city_alt,
                   Organization = c.is_primary ? c.organization : c.organization_alt,
                   SubNumber = c.is_subscriber ? c.sub_number : null,
                   PrimaryEmail = c.email1,
                   AltEmail = c.email2
               }).ToList();

            foreach (var c in contacts)
            {
                c.SubscriberNumber = c.SubNumber.HasValue ? c.SubNumber.Value.ToString() : "";
                List<string> titlesToFollowUp = dbContext.shipments.Where(x => x.contact_id == c.Id && x.should_followup).Select(s =>  s.shipment_title.title1).ToList();

                if(titlesToFollowUp.Count > 0)
                    c.TitlesForFollowUp = string.Join(", ", titlesToFollowUp.ToArray());
            }
            return contacts;
        }
Ejemplo n.º 3
0
        public FileResult CreateCsv(ContactSearch search)
        {
            List<ContactCsvLine> items = data.SearchCsv(search);

            return CreateCsv(items);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// TODO: DONT FORGET SEARCH CSV!
        /// </summary>
        /// <param name="search"></param>
        /// <returns></returns>
        public IEnumerable<ContactDetails> Search(ContactSearch search)
        {
            if (!search.HasCriteria())
                return new List<ContactDetails>();

            return SearchContacts(search)
               .Select(s => new ContactDetails
               {
                   City = s.is_primary ? s.city : s.city_alt,
                   DisplayName = s.lastname + ", " + s.firstname,
                   Organization = s.is_primary ? s.organization : s.organization_alt,
                   Id = s.id
               });
        }
Ejemplo n.º 5
0
        public ActionResult Index(ContactSearch search, string btnValue)
        {
            search.LoadCats(adminData.GetAllContactCats());
            if (btnValue == "export")
                return CreateCsv(search);

            var results = data.Search(search);
            search.Results = results;
            return View(search);
        }