コード例 #1
0
 public AllLinkViewModel()
 {
     Bag    = new Bagsmvc();
     Person = new Peoplemvc();
     Link   = new Linksmvccore();
     People = new List <Peoplemvc>();
     Bags   = new List <Bagsmvc>();
     Links  = new List <Linksmvccore>();
 }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("PersonNumber,PrimarySiteName,SecondarySiteName,PrimarySite,SecondarySite,FirstName,MiddleName,LastName,Country,IsoCountry,PrimaryEmail,SecondaryEmail,TertiaryEmail,Collector,Donor,Swapper,Seller,StarterKit,Comments")] Peoplemvc peoplemvc)
        {
            if (ModelState.IsValid)
            {
                _context.Add(peoplemvc);
                await _context.SaveChangesAsync();

                //await _cache.AddItem(peoplemvc, _context.People);
                await _cache.GetFromTable(true, _context.People);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(peoplemvc));
        }
コード例 #3
0
        public async Task <IActionResult> Details(int?id)
        {
            Peoplemvc person = new Peoplemvc();

            if (id == null)
            {
                return(NotFound());
            }

            // Get all people, then get the person that matches id
            var allpeople = await _cache.GetFromTable(_context.People);

            person = allpeople.FirstOrDefault(m => m.PersonNumber == id);

            if (person == null)
            {
                return(NotFound());
            }

            return(View(person));
        }
コード例 #4
0
        /* This will be called by both httpget and httppost of the index action */
        public async Task <List <Peoplemvc> > GetPeople()
        {
            // Start with a new list of people
            List <Peoplemvc>    peoplemvc = new List <Peoplemvc>();
            List <Linksmvccore> links     = new List <Linksmvccore>();

            // Get all people from the cache
            var allpeople = await _cache.GetFromTable(_context.People);

            // List<Peoplemvc> ap = await _context.People.Include(x => x.Links).ToListAsync();

            // Here's a placeholder person for when nobody fits search criteria
            Peoplemvc emptyperson = new Peoplemvc
            {
                FirstName = "No Matching Records Found"
            };

            // Keep track of whether someone wants everyone or no-one.
            bool EmptyRequest = true;
            bool FullRequest  = FormData != null && FormData["AllPeople"] == "on" ? true : false;

            // If somethine was selected, we no longer have an empty query
            if ((FormData != null) &&
                (FormData["HasWebsite"] == "on" ||
                 FormData["PersonName"] != "" ||
                 FormData["Detail"] != "" ||
                 FormData["Country"] != "" ||
                 FormData["AllPeople"] == "on" ||
                 FormData["Collector"] == "on" ||
                 FormData["Donor"] == "on" ||
                 FormData["Swapper"] == "on" ||
                 FormData["Seller"] == "on" ||
                 FormData["StarterKit"] == "on"
                ))
            {
                EmptyRequest = false;
            }

            // If nobody matches the criteria, return a blank informative message, otherwise return a list sorted on last name
            if (EmptyRequest)
            {
                peoplemvc.Add(emptyperson);
            }
            else
            {
                // Sort everyone by lastname.  No reason to sort any other way for people
                peoplemvc = allpeople.OrderBy(x => x.LastName).ToList();
            }

            // Not Full Request, so filter people records
            if (!FullRequest && FormData != null)
            {
                if (FormData["HasWebsite"] == "on")
                {
                    peoplemvc = peoplemvc.FindAll(x => x.PrimarySite != null && x.PrimarySite != "").ToList();
                    //                    peoplemvc = peoplemvc.Where(x => x.PrimarySite != null).ToList();
                }

                if (FormData["Collector"] == "on")
                {
                    peoplemvc = peoplemvc.FindAll(x => x.Collector == 1).ToList();
                }

                if (FormData["Donor"] == "on")
                {
                    peoplemvc = peoplemvc.FindAll(x => x.Donor == 1).ToList();
                }

                if (FormData["Swapper"] == "on")
                {
                    peoplemvc = peoplemvc.FindAll(x => x.Swapper == 1).ToList();
                }

                if (FormData["Seller"] == "on")
                {
                    peoplemvc = peoplemvc.FindAll(x => x.Seller == 1).ToList();
                }

                if (FormData["StarterKit"] == "on")
                {
                    peoplemvc = peoplemvc.FindAll(x => x.StarterKit == 1).ToList();
                }

                if (FormData["Country"] != "")
                {
                    peoplemvc = peoplemvc.FindAll(x => x.IsoCountry == FormData["Country"]).ToList();
                }

                // Search for a name match
                if (FormData["PersonName"] != "")
                {
                    peoplemvc = peoplemvc
                                .Where(x =>
                                       (x.FirstName != null && x.FirstName.Contains(FormData["PersonName"], StringComparison.OrdinalIgnoreCase)) ||
                                       (x.MiddleName != null && x.MiddleName.Contains(FormData["PersonName"], StringComparison.OrdinalIgnoreCase)) ||
                                       (x.LastName != null && x.LastName.Contains(FormData["PersonName"], StringComparison.OrdinalIgnoreCase))
                                       ).ToList();
                }

                // Search for a detail match
                if (FormData["Detail"] != "")
                {
                    peoplemvc = peoplemvc
                                .Where(x => x.Comments != null && x.Comments.Contains(FormData["Detail"], StringComparison.OrdinalIgnoreCase))
                                .ToList();
                }
            }


            return(peoplemvc);
        }