// Create entity from model. public SystemAddress(SystemAddressModel model) { Type = new SystemLookupItemValue(model.Type); Line1 = model.Line1; Line2 = model.Line2; City = model.City; State = new SystemLookupItemValue(model.State); PostalCode = model.PostalCode; Country = new SystemLookupItemValue(model.Country); }
public async Task <SystemAddressModel> Validate(SystemAddressModel model) { if (model.Type.Id == string.Empty) { throw new AddressTypeIdIsRequiredException(); } model.Type = await _systemLookupItemService.GetItem("Address Types", model.Type.Id); if (model.Line1 == string.Empty) { throw new AddressLine1IsRequiredException(); } if (model.City == string.Empty) { throw new AddressCityIsRequiredException(); } if (model.State.Id == string.Empty) { throw new AddressStateIdIsRequiredException(); } model.State = await _systemLookupItemService.GetItem("States", model.State.Id); if (model.PostalCode == string.Empty) { throw new AddressPostalCodeIsRequiredException(); } var code = model.PostalCode.Split('_'); if (code.Length - 1 >= 0 && code[0] != null && !int.TryParse(code[0], out int code1)) { throw new AddressPostalCodeIsInvalidException(); } if (code.Length - 1 >= 1 && code[1] != null && !int.TryParse(code[1], out int code2)) { throw new AddressPostalCodeIsInvalidException(); } if (model.Country.Id == string.Empty) { throw new AddressCountryIdIsRequiredException(); } model.Country = await _systemLookupItemService.GetItem("Countries", model.Country.Id); return(model); }