private void AddAddresses() { ////if string changed - add new, remove old ////if string empty - remove old if (!(string.IsNullOrEmpty(Address1.City) && string.IsNullOrEmpty(Address1.ZipCode) && string.IsNullOrEmpty(Address1.Street) && string.IsNullOrEmpty(Address1.Province))) { Address1 = AddressService.AddAddress(Address1); AddressCandidateService.AddAddressToCandidate(new Address_Candidate() { Address = Address1, Candidate = Candidate }); } //remove old address if (!(string.IsNullOrEmpty(Address2.City) && string.IsNullOrEmpty(Address2.ZipCode) && string.IsNullOrEmpty(Address2.Street) && string.IsNullOrEmpty(Address2.Province))) { Address2 = AddressService.AddAddress(Address2); AddressCandidateService.AddAddressToCandidate(new Address_Candidate() { Address = Address2, Candidate = Candidate }); } //remove old address if (!(string.IsNullOrEmpty(Address3.City) && string.IsNullOrEmpty(Address3.ZipCode) && string.IsNullOrEmpty(Address3.Street) && string.IsNullOrEmpty(Address3.Province))) { Address3 = AddressService.AddAddress(Address3); AddressCandidateService.AddAddressToCandidate(new Address_Candidate() { Address = Address3, Candidate = Candidate }); } }
private void UpdateCandidateAddresses() { ////if string changed - add new, remove old ////if string empty - remove old if (NewAddress1.FullAddress != OldAddress1.FullAddress) { if (!(string.IsNullOrEmpty(NewAddress1.City) && string.IsNullOrEmpty(NewAddress1.ZipCode) && string.IsNullOrEmpty(NewAddress1.Street) && string.IsNullOrEmpty(NewAddress1.Province))) { NewAddress1 = AddressService.AddAddress(NewAddress1); AddressCandidateService.AddAddressToCandidate(new Address_Candidate() { Address = NewAddress1, Candidate = NewCandidate }); } //remove old address AddressCandidateService.RemoveAddressFromCandidate(OldAddress1.Id, NewCandidate.Id); } if (NewAddress2.FullAddress != OldAddress2.FullAddress) { if (!(string.IsNullOrEmpty(NewAddress2.City) && string.IsNullOrEmpty(NewAddress2.ZipCode) && string.IsNullOrEmpty(NewAddress2.Street) && string.IsNullOrEmpty(NewAddress2.Province))) { NewAddress2 = AddressService.AddAddress(NewAddress2); AddressCandidateService.AddAddressToCandidate(new Address_Candidate() { Address = NewAddress2, Candidate = NewCandidate }); } //remove old address AddressCandidateService.RemoveAddressFromCandidate(OldAddress2.Id, NewCandidate.Id); } if (NewAddress3.FullAddress != OldAddress3.FullAddress) { if (!(string.IsNullOrEmpty(NewAddress3.City) && string.IsNullOrEmpty(NewAddress3.ZipCode) && string.IsNullOrEmpty(NewAddress3.Street) && string.IsNullOrEmpty(NewAddress3.Province))) { NewAddress3 = AddressService.AddAddress(NewAddress3); AddressCandidateService.AddAddressToCandidate(new Address_Candidate() { Address = NewAddress3, Candidate = NewCandidate }); } //remove old address AddressCandidateService.RemoveAddressFromCandidate(OldAddress3.Id, NewCandidate.Id); } //if (Address2 != OldAddress2) //{ // var newAddress = AddressService.AddAddress(new Address() // { // ZipCode = Address2 // //TODO make way to parse Address object from strings // }); // AddressCandidateService.AddAddressToCandidate(new Address_Candidate() // { // Address = newAddress, // Candidate = NewCandidate // }); // //remove old address // AddressCandidateService.RemoveAddressFromCandidate(OldCandidate.Addresses.Where(d => d.CandidateId == OldCandidate.Id).ToList()[1].AddressId, OldCandidate.Id); //} //if (Address3 != OldAddress3) //{ // var newAddress = AddressService.AddAddress(new Address() // { // ZipCode = Address3 // //TODO make way to parse Address object from strings // }); // AddressCandidateService.AddAddressToCandidate(new Address_Candidate() // { // Address = newAddress, // Candidate = NewCandidate // }); // //remove old address // AddressCandidateService.RemoveAddressFromCandidate(OldCandidate.Addresses.Where(d => d.CandidateId == OldCandidate.Id).ToList()[2].AddressId, OldCandidate.Id); //} //if (string.IsNullOrEmpty(Address1)) //{ // //remove old address // AddressCandidateService.RemoveAddressFromCandidate(OldCandidate.Addresses.Where(d => d.CandidateId == OldCandidate.Id).ToList()[0].AddressId, OldCandidate.Id); //} //if (string.IsNullOrEmpty(Address2)) //{ // //remove old address // AddressCandidateService.RemoveAddressFromCandidate(OldCandidate.Addresses.Where(d => d.CandidateId == OldCandidate.Id).ToList()[1].AddressId, OldCandidate.Id); //} //if (string.IsNullOrEmpty(Address3)) //{ // //remove old address // AddressCandidateService.RemoveAddressFromCandidate(OldCandidate.Addresses.Where(d => d.CandidateId == OldCandidate.Id).ToList()[2].AddressId, OldCandidate.Id); //} }