Exemple #1
0
        public async Task <Bank> Create(CreateBankDto dto)
        {
            var bank = await _bankRepo.GetAsync(dto.Bic);

            if (bank != null)
            {
                throw new ApplicationException("Банк уже зарегистрирован");
            }

            var country = await _countryService.GetById(dto.CountryCode);

            if (country is null)
            {
                throw new ModelNotFoundException("Страна не найдена");
            }

            var newBank = _mapper.Map <CreateBankDto, Bank>(dto);

            newBank.InCountry(country);

            await _bankRepo.AddAsync(newBank);

            await _bankRepo.SaveChangesAsync();

            return(newBank);
        }
        public async Task <IActionResult> Create([FromForm] CreateBankDto dto)
        {
            try
            {
                var bank = await _bankService.Create(dto);

                return(Created("Ok", _mapper.Map <Bank, BankToReturn>(bank)));
            }
            catch (Exception e)
            {
                return(BadRequest(new ApiException(StatusCodes.Status400BadRequest, e.Message)));
            }
        }
 public Task <BankDto> CreateAsync(CreateBankDto input)
 {
     throw new NotImplementedException();
 }