Exemplo n.º 1
0
        // GET: ParentController
        public ActionResult Index()
        {
            var identityUserId = User.FindFirstValue(ClaimTypes.NameIdentifier);
            //var parent = _repo.Parent.FindByCondition(p => p.IdentityUserId == identityUserId).FirstOrDefault();
            var parent = _repo.Parent.GetParent(identityUserId);

            if (parent == null)
            {
                return(RedirectToAction("Create"));
            }

            ParentIndexViewModel indexViewModel = new ParentIndexViewModel();

            indexViewModel.Parent = parent;
            var kids = _repo.Kid.FindByCondition(k => k.ParentId == parent.ParentId).ToList();

            indexViewModel.Kids = kids;

            //TODO index view logic - home screen

            return(View(indexViewModel));
        }
Exemplo n.º 2
0
        public ActionResult SearchResults(ParentIndexViewModel parentIndexView)
        {
            var           searchingParent   = _repo.Parent.GetParent(parentIndexView.Parent.IdentityUserId);
            List <Parent> AllParentsInZip   = new List <Parent>();
            List <Kid>    AllFoundKidsInZip = new List <Kid>();
            List <Parent> AllFoundParents   = new List <Parent>();

            //default behavior is zip searches for local zip code parents

            //search for parents by zip location
            var foundByZip = _repo.Parent.FindByCondition(p => p.LocationZip == parentIndexView.ZipSearch && p.ParentId != searchingParent.ParentId).ToList();

            AllParentsInZip.AddRange(foundByZip);



            //Find every kid in zip (use local parents)
            foreach (Parent parent in AllParentsInZip)
            {
                var foundKidsOfParent = _repo.Kid.FindByCondition(k => k.ParentId == parent.ParentId).ToList();
                AllFoundKidsInZip.AddRange(foundKidsOfParent);
            }



            //check name input - if not null perform search
            if (parentIndexView.NameSearch != null)
            {
                //search for parents by first name and last name and build a list of distinct results
                var foundByFirstName = AllParentsInZip.Where(p => p.FirstName.Contains(parentIndexView.NameSearch)).ToList();
                var foundByLastName  = AllParentsInZip.Where(p => p.LastName.Contains(parentIndexView.NameSearch)).ToList();

                var foundByName = foundByFirstName.Union(foundByLastName).ToList();
                //add found parents by name to AllFoundParents
                AllFoundParents.AddRange(foundByName);
            }

            //age range
            if (parentIndexView.AgeLow != null || parentIndexView.AgeHigh != null)
            {
                List <Parent> foundParentsByKidAges = new List <Parent>();
                if (parentIndexView.AgeLow != null)
                {
                    var foundKidsAboveLower = AllFoundKidsInZip.Where(k => k.Age >= parentIndexView.AgeLow);
                    foreach (Kid kid in foundKidsAboveLower)
                    {
                        var parent = _repo.Parent.GetParentDetails(kid.ParentId);
                        foundParentsByKidAges.Add(parent);
                    }
                }
                if (parentIndexView.AgeHigh != null)
                {
                    var foundKidsBelowUpper = AllFoundKidsInZip.Where(k => k.Age <= parentIndexView.AgeHigh);
                    foreach (Kid kid in foundKidsBelowUpper)
                    {
                        var parent = _repo.Parent.GetParentDetails(kid.ParentId);
                        foundParentsByKidAges.Add(parent);
                    }
                }
                AllFoundParents.AddRange(foundParentsByKidAges);
            }

            //health - immunizations
            if (parentIndexView.ImmunizedSearch == true)
            {
                var foundKidsImmunized = _repo.Kid.FindByCondition(k => k.Immunized == true);
                foreach (Kid kid in foundKidsImmunized)
                {
                    var parent = _repo.Parent.GetParentDetails(kid.ParentId);
                    AllFoundParents.Add(parent);
                }
            }

            //health - wears a mask
            if (parentIndexView.WearsMaskSearch == true)
            {
                var foundKidsWearsMask = _repo.Kid.FindByCondition(k => k.WearsMask == true);
                foreach (Kid kid in foundKidsWearsMask)
                {
                    var parent = _repo.Parent.GetParentDetails(kid.ParentId);
                    AllFoundParents.Add(parent);
                }
            }

            if (AllFoundParents.Count == 0)
            {
                AllFoundParents = AllParentsInZip;
            }



            AllFoundParents = AllFoundParents.GroupBy(p => p.ParentId).Select(p => p.Last()).ToList();
            foreach (Parent parent in AllFoundParents)
            {
                var kidsOfParents = _repo.Kid.FindByCondition(k => k.ParentId == parent.ParentId).ToList();
                parent.Kids = kidsOfParents;
            }
            ViewBag.FoundFriends  = FoundFriends(searchingParent.ParentId, AllFoundParents, CurrentParentFriendsList(searchingParent));
            ViewBag.FoundRequests = FoundRequests(searchingParent.ParentId, AllFoundParents, CurrentParentRequestedList(searchingParent));
            //var CurrentParentFriendsList = _repo.Friendship.FindByCondition(f => (f.ParentOneId == searchingParent.ParentId || f.ParentTwoId == searchingParent.ParentId) && f.FriendshipConfirmed == true).ToList();
            //var CurrentParentRequestedList = _repo.Friendship.FindByCondition(f => (f.ParentOneId == searchingParent.ParentId || f.ParentTwoId == searchingParent.ParentId) && f.FriendshipRequest == true && f.FriendshipConfirmed == false).ToList();
            //var FoundFriends = FindCurrentFriends(searchingParent.ParentId, AllFoundParents, CurrentParentFriendsList);
            //var FoundRequests = FindCurrentFriends(searchingParent.ParentId, AllFoundParents, CurrentParentRequestedList);
            //ViewBag.FoundFriends = FoundFriends;
            //ViewBag.FoundRequests = FoundRequests;
            return(View(AllFoundParents));
        }