Пример #1
0
        [HttpPost("register")] //<host>/api/house/register
        public async Task <IActionResult> Register([FromBody] HouseForRegisterDto houseForRegisterDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = await _context.Users.FirstOrDefaultAsync(test => test.Id == houseForRegisterDto.UserId);

            var houseToCreate = new House
            {
                Location      = houseForRegisterDto.Location,
                SquareFootage = houseForRegisterDto.SquareFootage,
                Food          = houseForRegisterDto.Food,
                Solar         = houseForRegisterDto.Solar,
                Wind          = houseForRegisterDto.Wind,
                Geothermal    = houseForRegisterDto.Geothermal,
                User          = user
            };

            var createHouse = await _repo.Register(houseToCreate);

            return(Ok(new { createHouse.Location, createHouse.SquareFootage }));
        }