Exemple #1
0
        public async Task <IActionResult> Create([FromBody] Response newResponse)
        {
            try
            {
                var user = await _userManager.GetUserAsync(HttpContext.User);

                var response = _responsesService.CreateResponse(newResponse, user);
                return(Created("", response));
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
        public IActionResult Create(string id, [FromForm] Response response)
        {
            if (!ModelState.IsValid)
            {
                throw new Exception("Response is not valid");
            }

            response.QuestionId = new Guid(id);

            var user = _userManager.GetUserAsync(HttpContext.User).Result;

            var newResponse = _service.CreateResponse(response, user);

            return(View(newResponse));
        }
        public async Task <IActionResult> CreateResponse([Bind("Body")] Response newResponse, int id)
        {
            try
            {
                newResponse.QuestionId = id;
                var user = await _userManager.GetUserAsync(HttpContext.User);

                var response = _responsesService.CreateResponse(newResponse, user);
                return(RedirectToAction(nameof(GetResponses), new { id = response.QuestionId }));
            }
            catch (Exception)
            {
                return(View(newResponse));
            }
        }