예제 #1
0
        public void FromAnswerViewModel_ToAnswerModelTest()
        {
            // arrange
            var from = new AnswerViewModel
            {
                Info = new AnswerInfoViewModel
                {
                    EthnicityCode = 1,
                    FirstName     = "First Name",
                    GenderCode    = 2,
                    LastName      = "Last Name",
                    RegionCode    = 4,
                    SchoolingCode = 5
                }
            };

            // act
            var result = from.ToAnswerModel();

            // assert
            Assert.Equal(from.Info.EthnicityCode, result.EthnicityId);
            Assert.Equal(from.Info.FirstName, result.FirstName);
            Assert.Equal(from.Info.GenderCode, result.GenderId);
            Assert.Equal(from.Info.LastName, result.LastName);
            Assert.Equal(from.Info.RegionCode, result.RegionId);
            Assert.Equal(from.Info.SchoolingCode, result.SchoolingId);
            Assert.Empty(result.Parents);
            Assert.Empty(result.Children);
        }
예제 #2
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));
            }
        }