public Owner AddOwner(Owner owner) { Owner addedOwner = null; using (LandPropertiesDBEntities entities = new LandPropertiesDBEntities()) { OWNER ownerToAdd = new OWNER { FIRST_NAME = owner.FirstName, LAST_NAME = owner.LastName, ADDRESS = owner.Address }; entities.OWNERs.Add(ownerToAdd); entities.SaveChanges(); addedOwner = ConvertDbToBusinessEntity(ownerToAdd); } return addedOwner; }
private Owner ConvertDbToBusinessEntity(OWNER dbEntity) { Owner businessEntity = new Owner(); businessEntity.ID = dbEntity.ID; businessEntity.FirstName = dbEntity.FIRST_NAME; businessEntity.LastName = dbEntity.LAST_NAME; businessEntity.Address = dbEntity.ADDRESS; if (dbEntity.LAND_PROPERTY != null && dbEntity.LAND_PROPERTY.Any()) { businessEntity.LandProperties = new List<LandProperty>(); dbEntity.LAND_PROPERTY.ToList().ForEach(lp => businessEntity.LandProperties.Add(new LandProperty { ID = lp.ID, Area = lp.AREA, UPI = lp.UPI })); } return businessEntity; }