Exemplo n.º 1
0
 public LandPropertiesDO(LandProperty landProperty)
 {
     this.Id = landProperty.Id;
     this.Area = landProperty.Area;
     this.UPI = landProperty.UPI;
     this.Image = landProperty.Image;
     this.Owner = landProperty.Owner == null ? null : new OwnersDO(landProperty.Owner);
     this.Mortgages = landProperty.Mortgages == null ? null : Wrappers.WrapMortgages(landProperty.Mortgages);
 }
Exemplo n.º 2
0
        private async Task<bool> AddLandPropertyAsync(dynamic data)
        {
            LandProperty newLandProperty = new LandProperty();
            newLandProperty.Area = data.Area;
            newLandProperty.UPI = data.UPI;

            if (!String.IsNullOrWhiteSpace(data.Image))
            {
                newLandProperty.Image = data.Image;
            }

            string _firstName = data.Owner.FirstName;
            string _lastName = data.Owner.LastName;
            Owner existingOwner = entities.Owners.FirstOrDefault(o => o.FirstName == _firstName && o.LastName == _lastName);

            if (existingOwner != null)
            {
                newLandProperty.Owner = existingOwner;
            }
            else
            {
                Owner newOwner = new Owner();
                newOwner.FirstName = data.Owner.FirstName;
                newOwner.LastName = data.Owner.LastName;
                newOwner.Address = data.Owner.Address;
                newOwner.UserID = data.Owner.UserID;

                if (!String.IsNullOrWhiteSpace(data.Owner.Image))
                {
                    newOwner.Image = data.Owner.Image;
                }
                newLandProperty.Owner = newOwner;
            }

            this.entities.LandProperties.Add(newLandProperty);
            await this.entities.SaveChangesAsync();

            return true;
        }