public IActionResult AddInteraction(int id, CreateInteractionRequestModel newInteraction)
        {
            var post = _posts.GetById(id);
            var user = _users.GetById(newInteraction.UserId);

            _interactions.Create(newInteraction, post, user);

            return(RedirectToAction("PostsPage"));
        }
Example #2
0
            public IActionResult Create([FromBody] CreateInteractionRequest newUser)
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var interaction = _interactions.Create(newUser);

                var url = Url.Action("GetById", new { id = interaction.Id });
                var responseViewModel = new InteractionResponse(interaction);

                return(Created(url, responseViewModel));
            }
        public IActionResult Create([FromBody] CreateInteractionRequest newUser)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var interaction = _interactions.Create(newUser);

            var url = Url.Action("GetById", new { id = interaction.Id });
            var responseViewModel = new InteractionResponse(interaction);

            var authHeaderIsValid = CheckAuthHeader();

            if (authHeaderIsValid)
            {
                return(Created(url, responseViewModel));
            }
            else
            {
                return(Unauthorized("User not logged in"));
            }
        }
Example #4
0
 public IActionResult AddInteraction(int id, CreateInteractionRequestModel newInteraction)
 {
     _interactions.Create(newInteraction, id);
     return(RedirectToAction("PostsPage"));
 }