Ejemplo n.º 1
0
        public IActionResult PostRealty([FromBody] Realty realty)
        {
            realty.BeneficiaryId = Guid.NewGuid();

            if (!RealtyValidations.RealtyIsValid(realty))
            {
                return(Forbid());
            }

            //_realtyRepository.Add(realty);

            return(Ok(realty));
        }
Ejemplo n.º 2
0
        public IActionResult UpdateRealty(Guid id, [FromBody] Realty realty)
        {
            if (!RealtyValidations.RealtyIsValid(realty))
            {
                return(Forbid());
            }

            var obj = (Realty)_beneficiaryRepository.Find(id);

            obj.IsDeleted = realty.IsDeleted;
            obj.RealtyConstructionDate      = realty.RealtyConstructionDate;
            obj.RealtyMarketValue           = realty.RealtyMarketValue;
            obj.RealtyMunicipalRegistration = realty.RealtyMunicipalRegistration;
            obj.RealtySaleValue             = realty.RealtySaleValue;

            return(Ok(_beneficiaryRepository.Update(id, obj)));
        }
Ejemplo n.º 3
0
        private List <Guid> AddRealties(List <RealtyViewModel> realties)
        {
            List <Guid> insertedRealties = new List <Guid>();

            insertedRealties.AddRange(realties.Where(ben => ben.BeneficiaryId != Guid.Empty).Select(ben => ben.BeneficiaryId));
            realties.RemoveAll(ben => ben.BeneficiaryId != Guid.Empty);

            // Verifies if Municipal Registration is already in DB
            if (_db.Realties
                .Select(real => real.RealtyMunicipalRegistration)
                .Where(reg => realties.Select(real => real.MunicipalRegistration).Contains(reg))
                .ToList().Count > 0)
            {
                return(null);
            }

            foreach (var realty in realties)
            {
                realty.IsDeleted = false;
                Address realtyAddress = new Address()
                {
                    AddressCity         = realty.AddressCity,
                    AddressComplement   = realty.AddressComplement,
                    AddressCountry      = realty.AddressCountry,
                    AddressNeighborhood = realty.AddressNeighborhood,
                    AddressNumber       = realty.AddressNumber,
                    AddressState        = realty.AddressState,
                    AddressStreet       = realty.AddressStreet,
                    AddressType         = realty.AddressType,
                    AddressZipCode      = realty.AddressZipCode
                };
                //if (AddressValidations.AddressIsValid(realtyAddress))
                realtyAddress = _db.Addresses.Add(realtyAddress).Entity;
                //else return null;

                Realty realtyToAdd = new Realty()
                {
                    IsDeleted = realty.IsDeleted,
                    RealtyConstructionDate      = realty.ConstructionDate,
                    RealtyMarketValue           = realty.MarketValue,
                    RealtyMunicipalRegistration = realty.MunicipalRegistration,
                    RealtySaleValue             = realty.SaleValue
                };

                if (RealtyValidations.RealtyIsValid(realtyToAdd))
                {
                    realtyToAdd = _db.Realties.Add(realtyToAdd).Entity;
                    insertedRealties.Add(realtyToAdd.BeneficiaryId);
                }
                else
                {
                    return(null);
                }

                _db.Beneficiary_Address.Add(new BeneficiaryAddress()
                {
                    AddressId            = realtyAddress.AddressId,
                    BeneficiaryId        = realtyToAdd.BeneficiaryId,
                    BeneficiaryAddressId = Guid.NewGuid()
                });
            }
            if (insertedRealties.Count == realties.Count)
            {
                return(insertedRealties);
            }
            return(null);
        }