/// <summary> /// Create new customer based on the current class instance. Return True if Customer Created. /// </summary> /// <param name="iDpsCustomer"></param> /// <returns></returns> public async Task <bool> CreateNewCustomerAsync(IDpsCustomer iDpsCustomer, IBoemmApi iboemmApi) { try { // validation .... if (string.IsNullOrEmpty(this.Customer.VatNumber) || string.IsNullOrWhiteSpace(this.Customer.VatNumber)) { return(false); } else { string VatNumber = await iDpsCustomer.AddNewCustomerAsync(this); if (string.IsNullOrEmpty(VatNumber) || string.IsNullOrWhiteSpace(VatNumber)) { return(false); } var boemmCustomer = await iboemmApi.AddOrUpdateNewCustomerAsync(this.Customer); if (boemmCustomer != null) { // update DpsCustomer this.Customer = boemmCustomer; var Updated = await iDpsCustomer.UpdateCustomerAsync(this); if (!Updated) { // create a job or an indeication that this customer isn't updated to match boemm DB . but we have customer alredy. } } return(true); } } catch (Exception e) { throw; } }
public async Task <DpsCustomer> GetCustomerByVatNumberAsync(string Vat, IDpsCustomer idpsCustomer, IBoemmApi iboemmApi) { var localDpsCustomer = await idpsCustomer.GetCustomerByVatNumberAsync(Vat); if (localDpsCustomer != null) { return(localDpsCustomer); } else { var BoemmCustomer = await iboemmApi.GetBoemmCustomerByVatNumberAsync(Vat); if (BoemmCustomer != null) { DpsCustomer dpsCustomer = new DpsCustomer(); dpsCustomer.Customer = BoemmCustomer; return(dpsCustomer); } else { return(null); } } }