Ejemplo n.º 1
0
        public async Task AddCocktailCommentAsync(int id, string createComment, int userId)
        {
            if (await dbContext.CocktailComment.AnyAsync(p => (p.UserId == userId && p.CocktailId == id)))
            {
                var existingComment = await dbContext.CocktailComment.FirstOrDefaultAsync(p => (p.UserId == userId && p.CocktailId == id));

                existingComment.Comment   = createComment;
                existingComment.CreatedOn = DateTime.Now;
                await dbContext.SaveChangesAsync();
            }
            else
            {
                var user = await FindUserByIdAsync(userId);

                var cocktail = await cService.FindCocktailByIdAsync(id);

                var cocktailComment = new CocktailComment()
                {
                    User         = user,
                    Cocktail     = cocktail,
                    UserName     = user.UserName,
                    CocktailName = cocktail.Name,
                    Comment      = createComment,
                    CreatedOn    = DateTime.Now
                };
                await dbContext.CocktailComment.AddAsync(cocktailComment);

                await dbContext.SaveChangesAsync();
            }
        }
        public async Task <IActionResult> CocktailDetails(string cocktailId)
        {
            var Cocktail = await cocktailService.FindCocktailByIdAsync(int.Parse(cocktailId));

            var vm = new CocktailViewModel(Cocktail);

            return(View("CocktailDetails", vm));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Edit(string cocktailId)
        {
            var id       = int.Parse(cocktailId);
            var cocktail = await cocktailService.FindCocktailByIdAsync(id);

            var ingredients = await iService.GetIngredientsByCocktailAsync(id);

            var vm = new EditCocktailViewModel(cocktail, ingredients);

            return(View("EditCocktail", vm));
        }
Ejemplo n.º 4
0
        public async Task AddCocktailBarAsync(int barId, int cocktailId)
        {
            var bar = await FindBarByIdAsync(barId);

            var cocktail = await cocktailService.FindCocktailByIdAsync(cocktailId);

            if (bar != null && cocktail != null)
            {
                var barCocktail = new BarCocktail()
                {
                    Bar          = bar,
                    Cocktail     = cocktail,
                    CocktailName = cocktail.Name,
                    BarName      = bar.Name
                };
                await dbContext.BarCocktail.AddAsync(barCocktail);

                await dbContext.SaveChangesAsync();
            }
            await nService.FavBarNotificationAsync(bar.Name, cocktail.Name);

            await nService.FavCocktailNotificationAsync(bar.Name, cocktail.Name, bar.City.Name);
        }