public void DeleteAddress(int ID) { Models.DBObjects.Address addressToDelete = dbContext.Addresses.FirstOrDefault(x => x.AddressID == ID); if (addressToDelete != null) { dbContext.Addresses.DeleteOnSubmit(addressToDelete); dbContext.SubmitChanges(); } }
public void UpdateAddress(AddressModel addressModel) { Models.DBObjects.Address existingAddress = dbContext.Addresses.FirstOrDefault(x => x.AddressID == addressModel.AddressID); if (existingAddress != null) { existingAddress.AddressID = addressModel.AddressID; existingAddress.Country = addressModel.Country; existingAddress.County = addressModel.County; existingAddress.City = addressModel.City; existingAddress.Street = addressModel.Street; existingAddress.StreetNumber = addressModel.StreetNumber; existingAddress.PostCode = addressModel.PostCode; dbContext.SubmitChanges(); } }
private Models.DBObjects.Address MapModelToDbObject(AddressModel addressModel) { Models.DBObjects.Address dbAddressModel = new Models.DBObjects.Address(); if (addressModel != null) { dbAddressModel.AddressID = addressModel.AddressID; dbAddressModel.Country = addressModel.Country; dbAddressModel.County = addressModel.County; dbAddressModel.City = addressModel.City; dbAddressModel.Street = addressModel.Street; dbAddressModel.StreetNumber = addressModel.StreetNumber; dbAddressModel.PostCode = addressModel.PostCode; return(dbAddressModel); } return(null); }
private AddressModel MapDbObjectToModel(Models.DBObjects.Address dbAddress) { AddressModel addressModel = new AddressModel(); if (dbAddress != null) { addressModel.AddressID = dbAddress.AddressID; addressModel.Country = dbAddress.Country; addressModel.County = dbAddress.County; addressModel.City = dbAddress.City; addressModel.Street = dbAddress.Street; addressModel.StreetNumber = dbAddress.StreetNumber; addressModel.PostCode = dbAddress.PostCode; return(addressModel); } return(null); }