/// <summary> /// Handles a request /// </summary> /// <param name="request">The request</param> /// <param name="cancellationToken">Cancellation token</param> /// <returns> /// Response from the request /// </returns> public async Task <APIResponse> Handle(CreateWalletCommand request, CancellationToken cancellationToken) { try { var walletRequest = mapper.Map <Wallets>(request.Request); repository.Wallets.CreateWallet(walletRequest); await repository.SaveAsync(); Walletstatus walletstatus = new Walletstatus(); walletstatus.WalletId = walletRequest.Id; walletstatus.Action = "Wallet Created"; walletstatus.Status = walletRequest.Status; walletstatus.Reason = "Wallet Created"; walletstatus.StatusDate = DateTime.UtcNow; walletstatus.Active = 1; walletstatus.CreatedBy = walletRequest.CreatedBy; walletstatus.CreatedAt = DateTime.UtcNow; repository.WalletStatus.CreateWalletStatus(walletstatus); await repository.SaveAsync(); return(new APIResponse(new WalletDetails { WalletId = walletRequest.Id, WalletStatusId = walletstatus.Id }, HttpStatusCode.Created)); } catch (Exception ex) { logger.Error(ex, "Exception in method 'CreateWalletHandler()'"); var exMessage = ex.InnerException != null ? ex.InnerException.Message : ex.Message; return(new APIResponse(exMessage, HttpStatusCode.InternalServerError)); } }
/// <summary> /// Handles a request /// </summary> /// <param name="request">The request</param> /// <param name="cancellationToken">Cancellation token</param> /// <returns> /// Response from the request /// </returns> public async Task <APIResponse> Handle(UpdateWalletCommand request, CancellationToken cancellationToken) { try { var Wallet = await repository.Wallets.GetWalletById(request.WalletId); if (Wallet == null) { return(new APIResponse(HttpStatusCode.NotFound)); } int OldStatusId = Wallet.Status; if (request.IsPaused == true || request.IsReleased == true || request.IsChurned == true) { string status = string.Empty; if (request.IsPaused) { status = "PAUSED"; } else if (request.IsReleased) { status = "RELEASED"; } else if (request.IsChurned) { status = "CHURNED"; } var WalletStatus = await repository.MultiDetails.GetMultiDetailsByCode("WALLET STATUS"); if (WalletStatus != null && WalletStatus.Count > 0) { foreach (var type in WalletStatus) { if (type.Value.ToUpper() == status) { Wallet.Status = type.Id; break; } } } if (Wallet.Status != OldStatusId) { Walletstatus walletstatus = new Walletstatus(); walletstatus.WalletId = Wallet.Id; walletstatus.Action = "WALLET " + status; walletstatus.Status = Wallet.Status; walletstatus.Reason = "WALLET UPDATED - " + status; walletstatus.StatusDate = DateTime.UtcNow; walletstatus.Active = 1; walletstatus.CreatedBy = request.Request.UpdatedBy; walletstatus.CreatedAt = DateTime.UtcNow; repository.Wallets.UpdateWallet(Wallet); repository.WalletStatus.CreateWalletStatus(walletstatus); } } else { var WalletRequest = mapper.Map(request.Request, Wallet); if (WalletRequest.Status != OldStatusId) { Walletstatus walletstatus = new Walletstatus(); walletstatus.WalletId = WalletRequest.Id; walletstatus.Action = "Status Updated"; walletstatus.Status = WalletRequest.Status; walletstatus.Reason = "Status Updated"; walletstatus.StatusDate = DateTime.UtcNow; walletstatus.Active = 1; walletstatus.CreatedBy = WalletRequest.CreatedBy; walletstatus.CreatedAt = DateTime.UtcNow; repository.WalletStatus.CreateWalletStatus(walletstatus); } repository.Wallets.UpdateWallet(WalletRequest); } await repository.SaveAsync(); return(new APIResponse(HttpStatusCode.NoContent)); } catch (Exception ex) { logger.Error(ex, "Exception in method 'UpdateWalletHandler()'"); var exMessage = ex.InnerException != null ? ex.InnerException.Message : ex.Message; return(new APIResponse(exMessage, HttpStatusCode.InternalServerError)); } }