本文整理汇总了C#中Person.AddAddress方法的典型用法代码示例。如果您正苦于以下问题:C# Person.AddAddress方法的具体用法?C# Person.AddAddress怎么用?C# Person.AddAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Person
的用法示例。
在下文中一共展示了Person.AddAddress方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateAddress
// Create or update the person's business address if exists
private void UpdateAddress(Person person, Application application)
{
// check if the person already has the address
var address = person.Addresses.Where(a => a.AddressType.Id == StaticIndexes.Address_Business.ToCharArray()[0]).FirstOrDefault();
if (address == null)
{
address = new Address(application.FirmAddressLine1, application.FirmAddressLine2, application.FirmCity, application.FirmState, application.FirmZip, _addressTypeRepository.GetNullableById(StaticIndexes.Address_Business.ToCharArray()[0]), person);
person.AddAddress(address);
}
else
{
// update the existing address
address.Line1 = application.FirmAddressLine1;
address.Line2 = application.FirmAddressLine2;
address.City = application.FirmCity;
address.State = application.FirmState;
address.Zip = application.FirmZip;
}
}
示例2: SetAddresses
private static void SetAddresses(Person person, IList<Address> addresses, ModelStateDictionary modelState)
{
// remove the blank address
var remove = addresses.Where(a => !a.HasAddress()).ToList();
foreach (var a in remove) addresses.Remove(a);
// update/add updated addresses
foreach (var addr in addresses)
{
var type = addr.AddressType;
var origAddress = person.Addresses.Where(a => a.AddressType == type).FirstOrDefault();
// run validation if required
if (type.Required)
{
addr.Person = person;
addr.TransferValidationMessagesTo(modelState);
}
// address was entered
if (addr.HasAddress())
{
// person did not have this address in the first place, add it in
if (origAddress == null)
{
person.AddAddress(addr);
}
// update existing address
else
{
Mapper.Map(addr, origAddress);
}
}
// address was blanked out/removed
else
{
if (origAddress != null) person.Addresses.Remove(origAddress);
}
}
}