public static Address GetById(int addressId) { Address address = null; string sql = @"SELECT * FROM Address WHERE Id=@Id"; try { using (SqlConnection conn = new SqlConnection(DataConnection.AppData)) { conn.Open(); using (SqlCommand cmd = new SqlCommand(sql, conn)) { cmd.Parameters.AddWithValue("@Id", addressId); SqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { address = new Address(reader); } } } } catch (Exception e) { string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name; ErrLogger.Log(_className, methodName, e.Message); address = null; } return address; }
public ContactsVM() { _DB = new ContactsContext(); soapClient = new SoapService.SoapServiceClient(); Contacts = new ObservableCollection<Contact>(); Addresses = new ObservableCollection<Address>(); Companies = new ObservableCollection<Company>(); AddressIDs = new ObservableCollection<int>(); /* Old save command SaveCommand = new DelegateCommand(() => { _DB.SaveChanges(); }); */ SaveCommand = new DelegateCommand(() => { foreach (var x in Contacts) { soapClient.AddContact(x); } soapClient.Save(); }); /*old Add Contact AddContactCommand = new DelegateCommand(() => { ViewingContact = new Contact(); Contacts.Add(ViewingContact); _DB.Contacts.Add(VewingContact); }); */ AddContactCommand = new DelegateCommand(() => { ViewingContact = new Contact(); Contacts.Add(ViewingContact); //soapClient.AddContactAsync(ViewingContact); }); AddCompanyCommand = new DelegateCommand(() => { ViewingCompany = new Company(); Companies.Add(ViewingCompany); _DB.Companies.Add(ViewingCompany); }); AddAddressCommand = new DelegateCommand(() => { ViewingAddress = new Address(); Addresses.Add(ViewingAddress); _DB.Addresses.Add(ViewingAddress); }); DeleteContactCommand = new DelegateCommand(() => { _DB.Contacts.Remove(ViewingContact); Contacts.Remove(ViewingContact); }); DeleteCompanyCommand = new DelegateCommand(() => { _DB.Contacts.Remove(ViewingContact); Contacts.Remove(ViewingContact); }); DeleteAddressCommand = new DelegateCommand(() => { _DB.Contacts.Remove(ViewingContact); Contacts.Remove(ViewingContact); }); AddContactMethodCommand = new DelegateCommand(() => { var cm = new ContactMethod(); ViewingContact.ContactMethods.Add(cm); }); init(); }
public static AddressViewModel ToViewModel(this DataAccess.Address entity, AddressViewModel model) { model.Id = entity.Id; model.Line1 = entity.Line1; model.Line2 = entity.Line2; model.Code = entity.Code; model.Id = entity.Id; model.CountryId = entity.Suburb.Town.City.Province.CountryId; model.ProvinceId = entity.Suburb.Town.City.ProvinceId; model.CityId = entity.Suburb.Town.CityId; model.TownId = entity.Suburb.TownId; model.SuburbId = entity.SuburbId; model.IsActive = entity.IsActive; model.Country = entity.Suburb.Town.City.Province.Country.Name; model.Province = entity.Suburb.Town.City.Province.Name; model.City = entity.Suburb.Town.City.Name; model.Town = entity.Suburb.Town.Name; model.Suburb = entity.Suburb.Name; return(model); }
public bool Save() { UserProfile profile = UserProfile.GetByUserId(UserId); Address address = new Address(); address.Id = profile == null ? 0 : profile.AddressId; address.Street = StreetAddress; address.City = City; address.PostalCode = PostalCode; address.CountryId = Convert.ToInt32(CountryId); address = address.Save(); profile = profile ?? new UserProfile(); profile.Title = Title; profile.FirstName = FirstName; profile.LastName = LastName; profile.PhoneNumber = PhoneNumber; profile.AddressId = address == null ? 0 : address.Id; profile.UserId = UserId; profile = profile.Save(); return (address != null && profile != null); }
private void SetAccountInfo(int uniqueID, Address address) { Accessor.SetAccountInfo(uniqueID, address); }