public Owner Save(Owner owner) { if (owner.ID != 0) return this._ownersRepository.EditOwner(owner); else return this._ownersRepository.AddOwner(owner); }
public Owner EditOwner(Owner owner) { using (LandPropertiesDBEntities entities = new LandPropertiesDBEntities()) { var dbOwner = entities.OWNERs.FirstOrDefault(o => o.ID == owner.ID); dbOwner.FIRST_NAME = owner.FirstName; dbOwner.LAST_NAME = owner.LastName; dbOwner.ADDRESS = owner.Address; entities.SaveChanges(); return ConvertDbToBusinessEntity(dbOwner); } }
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; }
public Owner Save(Owner owner) { return new OwnerBL().Save(owner); }