public async Task <IActionResult> UpdateAccount([FromRoute] Guid id, [FromBody] JsonPatchDocument <AccountRequest> update) { var command = new UpdateAccountCommand(id, _mapper.Map <JsonPatchDocument <Account> >(update)); var result = await _bus.Send(command); return(Ok(_mapper.Map <AccountResponse>(result))); }
public async Task <IHttpActionResult> Update([FromUri] long id, UpdateAccountCommand command) { command.Id = id; await Mediator.Send(command); return(Ok()); }
public async Task <bool> PostAccountUpdatesChangeDefaultPaymentMethod(int ownerId, BillingPaymentMethodTypes method) { bool ret = false; try { ownerCollection = testDataManager.GetEnrolledOwnerCollection(ownerId); IReadOnlyList <Account> accounts = await GetBillingAccountByPolicyHolderId(ownerCollection.OwnerInformation.UniqueId.ToString()); List <PaymentMethod> methods = await GetAccountPaymentMethods(ownerId); PaymentMethod newMethod = methods.Where(e => e.Type.Equals(method.ToString())).First(); UpdateAccountCommand command = GetUpdateAccountCommandFromAccount(accounts.First()); command.DefaultPaymentMethodId = newMethod.Id; RestRequestSpecification req = new RestRequestSpecification(); req.Verb = HttpMethod.Post; req.Headers = Headers; req.ContentType = "application/json"; req.RequestUri = $"v2/AccountUpdates"; req.Content = JsonSerializer.Serialize(command); var returnPost = await asyncRestClientBilling.ExecuteAsync <string>(req); ret = returnPost.Success; } catch (Exception ex) { log.Fatal(ex); } return(ret); }
public async Task <bool> PostAccountUpdateCharity(int ownerId, int charityId) { bool ret = false; try { ownerCollection = testDataManager.GetEnrolledOwnerCollection(ownerId); IReadOnlyList <Account> accounts = await GetBillingAccountByPolicyHolderId(ownerCollection.OwnerInformation.UniqueId.ToString()); UpdateAccountCommand command = GetUpdateAccountCommandFromAccount(accounts.First()); CharityIds charity = Charity.Charities.Where(i => i.Id == charityId).First(); if (charity != null) { command.CharityId = charity.UniqueId; RestRequestSpecification req = new RestRequestSpecification(); req.Verb = HttpMethod.Post; req.Headers = Headers; req.ContentType = "application/json"; req.RequestUri = $"v2/AccountUpdates"; req.Content = JsonSerializer.Serialize(command); var returnPost = await asyncRestClientBilling.ExecuteAsync <string>(req); ret = returnPost.Success; } } catch (Exception ex) { log.Fatal(ex); } return(ret); }
public async Task <IActionResult> Update([FromBody] UpdateAccountCommand updateAccountCommand) { updateAccountCommand.Id = User.GetUserId(); var account = await _mediator.Send(updateAccountCommand); return(Ok(account)); }
public async Task <APIResult> Update([FromBody] UpdateAccountCommand command) { var rs = await mediator.Send(command); return(new APIResult() { Result = rs }); }
public async Task <AccountDTO> UpdateAccountAsync(UpdateAccountCommand command, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var account = await GetAccountAsync(command.AccountId, cancellationToken); SetAccountProperties(account, command); await _context.SaveChangesAsync(cancellationToken); return(account.ToDTO()); }
public UpdateAccountCommand GetUpdateAccountCommandFromAccount(Account account) { UpdateAccountCommand ret = new UpdateAccountCommand(); ret.AccountId = account.Id; ret.BillCycleDay = account.BillCycleDay; ret.CharityId = account.CharityId; ret.DefaultPaymentMethodId = account.DefaultPaymentMethodId; ret.NonReferencedCreditMethodTypeId = account.NonReferencedCreditMethodTypeId; return(ret); }
public async Task <IActionResult> UpdateAccount(int accountId, AccountForUpdateDto accountForUpdateDto) { var command = new UpdateAccountCommand(accountForUpdateDto, accountId); var result = await Mediator.Send(command); if (result) { return(NoContent()); } throw new Exception("Error updating the account."); }
private void UpdateAccountProperties(Account currentAccount, UpdateAccountCommand request, AccountType accountType) { currentAccount.Name = request.Name; currentAccount.Zip = request.Zip; currentAccount.Country = request.Country; currentAccount.City = request.City; currentAccount.Street = request.Street; currentAccount.StreetNo = request.StreetNo; currentAccount.ContactEmail = request.ContactEmail; currentAccount.AccountTypeId = accountType == null ? 1 : accountType.Id; currentAccount.ModifiedBy = request.ModifiedBy; currentAccount.MoidifiedAt = DateTime.UtcNow; }
public async Task <IActionResult> Update(string id, [FromBody] Account accountIn) { var command = new UpdateAccountCommand(id, accountIn); var result = await _mediator.Send(command); if (result) { _logger.LogInformation("Account " + id + " was updated"); return(NoContent()); } _logger.LogInformation("Error while account updating"); return(NotFound()); }
public async Task <ActionResult> Put([FromRoute] string id, [FromBody] UpdateAccountCommand request) { var response = await _updateAccountCommandHandler.HandleAsync(new UpdateAccountCommand() { Id = id, Address = request.Address, Age = request.Age, FirstName = request.FirstName, LastName = request.LastName }, CancellationToken.None); return(Ok(response)); }
public void Init() { InitTestClass(); request.Verb = HttpMethod.Post; request.RequestUri = $"v2/accountupdates"; command = new UpdateAccountCommand(); command.AccountId = BillingApiTestSettings.Default.BillingAccountUpdateTestAccountId.ToString(); command.DefaultPaymentMethodId = BillingApiTestSettings.Default.BillingAccountUpdateTestDefaultPaymentMethodId; command.BillCycleDay = BillingApiTestSettings.Default.BillingAccountUpdateTestBillCycleDay; command.CharityId = BillingApiTestSettings.Default.BillingAccountUpdateTestCharityId; command.NonReferencedCreditMethodTypeId = BillingApiTestSettings.Default.BillingAccountUpdateTestNonReferencedCreditMethodTypeId; }
public async Task ThrowNotFoundExceptionForNonExistingAccountId() { // Arrange UpdateAccountCommand updateCommand = new UpdateAccountCommand() { Id = 2, AccountId = "0000", AccountName = "Account Payable Update", Active = 1, ParentAccount = 1, }; UpdateAccountCommandHandler handler = new UpdateAccountCommandHandler(_Database); await Assert.ThrowsAsync <NotFoundException> (() => handler.Handle(updateCommand, CancellationToken.None)); }
public Task <CancellationToken> Handle(UpdateAccountCommand command, CancellationToken cancellationToken) { Logger.Log($"{nameof(UpdateAccountCommand)} handler invoked"); if (command == null) { throw new ArgumentNullException(nameof(command)); } if (string.IsNullOrEmpty(command.Account.Name)) { throw new Exception($"{command.Account.Name} is required"); } // TODO Figure out how to validate this from the "database" without making it a long synchronous call if (string.IsNullOrEmpty(command.Account.AccountTypeCode) || (command.Account.AccountTypeCode != "LIRA" && command.Account.AccountTypeCode != "TFSA" && command.Account.AccountTypeCode != "RESP" && command.Account.AccountTypeCode != "RRSP" && command.Account.AccountTypeCode != "Unreg")) { throw new Exception($"Invalid {command.Account.AccountTypeCode}. Must be one of values [LIRA, RESP, RRSP, TFSA, UnReg]"); } Logger.Log($"Looking for aggregate: {command.Id}"); var aggregate = _repository.GetById(command.Id); if (command.Account.AccountTypeCode != aggregate.AccountTypeCode) { throw new Exception($"AccountTypeCode [{command.Account.AccountTypeCode}] does not match existing AccountTypeCode [{aggregate.AccountTypeCode}] for Account"); } Logger.Log($"Found existing aggregate to update: {aggregate.Id}"); // Validate that AccountId exists if (aggregate.Id == Guid.Empty) { throw new Exception($"Account with Id {aggregate.Id} does not exist"); } aggregate.UpdateAccount(command.Account); Logger.Log($"Updated aggregate {aggregate.Id}"); _repository.Save(aggregate, aggregate.Version); Logger.Log($"Completed saving {nameof(Account)} aggregate to event store"); return(Task.FromResult(cancellationToken)); }
public async Task <IActionResult> UpdateAccount(int id, UpdateAccountCommand account) { if (id != account.Id) { return(BadRequest()); } var foundAndUpdated = await _mediator.Send(account); if (!foundAndUpdated) { return(NotFound()); } return(NoContent()); }
public string Handle(PlaceBetCommand command) { Bet bet = Mapper.Map <Bet>(command); dbContext.GetCollection <Bet>().InsertOne(bet); AccountByUsernameQuery accountQuery = new AccountByUsernameQuery(command.Username); Account account = accountByUsernameHandler.Handle(accountQuery); account.Balance -= command.Stake; UpdateAccountCommand updateAccountCommand = Mapper.Map <UpdateAccountCommand>(account); updateAccountHandler.Handle(updateAccountCommand); return(bet.Id); }
public async Task UpdateAccountSuccessfuly() { // Arrange UpdateAccountCommand updateCommand = new UpdateAccountCommand() { Id = 10, AccountId = "0000", AccountName = "Account Payable Update", Active = 1, ParentAccount = 1, }; UpdateAccountCommandHandler handler = new UpdateAccountCommandHandler(_Database); // Act var result = await handler.Handle(updateCommand, CancellationToken.None); // Assert Assert.Equal(Unit.Value, result); }
public async Task <Result <bool> > Handle(UpdateAccountCommand request, CancellationToken cancellationToken) { try { var user = await _userRepository.GetUserByEmail(request.ModifiedBy); var isAdminOfAccount = await _accountAdminRepository.IsAdminOfAccount(user.Id, request.Id); if (user.Role.Name != "Admin" && !isAdminOfAccount) { return(Result <bool> .AccessDenied("No access!")); } var account = await _accountRepository.Get(request.Id); if (account == null) { return(Result <bool> .BadRequest($"Account with Id: {request.Id} not found!")); } if (request.AdminEmails != null) { await UpdateAccountAdmins(account.Id, request.ModifiedBy, request.AdminEmails); } if (request.UserEmails != null) { await UpdateAccountUsers(account.Id, request.ModifiedBy, request.UserEmails); } var accountType = await _accountTypeRepository.GetAccountTypeByName(request.AccountType); UpdateAccountProperties(account, request, accountType); var res = await _accountRepository.Update(account); return(Result <bool> .Ok(res)); } catch (Exception e) { return(Result <bool> .Failure(e.Message)); } }
public async Task <IActionResult> UpdateAccount(UpdateAccountCommand command) { return(Ok(await _mediator.Send(command))); /*try * { * return Ok(await _mediator.Send(command)); * } * catch (ArgumentException) * { * * } * catch () * { * * }*/ //throw new InvalidOperationException("hhh"); //new UnprocessableEntityObjectResult("dddd"); // return Ok(await _mediator.Send(command)); }
public async Task <IActionResult> UpdateAccount(UpdateAccountCommand command) { if (!ModelState.IsValid) { ViewBag.HasAvatar = _userService.HasAvatar(); var countryListVm = await Mediator.Send(new GetCountryListQuery()); ViewBag.Countries = countryListVm.Countries.Select(x => new SelectListItem() { Value = x.Id.ToString(), Text = x.Name }).ToList(); return(View(command)); } await Mediator.Send(command); return(RedirectToAction(nameof(UpdateAccount))); }
public async void Handler_ShouldApplyCorrectCommission(double commission) { var uow = Substitute.For <IUow>(); var comissionMapper = Substitute.For <ICommissionMapper>(); var comissionApplier = Substitute.For <ICommissionApplier>(); comissionMapper.GetCommissionApplier(Arg.Any <string>()).Returns(comissionApplier); comissionApplier.Apply(Arg.Any <decimal>()).Returns(commission); var updateAccountCommandHandler = new UpdateAccountCommandHandler(uow, comissionMapper); var account = new Account { Id = 2, AccountId = 9834, Balance = 456.45 }; var accounts = new List <Account>() { account }; var command = new UpdateAccountCommand() { AccountId = 100, Amount = 600, MessageType = "PAYMENT", Origin = "MASTER", TransactionId = Guid.NewGuid() }; uow.AccountRepository .Get(Arg.Any <Expression <Func <Account, bool> > >(), Arg.Any <Func <IQueryable <Account>, IOrderedQueryable <Account> > >(), StringValues.Empty) .Returns(accounts); var actualAccounts = await updateAccountCommandHandler.Handle(command, new CancellationToken()); await uow.AccountTransactionRepository.Received().Insert(Arg.Is <AccountTransaction>(at => at.Commission == commission)); }
private void SetAccountProperties(Account account, UpdateAccountCommand command) { if (command.Sum.HasValue) { if (account.Type == AccountType.Deposit) { account.Sum += command.Sum.Value; if (account.Sum < 0) { throw new AccountInvalidOperationException("Deposit sum can not be less than 0."); } } else { account.Sum += command.Sum.Value; } } if (command.Type.HasValue) { account.Type = command.Type.Value; } }
public async Task Update([FromBody] UpdateAccountCommand command) => await new UpdateAccountCommandHandler(persistence).Handle(command);
public async Task Handle(AccountUpdatedEvent @event) { UpdateAccountCommand command = _mapper.Map <UpdateAccountCommand>(@event); await _mediator.Send(command); }
public async Task UpdateAccount(UpdateAccountCommand command) { command.Id = User.Claims.GetAccountId(); await commandFactory.Execute(command); }
public async Task <ActionResult> UpdateAccount(int id, [FromBody] UpdateAccountCommand model) { await _Mediator.Send(model); return(NoContent()); }
public Task UpdateAccount(UpdateAccountCommand command, CancellationToken token) => HandlerDispatcher.Invoke <UpdateAccountHandler, UpdateAccountCommand>(command, token);