예제 #1
0
        public void Insert(House house, IFormFile image)
        {
            var imageName = _fileService.UploadImage(image);

            house.ImageName = imageName;
            _houseRepository.Insert(house);
        }
        public IActionResult Create([FromBody] HouseDto houseDto)
        {
            House house          = _mapper.Map <House>(houseDto);
            var   claimsIdentity = this.User.Identity as ClaimsIdentity;
            var   userId         = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
            bool  succes         = Int32.TryParse(userId, out var ownerId);

            if (succes)
            {
                house.OwnerId = ownerId;
            }
            _houseRepository.Insert(house);
            _houseRepository.Save();
            return(Ok());
        }
예제 #3
0
        public void InsertHouse(DTOHouse dto)
        {
            var house = new House
            {
                Number = dto.Number,
                Phone  = dto.Phone
            };

            _houseRepository.Insert(house);

            if (dto.Residents != null && dto.Residents.Count > 0)
            {
                foreach (var resident in dto.Residents)
                {
                    var person = new Person()
                    {
                        Cpf         = resident.Cpf,
                        DateOfBirth = resident.DateOfBirth,
                        Name        = resident.Name,
                        Nickname    = resident.Nickname
                    };
                    _personRepository.Insert(person);

                    if (resident.Contact != null)
                    {
                        var contact = new Contact
                        {
                            PersonId   = person.Id,
                            Email      = resident.Contact.Email,
                            Cellphone1 = resident.Contact.Cellphone1,
                            Cellphone2 = resident.Contact.Cellphone2
                        };
                        _contactRepository.Insert(contact);
                    }

                    var family = new Family()
                    {
                        HouseId              = house.Id,
                        PersonId             = person.Id,
                        FamilyRelationshipId = (int)resident.FamilyRelationshipId
                    };
                    _familyRepository.Insert(family);
                }
            }
        }