Esempio n. 1
0
        /// <summary>
        /// User comments a cocktail
        /// </summary>
        /// <param name="commentDTO">Comment DTO </param>
        /// <param name="cocktailId">Cocktail Id that is commented</param>
        /// <param name="userId">User Id that leaves the comment</param>
        /// <returns>The comment, DTO</returns>
        public async Task <CocktailUserCommentDTO> AddCocktailComment(CocktailUserCommentDTO commentDTO, Guid cocktailId, Guid userId)
        {
            var cocktail = await _context.Cocktails
                           .FirstOrDefaultAsync(x => x.Id == cocktailId);

            commentDTO.UserId = userId;
            var comment = _cocktailCommentMapper.MapDTOToEntity(commentDTO);

            await _context.CocktailComments.AddAsync(comment);

            await _context.SaveChangesAsync();

            return(_cocktailCommentMapper.MapEntityToDTO(comment));
        }
Esempio n. 2
0
        public async Task <CocktailUserCommentDTO> CreateAsync(CocktailUserCommentDTO commentDTO)
        {
            try
            {
                if (await CombinationExistAsync(commentDTO.CocktailId, commentDTO.UserId))
                {
                    return(new CocktailUserCommentDTO());
                }
                else
                {
                    var comment = _mapper.MapDTOToEntity(commentDTO);

                    _context.CocktailComments.Add(comment);

                    await _context.SaveChangesAsync();

                    return(commentDTO);
                }
            }
            catch (Exception)
            {
                return(new CocktailUserCommentDTO());
            }
        }