private List <int> VerifyAddress(IGenericAddressVM address) { var errors = new List <int>(); var location = address.IsStandard ? address.sAddress : (GenericLocationVM)address.lAddress; errors.AddRange(location.VerifyBuildingName()); errors.AddRange(location.VerifyPoBox()); errors.AddRange(location.VerifyStreetAddress()); errors.AddRange(location.VerifyAltAddress()); if (address.IsStandard) { var sAddress = address.sAddress; errors.AddRange(sAddress.VerifySuburb()); errors.AddRange(sAddress.VerifyPostcode()); errors.AddRange(sAddress.VerifyState()); } else { var lAddress = address.lAddress; errors.AddRange(lAddress.VerifyGroup()); errors.AddRange(lAddress.VerifyLane()); errors.AddRange(lAddress.VerifyQuarter()); errors.AddRange(lAddress.VerifyHamlet()); errors.AddRange(lAddress.VerifyCommute()); errors.AddRange(lAddress.VerifyWard()); errors.AddRange(lAddress.VerifyDistrict()); errors.AddRange(lAddress.VerifyTown()); errors.AddRange(lAddress.VerifyProvince()); errors.AddRange(lAddress.VerifyCity()); } return(errors); }
private async Task <RawLocation> InsertRawLocation(IGenericAddressVM address) { _logger.LogInformation("HidroAddressService.InsertRawLocation - Service runs internally."); RawLocation rawLocation; if (address.IsStandard) { rawLocation = address.sAddress; rawLocation.IsStandard = address.IsStandard; } else { rawLocation = address.lAddress; rawLocation.IsStandard = address.IsStandard; } _dbContext.RawLocation.Add(rawLocation); try { await _dbContext.SaveChangesAsync(); } catch (Exception e) { _logger.LogError("HidroAddressService.InsertRawAddressFor - Error at inserting rawLocation: " + e); return(null); } return(rawLocation); }
public async Task <IGenericAddressVM> InsertRawAddressFor(int hidrogenianId, IGenericAddressVM address) { _logger.LogInformation("HidroAddressService.InsertRawAddressFor - hidrogenianId=" + hidrogenianId); var rawLocation = await InsertRawLocation(address); if (rawLocation == null) { return(null); } var hidrogenianAddress = new HidroAddress { HidrogenianId = hidrogenianId, LocationId = rawLocation.Id, Title = address.Title, IsRefined = false, IsPrimaryAddress = false, IsDeliveryAddress = false }; _dbContext.HidroAddress.Add(hidrogenianAddress); try { await _dbContext.SaveChangesAsync(); } catch (Exception e) { _logger.LogError("HidroAddressService.InsertRawAddressFor - Error at inserting hidroAddress: " + e); return(null); } address.Id = hidrogenianAddress.Id; return(address); }
public async Task <KeyValuePair <bool?, IGenericAddressVM> > UpdateHidroAddress(IGenericAddressVM address) { _logger.LogInformation("HidroAddressService.UpdateHidroAddress - Service starts."); var dbAddress = await _dbContext.HidroAddress.FindAsync(address.Id); if (dbAddress == null) { return(new KeyValuePair <bool?, IGenericAddressVM>(null, null)); } var rawLocation = await InsertRawLocation(address); if (rawLocation == null) { return(new KeyValuePair <bool?, IGenericAddressVM>(false, null)); } dbAddress.LocationId = rawLocation.Id; dbAddress.Title = address.Title; dbAddress.IsDeliveryAddress = false; dbAddress.IsPrimaryAddress = false; dbAddress.IsRefined = false; dbAddress.LastUpdated = DateTime.UtcNow; _dbContext.HidroAddress.Update(dbAddress); try { await _dbContext.SaveChangesAsync(); } catch (Exception e) { _logger.LogError("HidroAddressService.UpdateHidroAddress - Error: " + e); return(new KeyValuePair <bool?, IGenericAddressVM>(true, null)); } if (address.IsStandard) { address.sAddress.Id = rawLocation.Id; } else { address.lAddress.Id = rawLocation.Id; } address.IsRefined = false; return(new KeyValuePair <bool?, IGenericAddressVM>(true, address)); }