/// <summary> /// Handles the specified command. /// </summary> /// <param name="command">The command.</param> public void Handle(HmrcRegisterCustomerCommand command) { InfoAccumulator info = Validate(command); if (info.HasErrors) { SendReply(info, command); return; } info = MarketPlaceQueries.ValidateCustomerMarketPlace(HmrcInternalId, command.UserName); if (info.HasErrors) { SendReply(info, command); return; } int customerId = int.Parse(EncryptionUtils.SafeDecrypt(command.CustomerId)); AccountModel hmrcAccountModel = new AccountModel { login = command.UserName, password = command.Password }; byte[] securityData = SerializationUtils.SerializeToBinaryXml(hmrcAccountModel); securityData = EncryptionUtils.Encrypt(securityData); int marketplaceId = (int)MarketPlaceQueries.CreateNewMarketPlace(customerId, command.UserName, securityData, HmrcInternalId); if (marketplaceId < 1) { string msg = string.Format("could not create marketplace for customer {0}", command.CustomerId); //writes encrypted customer id Log.Error(msg); throw new Exception(msg); } var updateHistory = new CustomerMarketPlaceUpdateHistory() { CustomerMarketPlaceId = marketplaceId, UpdatingStart = DateTime.UtcNow }; int marketPlaceHistoryId = (int)MarketPlaceQueries.UpsertMarketPlaceUpdatingHistory(updateHistory); if (marketPlaceHistoryId < 1) { string message = string.Format("could not upsert marketplace history for customer: {0}", command.CustomerId); Log.Error(message); throw new Exception(message); } HmrcGetVatReturns3dPartyCommand commandToSend = new HmrcGetVatReturns3dPartyCommand { UserName = command.UserName, Password = command.Password, CustomerId = command.CustomerId }; SendCommand(ThirdPartyServiceConfig.Address, commandToSend, command); }
/// <summary> /// Handles the specified command. /// </summary> /// <param name="command">The command.</param> public async void Handle(HmrcGetVatReturns3dPartyCommand command) { HmrcVatReturnsInfo vatReturns = await HmrcService.GetVatReturns(command.UserName, command.Password); if (vatReturns.Info.HasErrors) { SendReply(vatReturns.Info, command); return; } InfoAccumulator info = new InfoAccumulator(); SendReply(info, command, resp => { resp.Password = command.Password; resp.UserName = command.UserName; resp.CustomerId = command.CustomerId; PrepareResponse(resp, vatReturns); }); }