예제 #1
0
        /// <summary>
        /// adds pet to favorite table database
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="petID"></param>
        /// <returns></returns>
        public async Task <IActionResult> AddFavorites(int userID, int petID)
        {
            Favorite favorite = await _context.Favorites.FirstOrDefaultAsync(x => x.UserID == userID && x.PetID == petID);

            if (favorite == null)
            {
                Favorite FavoritePet = new Favorite()
                {
                    UserID = userID,
                    PetID  = petID,
                };
                _context.Favorites.Add(FavoritePet);
                await _context.SaveChangesAsync();
            }

            return(RedirectToAction("Details", "Pet", new { id = petID }));
        }
예제 #2
0
 /// <summary>
 /// Saves userprofile to database
 /// </summary>
 /// <param name="profile">user profile</param>
 /// <returns></returns>
 public async Task CreateProfile(Profile profile)
 {
     _context.Profiles.Add(profile);
     await _context.SaveChangesAsync();
 }
예제 #3
0
 /// <summary>
 /// creates a favorite and adds to database
 /// </summary>
 /// <param name="favorite"></param>
 /// <returns></returns>
 public async Task CreateFavorite(Favorite favorite)
 {
     _context.Favorites.Add(favorite);
     await _context.SaveChangesAsync();
 }