AccountMYOBUtils.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. using InABox.Core;
  2. using InABox.Poster.MYOB;
  3. using MYOB.AccountRight.SDK.Services.GeneralLedger;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using MYOBAccount = MYOB.AccountRight.SDK.Contracts.Version2.GeneralLedger.Account;
  10. namespace PRS.Shared.Posters.MYOB;
  11. public static class AccountMYOBUtils
  12. {
  13. public static Result<Guid, Exception> GetAccount(MYOBConnectionData data, string glCode)
  14. {
  15. if (!data.GetUID<AccountService, MYOBAccount>(
  16. new Filter<MYOBAccount>(x => x.DisplayID).IsEqualTo(glCode))
  17. .Get(out var accountID, out var error))
  18. {
  19. return Result.Error(new Exception($"Failed to find Account in MYOB with code {glCode}", error));
  20. }
  21. else if (accountID == Guid.Empty)
  22. {
  23. return Result.Error(new Exception($"Failed to find Account in MYOB with code {glCode}"));
  24. }
  25. else
  26. {
  27. return Result.Ok(accountID);
  28. }
  29. }
  30. }