Beispiel #1
0
        public async Task <IActionResult> IndexForContact(int contactId)
        {
            //Get userId and instantiate View Model
            TasksAndPetsVM tasksAndPets = new TasksAndPetsVM();

            ViewBag.contactId = contactId;

            //Gets current user's contacts and passes it to view
            var userId        = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            var currentUserId = await _repo.PetOwner.FindOwnerId(userId);

            var contacts = await _repo.ContactsJxn.FindAllContacts(currentUserId);

            ViewBag.Contacts = contacts;

            //Find owner and set property on View Model
            var contact = await _repo.PetOwner.FindOwnerWithId(contactId);

            tasksAndPets.PetOwner = contact;

            //Find all of the owner's pets and set prop on View Model
            var petIds = await _repo.PetOwnership.FindAllPets(contact.PetOwnerId);

            tasksAndPets.CurrentUsersPets = await FindOwnersPets(petIds);

            //Find all tasks and set prop on View Model
            tasksAndPets.CurrentUsersTasks = await FindOwnersTasks(tasksAndPets.CurrentUsersPets);

            tasksAndPets.CurrentUsersTasks = FilterTasks(tasksAndPets.CurrentUsersTasks);

            return(View(tasksAndPets));
        }
Beispiel #2
0
        // GET: PetOwners
        public async Task <IActionResult> Index()
        {
            //Get userId and instantiate View Model
            TasksAndPetsVM tasksAndPets = new TasksAndPetsVM();
            string         userId       = this.User.FindFirstValue(ClaimTypes.NameIdentifier);

            //Find owner and set property on View Model
            var owner = await _repo.PetOwner.FindOwner(userId);

            if (owner == null)
            {
                return(RedirectToAction("Create"));
            }
            tasksAndPets.PetOwner = owner;

            //Find all of the owner's pets and set prop on View Model
            var petIds = await _repo.PetOwnership.FindAllPets(owner.PetOwnerId);

            tasksAndPets.CurrentUsersPets = await FindOwnersPets(petIds);

            //Set recommendations for each pet
            await SetPetsRecommendations(tasksAndPets.CurrentUsersPets, tasksAndPets.RecommendationsWithoutType);

            //Find all tasks and set prop on View Model
            tasksAndPets.CurrentUsersTasks = await FindOwnersTasks(tasksAndPets.CurrentUsersPets);

            tasksAndPets.CurrentUsersTasks = FilterTasks(tasksAndPets.CurrentUsersTasks);

            //Find all contacts of user and set prop on View Model
            tasksAndPets.Contacts = await GetContacts(owner.PetOwnerId);

            //Find pet stores
            tasksAndPets.NearbyPetStores = await ShowNearbyPetStores(owner.PetOwnerId);

            //Find vets
            tasksAndPets.NearbyVets = await ShowNearbyVets(owner.PetOwnerId);

            //Send Daily Reminder
            if (DateTime.Now.Hour > 12 && owner.ResetDay != DateTime.Now.Day)
            {
                _twilioAPI.SendSMSReminder(owner, tasksAndPets.CurrentUsersTasks);
                owner.ResetDay = DateTime.Now.Day;
                _repo.PetOwner.EditPetOwner(owner);
                await _repo.Save();
            }

            ViewBag.googleAPIKey = API_Key.googleAPIKey;
            return(View(tasksAndPets));
        }