Exemplo n.º 1
0
        public async Task <ActionResult <Reaction> > PostReaction(Wimym.Common.Models.ReactionResponse reaction)
        {
            var user = await _userHelper.GetUserByEmailAsync(reaction.User.Email);

            if (user == null)
            {
                return(this.BadRequest("Invalid user"));
            }

            //TODO: Upload images
            var entityReaction = new Reaction
            {
                Punctuation     = reaction.Punctuation,
                Name            = reaction.Name,
                Email           = reaction.Email,
                Observation     = reaction.Observation,
                ApplicationUser = user
            };

            var newReaction = await _reactionRepository.CreateAsync(entityReaction);

            // _context.Reactions.Add(newReaction);
            // await _context.SaveChangesAsync();
            return(Ok(newReaction));

            //  return CreatedAtAction("GetReaction", new { id = reaction.Id }, reaction);
        }
        public async Task <IActionResult> PostReaction([FromBody] Notif.Transversal.Models.ReactionResponse reaction)
        {
            if (!ModelState.IsValid)
            {
                return(this.BadRequest(ModelState));
            }
            ApplicationUser user;

            if (reaction.User != null)
            {
                user = await _userHelper.GetUserByEmailAsync(reaction.User.Email);

                if (user == null)
                {
                    return(this.BadRequest("Invalid user"));
                }
            }
            else
            {
                return(this.BadRequest("user data is empty."));
            }
            //TODO: Upload images
            var entityReaction = new Reaction
            {
                Punctuation     = reaction.Punctuation,
                Name            = reaction.Name,
                Email           = reaction.Email,
                Observation     = reaction.Observation,
                ApplicationUser = user
            };

            var newProduct = await _reactionRepository.CreateAsync(entityReaction);

            return(Ok(newProduct));
        }