// Shopkeeper to Customer Transaction public string ShopkeepertoCustomerTransaction(string ChangerQS) { _shopkeeperToCustomer = ChangerUtils.URLSplitter <ShopKeeperToCustomerTransaction>(ChangerQS, out IsRequestDTOSuccess); _crossTransactionResponse = new CrossTransactionResponse(); try { if (IsRequestDTOSuccess) { _crossTransactionResponse = _terminalService.ShopkeeperToCustomerTransaction(_shopkeeperToCustomer); } else { _crossTransactionResponse.ErrorNumber = 1303; _crossTransactionResponse.ErrorMessage = ConfigurationManager.AppSettings[_crossTransactionResponse.ErrorNumber.ToString()]; } } catch (ChangerMintsError Er) { _logerr.LogError(Er.Message, Er, LogType.Error); return(ChangerUtils.ResponseConcatenater <ChangerMintsError>(Er, true)); } catch (Exception ex) { _crossTransactionResponse.ErrorNumber = 2001; _crossTransactionResponse.ErrorMessage = ConfigurationManager.AppSettings[_crossTransactionResponse.ErrorNumber.ToString()]; } return(ChangerUtils.ResponseConcatenater <CrossTransactionResponse>(_crossTransactionResponse, true)); }
// Shopkeeper to Customer Transaction Service public CrossTransactionResponse ShopkeeperToCustomerTransaction(ShopKeeperToCustomerTransaction ShopkeeperToCustomer) { _crossTransactionResponse = new CrossTransactionResponse(); try { var messageCreators = new List <ModelResponses <CrossTransactionResponse, ChangerValidations> > { // Check if the Shopkeeper Account is of Valid length new ModelResponses <CrossTransactionResponse, ChangerValidations>(model => model.IsShopKeeperAccountValid( ShopkeeperToCustomer.ShopKeeperAccountNumber), 1101), // Check if the Customer Account is of Valid length new ModelResponses <CrossTransactionResponse, ChangerValidations>(model => model.IsCustomerNFCTagIDValid( ShopkeeperToCustomer.NFCTagID), 1202), // Check if the Amount is of >0 new ModelResponses <CrossTransactionResponse, ChangerValidations>(model => model.IsAmountValid( ShopkeeperToCustomer.Amount), 1401), }; ModelResponses <CrossTransactionResponse, ChangerValidations> errorCreator = null; if (!ChangerValidations.GetInputParametersStatus <CrossTransactionResponse, ChangerValidations>(messageCreators, out errorCreator)) { return(errorCreator.FillErrorDTO <CrossTransactionResponse>()); } // Get current customer details var currentCustomerDetails = _changerMintsUOW.Repository <CustomerDetail>().Query().Filter(q => q.NFCTagID == ShopkeeperToCustomer.NFCTagID).Get().FirstOrDefault(); // Verify if the customer is registered to the changer if (currentCustomerDetails == null) { //Transaction Fail _crossTransactionResponse.ErrorNumber = 1208; _crossTransactionResponse.ErrorMessage = ConfigurationManager.AppSettings[_crossTransactionResponse.ErrorNumber.ToString()]; return(_crossTransactionResponse); } var currentCustomerNFCDetails = _changerMintsUOW.Repository <CustomerNFCTagDetail>().Query().Filter(q => q.NFCTagID == ShopkeeperToCustomer.NFCTagID).Get().FirstOrDefault(); if (currentCustomerNFCDetails.NFCTagUID != ShopkeeperToCustomer.NFCTagUID) { //Transaction Fail - NFCUID mis match _crossTransactionResponse.ErrorNumber = 1210; _crossTransactionResponse.ErrorMessage = ConfigurationManager.AppSettings[_crossTransactionResponse.ErrorNumber.ToString()]; return(_crossTransactionResponse); } // Retrieve particulars from the database for given Shopkeeper and Customer var currentShopkeeperAccountDetails = _changerMintsUOW.Repository <ShopKeeperAccountDetail>().Query().Filter(q => q.ShopKeeperAccountNumber == ShopkeeperToCustomer.ShopKeeperAccountNumber).Get().FirstOrDefault(); var currentCustomerAccountDetails = _changerMintsUOW.Repository <CustomerAccountDetail>().Query().Filter(q => q.CustomerAccountNumber == currentCustomerDetails.CustomerAccountNumber).Get().FirstOrDefault(); // Verify if the Shopkeeper is registered to our system. if (currentShopkeeperAccountDetails == null) { //Transaction Fail _crossTransactionResponse.ErrorNumber = 1107; _crossTransactionResponse.ErrorMessage = ConfigurationManager.AppSettings[_crossTransactionResponse.ErrorNumber.ToString()]; return(_crossTransactionResponse); } // Verify if the customer is registered to the changer if (currentCustomerAccountDetails == null) { //Transaction Fail _crossTransactionResponse.ErrorNumber = 1208; _crossTransactionResponse.ErrorMessage = ConfigurationManager.AppSettings[_crossTransactionResponse.ErrorNumber.ToString()]; return(_crossTransactionResponse); } // If the balance is greater than the transferable amount, start the transaction if (currentShopkeeperAccountDetails.SenderBalance > ShopkeeperToCustomer.Amount && currentShopkeeperAccountDetails.SenderBalance > 0) { // Start the transaction currentShopkeeperAccountDetails.SenderBalance -= ShopkeeperToCustomer.Amount; currentCustomerAccountDetails.Balance += ShopkeeperToCustomer.Amount; _changerMintsUOW.Repository <ShopKeeperAccountDetail>().Update(currentShopkeeperAccountDetails); _changerMintsUOW.Repository <CustomerAccountDetail>().Update(currentCustomerAccountDetails); _changerMintsUOW.Save(); // Update Shopkeeper & Customer Transaction Details var getShopkeeperAccountDetails = _changerMintsUOW.Repository <ShopKeeperAccountDetail>().Query().Filter(q => q.ShopKeeperAccountNumber == ShopkeeperToCustomer.ShopKeeperAccountNumber).Get().FirstOrDefault(); var getCustomerAccountDetails = _changerMintsUOW.Repository <CustomerAccountDetail>().Query().Filter(q => q.CustomerAccountNumber == currentCustomerDetails.CustomerAccountNumber).Get().FirstOrDefault(); var query1 = from s in _changerMintsUOW.Repository <ShopKeeperAccountDetail>().Query().Filter(q => q.ShopKeeperAccountNumber == ShopkeeperToCustomer.ShopKeeperAccountNumber).Get() select new CrossTransactionResponse { ShopKeeperSenderBalance = s.SenderBalance, ShopKeeperReceiverBalance = s.ReceiverBalance }; UpdateTransactionDetails <ShopKeeperToCustomerTransaction>(ShopkeeperToCustomer); // Fill the Response DTO & send back to the controller _crossTransactionResponse.ErrorNumber = 1302; _crossTransactionResponse.ErrorMessage = ConfigurationManager.AppSettings[_crossTransactionResponse.ErrorNumber.ToString()]; _crossTransactionResponse.ShopKeeperSenderBalance = Convert.ToDecimal(getShopkeeperAccountDetails.SenderBalance); _crossTransactionResponse.ShopKeeperReceiverBalance = Convert.ToDecimal(getShopkeeperAccountDetails.ReceiverBalance); } else { _crossTransactionResponse.ErrorNumber = 1301; _crossTransactionResponse.ErrorMessage = ConfigurationManager.AppSettings[_crossTransactionResponse.ErrorNumber.ToString()]; } } catch (Exception e) { throw e; } return(_crossTransactionResponse); }