public async Task <IActionResult> CreateAccount([FromBody] BankAccountCreateDto dto) { var account = await this.sender.Send(new CreateBankAccountCommand(this.currentUserId, dto.Name)); if (account.Status != ResultStatus.Success) { return(this.ToActionResult(account)); } return(Created($"{HttpContext.Request.Path}/{account.Value.Id}", account.Value)); }
public async Task <IActionResult> Create([FromForm] BankAccountCreateDto dto) { try { var account = await _bankAccountsService.Create(dto); return(Created("Ok", _mapper.Map <BankAccount, BankAccountToReturn>(account))); } catch (Exception e) { return(BadRequest(new ApiException(StatusCodes.Status400BadRequest, e.Message))); } }
public IActionResult Create(long customerId, [FromBody] BankAccountCreateDto bankAccountCreateDto) { //LoggerBasSingleton.Instance.Log("Inicio de función"); //LoggerThreadSafe1Singleton.Instance.Log("Inicio de función"); //LoggerThreadSafe2Singleton.Instance.Log("Inicio de función"); //LoggerThreadSafe3Singleton.Instance.Log("Inicio de función"); LoggerThreadSafe4LazySingleton.Instance.Log("Inicio de función"); bankAccountCreateDto.CustomerId = customerId; BankAccount bankAccount = _bankAccountCreateAssembler.toEntity(bankAccountCreateDto); _bankAccountRepository.Create(bankAccount); LoggerThreadSafe4LazySingleton.Instance.Log("Fin de función"); return(StatusCode(StatusCodes.Status201Created, new ApiStringResponseDto("BankAccount Created!"))); }
public IActionResult Create(long customerId, [FromBody] BankAccountCreateDto bankAccountCreateDto) { bool uowStatus = false; try { uowStatus = _unitOfWork.BeginTransaction(); bankAccountCreateDto.CustomerId = customerId; //TODO: Validations with Notification Pattern BankAccount bankAccount = _bankAccountCreateAssembler.toEntity(bankAccountCreateDto); _bankAccountRepository.Create(bankAccount); _unitOfWork.Commit(uowStatus); return(StatusCode(StatusCodes.Status201Created, new ApiStringResponseDto("BankAccount Created!"))); } catch (Exception ex) { _unitOfWork.Rollback(uowStatus); Console.WriteLine(ex.StackTrace); return(StatusCode(StatusCodes.Status500InternalServerError, new ApiStringResponseDto("Internal Server Error"))); } }
public async Task <BankAccount> Create(BankAccountCreateDto dto) { var currency = await _currencyRepo.GetAsync(dto.CurrencyCode); var bank = await _bankRepo.GetAsync(dto.BankBic); var counterparty = await _counterpartyRepo.GetAsync(dto.CompanyId); var account = _mapper.Map <BankAccountCreateDto, BankAccount>(dto); account.InBank(bank) .InCurrency(currency) .AttachCounterparty(counterparty); await _bankAccountRepo.AddAsync(account); await _bankAccountRepo.SaveChangesAsync(); return(account); }
public async Task <IHttpActionResult> CreateAccount([FromBody] BankAccountCreateDto bankAccountCreateDto, long userId) { if (!ModelState.IsValid) { return(BadRequest("Account name is required!")); } if (!IsUserAuthorized(userId)) { return(Unauthorized()); } bankAccountCreateDto.UserId = userId; var bankAccount = _mapper.Map <BankAccount>(bankAccountCreateDto); _unitOfWork.BankAccounts.Add(bankAccount); if (await _unitOfWork.Complete() > 0) { return(Created(new Uri(Request.RequestUri + "/" + bankAccount.Id), bankAccount)); } return(BadRequest("An error happened while creating new account!")); }
public BankAccount toEntity(BankAccountCreateDto bankAccountCreateDto) { return(_mapper.Map <BankAccount>(bankAccountCreateDto)); }