示例#1
0
        public async Task <UserCocktail> UpdateUserCocktail(UserCocktail updatedUserCocktail, int id)
        {
            string userId = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            var    model  = await _userCocktailsService.Update(updatedUserCocktail, id, userId);

            return(model);
        }
示例#2
0
        public async Task <UserCocktail> AddNewUserCocktail(UserCocktail newUserCocktail)
        {
            string userId = User.FindFirst(ClaimTypes.NameIdentifier).Value;

            newUserCocktail.UserId = userId;
            var model = await _userCocktailsService.AddNew(newUserCocktail);

            return(model);
        }
        public bool AddToPreferences(int id)
        {
            Cocktail     cocktail     = _context.Cocktails.Find(id);
            UserCocktail userCocktail =
                new UserCocktail
            {
                User     = _user,
                Cocktail = cocktail
            };

            _context.UserCocktails.Add(userCocktail);
            _user.SavedCocktails.Add(userCocktail);
            return(_context.SaveChanges() == 1);
        }
示例#4
0
        public async Task FavoriteCocktailAsync(int userId, int cocktailId)
        {
            var user = await FindUserByIdAsync(userId);

            var cocktail = await cService.FindCocktailByIdAsync(cocktailId);

            var userCocktail = new UserCocktail()
            {
                UserId       = userId,
                CocktailId   = cocktailId,
                User         = user,
                Cocktail     = cocktail,
                UserUserName = user.UserName,
                CocktailName = cocktail.Name
            };

            dbContext.UserCocktail.Add(userCocktail);
            await dbContext.SaveChangesAsync();
        }
示例#5
0
        public async Task <int> DeleteUserCocktail(UserCocktail userCocktail)
        {
            string userId = User.FindFirst(ClaimTypes.NameIdentifier).Value;

            return(await _userCocktailsService.Delete(userCocktail, userId));
        }