Ejemplo n.º 1
0
        public async Task <ActionResult <AnswerViewModel> > Post([FromBody] AnswerViewModel value)
        {
            try
            {
                var census   = value.ToAnswerModel();
                var parents  = value.RetrieveAnswerModelParents();
                var children = value.RetrieveAnswerModelChildren();

                var result = await _repository.CreateWithParentsAndChidrenAsync(census, parents, children);

                // updatnng information for dashboard
                var results = (await _repository.DashboardCount()).ToList();

                await _dashboardHub.SendMessage(new { regions = results[0], genders = results[1], schoolings = results[2], ethnicities = results[3] });

                return(CreatedAtAction(nameof(Get), new { id = result.Id }, result.ToAnswerViewModel()));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }