/// <summary>
        /// Get a DeviceUsageId so we can use it to call a POS Snippet
        /// </summary>
        /// <returns></returns>
        public async Task <string> GetSessionAsync()
        {
            try
            {
                var session = await service.SystemResource.GetSessionAsync();

                return(session.Key.ToString());
            }
            catch (ApiException ex)
            {
                apiException = new APIExceptions {
                    ErrorCode = ex.Code, ErrorDescription = ex.Message, ErrorApi = "GetSessionAsync"
                };
                return(null);
            }
            catch (Exception ex)
            {
                logger.WriteLogError("**** LoyaltyEngineServices FAILURE: GetDeviceSessionKey Exception Error= " + ex.Message);
                if (ex.InnerException != null)
                {
                    logger.WriteLogError("**** InnerException  = " + ex.InnerException.Message);
                }
                return(null);
            }
        }
 public async Task SubmitLogsAsync()
 {
     try
     {
         await _logger.SubmitLogsAsync(_serviceUrls.LoggingApiUrl, _conFigHelper.ACCESS_KEY);
     }
     catch (ApiException ex)
     {
         apiException = new APIExceptions {
             ErrorCode = ex.Code, ErrorDescription = ex.Message, ErrorApi = "SubmitLogsAsync"
         };
     }
     catch (Exception ex)
     {
         //gridService.Logger.LogError("*** Logger.SubmitLogsAsync Exception in gridService = " + ex.Message);
     }
 }
 public void LogInfo(string logMessage)
 {
     try
     {
         _logger.LogInfo(logMessage);
     }
     catch (ApiException ex)
     {
         apiException = new APIExceptions {
             ErrorCode = ex.Code, ErrorDescription = ex.Message, ErrorApi = "Logger.LogInfo"
         };
     }
     catch (Exception ex)
     {
         //gridService.Logger.LogError("*** Logger.LogInfo Exception in gridService = " + ex.Message);
     }
 }
 public async Task <Customer> GetAsync(Guid customerUid)
 {
     try
     {
         return(await _gridService.CustomerResource.GetAsync(customerUid));
     }
     catch (ApiException ex)
     {
         apiException = new APIExceptions {
             ErrorCode = ex.Code, ErrorDescription = ex.Message, ErrorApi = "GetAsync"
         };
         return(null);
     }
     catch (Exception ex)
     {
         _logger.LogError("*** GetAsync Exception in gridService = " + ex.Message);
         return(null);
     }
 }
        /// <summary>
        /// Get Cart By SourceExternalId
        /// </summary>
        /// <param name="cartSourceExternalId"></param>
        /// <returns></returns>
        public CalculatedCart GetBySourceExternalIdAsync(string cartSourceExternalId)
        {
            try
            {
                return(AsyncHelpers.RunSync <CalculatedCart>(() => service.CartResource.GetBySourceExternalIdAsync(cartSourceExternalId)));
            }
            catch (ApiException ex)
            {
                apiException = new APIExceptions {
                    ErrorCode = ex.Code, ErrorDescription = ex.Message, ErrorApi = "GetBySourceExternalIdAsync"
                };
                return(null);
            }
            catch (Exception ex)
            {
                logger.WriteLogError("**** LoyaltyEngineServices FAILURE: GetBySourceExternalIdAsync Exception Error= " + ex.Message);

                return(null);
            }
        }
 /// <summary>
 /// SetCartToCustomer
 /// </summary>
 /// <param name="cartUid"></param>
 /// <param name="customer"></param>
 public async void SetCartToCustomer(Guid cartUid, Customer customer)
 {
     try
     {
         await service.CartResource.SetCustomerAsync(cartUid, customer);
     }
     catch (ApiException ex)
     {
         apiException = new APIExceptions {
             ErrorCode = ex.Code, ErrorDescription = ex.Message, ErrorApi = "GetAsync"
         };
     }
     catch (Exception ex)
     {
         logger.WriteLogError("**** LoyaltyEngineServices FAILURE: SetCartToCustomer Exception Error= " + ex.Message);
         if (ex.InnerException != null)
         {
             logger.WriteLogError("**** InnerException  = " + ex.InnerException.Message);
         }
     }
 }
 /// <summary>
 /// ResolveCustomer
 /// </summary>
 /// <param name="searchCustomer"></param>
 /// <returns></returns>
 public async Task <Customer> ResolveCustomer(Customer searchCustomer)
 {
     try
     {
         return(await service.CustomerResource.ResolveAsync(searchCustomer));
     }
     catch (ApiException ex)
     {
         apiException = new APIExceptions {
             ErrorCode = ex.Code, ErrorDescription = ex.Message, ErrorApi = "ResolveAsync"
         };
         return(null);
     }
     catch (Exception ex)
     {
         logger.WriteLogError("**** LoyaltyEngineServices FAILURE: ResolveCustomer Exception Error= " + ex.Message);
         if (ex.InnerException != null)
         {
             logger.WriteLogError("**** InnerException  = " + ex.InnerException.Message);
         }
         return(null);
     }
 }
 /// <summary>
 /// DeactiveClub
 /// </summary>
 /// <param name="leaveClub"></param>
 /// <returns></returns>
 public async Task <CommandResponse> DeactiveClub(ExpireClubMembershipCommand leaveClub)
 {
     try
     {
         return(await service.CustomerResource.ExpireClubMembershipAsync(leaveClub));
     }
     catch (ApiException ex)
     {
         apiException = new APIExceptions {
             ErrorCode = ex.Code, ErrorDescription = ex.Message, ErrorApi = "ExpireClubMembershipAsync"
         };
         return(null);
     }
     catch (Exception ex)
     {
         logger.WriteLogError("**** LoyaltyEngineServices FAILURE: DeactiveClub Exception Error= " + ex.Message);
         if (ex.InnerException != null)
         {
             logger.WriteLogError("**** InnerException  = " + ex.InnerException.Message);
         }
         return(null);
     }
 }
 /// <summary>
 /// GetCustomer
 /// </summary>
 /// <param name="cartUid"></param>
 /// <returns></returns>
 public async Task <Customer> GetCustomer(Guid cartUid)
 {
     try
     {
         return(await service.CartResource.GetCustomerAsync(cartUid));
     }
     catch (ApiException ex)
     {
         apiException = new APIExceptions {
             ErrorCode = ex.Code, ErrorDescription = ex.Message, ErrorApi = "GetAsync"
         };
         return(null);
     }
     catch (Exception ex)
     {
         logger.WriteLogError("**** LoyaltyEngineServices FAILURE: GetCustomer Exception Error= " + ex.Message);
         if (ex.InnerException != null)
         {
             logger.WriteLogError("**** InnerException  = " + ex.InnerException.Message);
         }
         return(null);
     }
 }
 /// <summary>
 /// LoyaltyPointAdjustment
 /// </summary>
 /// <param name="adjustment"></param>
 /// <returns></returns>
 public async Task <LoyaltyPointsTransaction> LoyaltyPointAdjustment(AdjustLoyaltyPointsCommand adjustment)
 {
     try
     {
         return(await service.CustomerResource.AdjustLoyaltyAsync(adjustment));
     }
     catch (ApiException ex)
     {
         apiException = new APIExceptions {
             ErrorCode = ex.Code, ErrorDescription = ex.Message, ErrorApi = "AdjustLoyaltyAsync"
         };
         return(null);
     }
     catch (Exception ex)
     {
         logger.WriteLogError("**** LoyaltyEngineServices FAILURE: LoyaltyPointAdjustment Exception Error= " + ex.Message);
         if (ex.InnerException != null)
         {
             logger.WriteLogError("**** InnerException  = " + ex.InnerException.Message);
         }
         return(null);
     }
 }
 /// <summary>
 /// ClubActivation
 /// </summary>
 /// <param name="joinClub"></param>
 /// <returns></returns>
 public async Task <CommandResponse> ClubActivation(JoinClubCommand joinClub)
 {
     try
     {
         return(await service.CustomerResource.JoinClubAsync(joinClub));
     }
     catch (ApiException ex)
     {
         apiException = new APIExceptions {
             ErrorCode = ex.Code, ErrorDescription = ex.Message, ErrorApi = "JoinClubAsync"
         };
         return(null);
     }
     catch (Exception ex)
     {
         logger.WriteLogError("**** LoyaltyEngineServices FAILURE: ClubActivation Exception Error= " + ex.Message);
         if (ex.InnerException != null)
         {
             logger.WriteLogError("**** InnerException  = " + ex.InnerException.Message);
         }
         return(null);
     }
 }
 /// <summary>
 /// ApplyCouponAsync
 /// </summary>
 /// <param name="cartUid"></param>
 /// <param name="code"></param>
 /// <returns></returns>
 public async Task <Coupon> ApplyCouponAsync(Guid cartUid, string code)
 {
     try
     {
         return(await service.CartResource.ApplyCouponAsync(cartUid, code));
     }
     catch (ApiException ex)
     {
         apiException = new APIExceptions {
             ErrorCode = ex.Code, ErrorDescription = ex.Message, ErrorApi = "GetAppliedCouponsAsync"
         };
         return(null);
     }
     catch (Exception ex)
     {
         logger.WriteLogError("**** LoyaltyEngineServices FAILURE: ApplyCouponAsync Exception Error= " + ex.Message);
         if (ex.InnerException != null)
         {
             logger.WriteLogError("**** InnerException  = " + ex.InnerException.Message);
         }
         return(null);
     }
 }
 /// <summary>
 /// QuickSearch
 /// </summary>
 /// <param name="searchCriteria"></param>
 /// <returns></returns>
 public async Task <IEnumerable <Customer> > QuickSearch(string searchCriteria)
 {
     try
     {
         return(await service.CustomerResource.QuickSearchAsync(searchCriteria));
     }
     catch (ApiException ex)
     {
         apiException = new APIExceptions {
             ErrorCode = ex.Code, ErrorDescription = ex.Message, ErrorApi = "QuickSearchAsync"
         };
         return(null);
     }
     catch (Exception ex)
     {
         logger.WriteLogError("**** LoyaltyEngineServices FAILURE: QuickSearch Exception Error= " + ex.Message);
         if (ex.InnerException != null)
         {
             logger.WriteLogError("**** InnerException  = " + ex.InnerException.Message);
         }
         return(null);
     }
 }
 /// <summary>
 /// CommitAsync
 /// </summary>
 /// <param name="commitCommand"></param>
 /// <returns></returns>
 public async Task <CartCommitment> CommitAsync(CommitCartCommand commitCommand)
 {
     try
     {
         return(await service.CartResource.CommitAsync(commitCommand));
     }
     catch (ApiException ex)
     {
         apiException = new APIExceptions {
             ErrorCode = ex.Code, ErrorDescription = ex.Message, ErrorApi = "ApproveAsync"
         };
         return(null);
     }
     catch (Exception ex)
     {
         logger.WriteLogError("**** LoyaltyEngineServices FAILURE: CommitAsync Exception Error= " + ex.Message);
         if (ex.InnerException != null)
         {
             logger.WriteLogError("**** InnerException  = " + ex.InnerException.Message);
         }
         return(null);
     }
 }
 /// <summary>
 /// GetDeviceProfileAsync
 /// </summary>
 /// <returns></returns>
 public async Task <DeviceProfile> GetDeviceProfileAsync()
 {
     try
     {
         return(await service.SystemResource.GetDeviceProfileAsync());
     }
     catch (ApiException ex)
     {
         apiException = new APIExceptions {
             ErrorCode = ex.Code, ErrorDescription = ex.Message, ErrorApi = "GetDeviceProfileAsync"
         };
         return(null);
     }
     catch (Exception ex)
     {
         logger.WriteLogError("**** LoyaltyEngineServices FAILURE: GetDeviceProfileAsync Exception Error= " + ex.Message);
         if (ex.InnerException != null)
         {
             logger.WriteLogError("**** InnerException  = " + ex.InnerException.Message);
         }
         return(null);
     }
 }
 /// <summary>
 /// CalculateAsync
 /// </summary>
 /// <param name="calculateCartCommand"></param>
 /// <returns></returns>
 public CalculatedCart CalculateCartAsync(CalculateCartCommand calculateCartCommand)
 {
     try
     {
         return(AsyncHelpers.RunSync <CalculatedCart>(() => service.CartResource.CalculateAsync(calculateCartCommand)));
     }
     catch (ApiException ex)
     {
         apiException = new APIExceptions {
             ErrorCode = ex.Code, ErrorDescription = ex.Message, ErrorApi = "CalculateAsync"
         };
         return(null);
     }
     catch (Exception ex)
     {
         logger.WriteLogError("**** LoyaltyEngineServices FAILURE: CalculateAsync Exception Error= " + ex.Message);
         if (ex.InnerException != null)
         {
             logger.WriteLogError("**** InnerException  = " + ex.InnerException.Message);
         }
         return(null);
     }
 }
 /// <summary>
 /// Get Cart By SourceExternalId
 /// </summary>
 /// <param name="cartSourceExternalId"></param>
 /// <returns></returns>
 public async Task <CalculatedCart> GetCartBySourceExternalId(string cartSourceExternalId)
 {
     try
     {
         return(await service.CartResource.GetBySourceExternalIdAsync(cartSourceExternalId));
     }
     catch (ApiException ex)
     {
         apiException = new APIExceptions {
             ErrorCode = ex.Code, ErrorDescription = ex.Message, ErrorApi = "GetBySourceExternalIdAsync"
         };
         return(null);
     }
     catch (Exception ex)
     {
         logger.WriteLogError("**** LoyaltyEngineServices FAILURE: GetCartBySourceExternalId Exception Error= " + ex.Message);
         if (ex.InnerException != null)
         {
             logger.WriteLogError("**** InnerException  = " + ex.InnerException.Message);
         }
         return(null);
     }
 }
 /// <summary>
 /// ReverseCommandAsync
 /// </summary>
 /// <param name="reverseCommand"></param>
 /// <returns></returns>
 public async Task <CommandResponse> ReverseCommandAsync(ReverseCommand reverseCommand)
 {
     try
     {
         return(await service.CommandResource.ReverseCommandAsync(reverseCommand));
     }
     catch (ApiException ex)
     {
         apiException = new APIExceptions {
             ErrorCode = ex.Code, ErrorDescription = ex.Message, ErrorApi = "ReverseCommandAsync"
         };
         return(null);
     }
     catch (Exception ex)
     {
         logger.WriteLogError("**** LoyaltyEngineServices FAILURE: ReverseCommandAsync Exception Error= " + ex.Message);
         if (ex.InnerException != null)
         {
             logger.WriteLogError("**** InnerException  = " + ex.InnerException.Message);
         }
         return(null);
     }
 }