Esempio n. 1
0
        public async Task <IActionResult> ConfigurePair(
            [FromBody] SymbolsPairConfigurationDTO model,
            [FromServices] IConfigurationService configurationService,
            [FromServices] IValidationService validationService)
        {
            try
            {
                await ValidateModelData(model, validationService);
            }
            catch (ValidationException ex)
            {
                return(BadRequest(ex.Message));
            }

            var dto      = new SymbolConfigurationDTO(model.BaseSymbol, model.TargetSymbol);
            var response = InvokeMethod(configurationService.AddCurrency, dto);

            if (response is SymbolConfigurationDTO)
            {
                var responseDTO = response as SymbolConfigurationDTO;
                return(Created($"api/configuration/{responseDTO.Id}", responseDTO));
            }

            return(response as IActionResult);
        }
Esempio n. 2
0
        public SymbolConfiguration Update(SymbolConfigurationDTO model)
        {
            var symbolConfiguration = Get(model.Id);

            symbolConfiguration.UpdateSymbols(model.BaseSymbol, model.TargetSymbol);
            return(symbolConfiguration);
        }
Esempio n. 3
0
        public SymbolConfiguration Add(SymbolConfigurationDTO model)
        {
            var symbolConfiguration = new SymbolConfiguration(Guid.NewGuid(), model.BaseSymbol, model.TargetSymbol);

            dbList.Add(symbolConfiguration);

            return(symbolConfiguration);
        }
Esempio n. 4
0
        public IActionResult DeleteSymbolConfiguration(
            [FromRoute] Guid configurationId,
            [FromServices] IConfigurationService configurationService)
        {
            var dto = new SymbolConfigurationDTO(configurationId);

            var response = InvokeMethod(configurationService.DeleteCurrency, dto);

            if (response is SymbolConfigurationDTO)
            {
                return(NoContent());
            }

            return(response as IActionResult);
        }
Esempio n. 5
0
        public IActionResult GetSymbolConfiguration(
            [FromRoute] Guid configurationId,
            [FromServices] IConfigurationService configurationService)
        {
            var dto = new SymbolConfigurationDTO(configurationId);

            var response = InvokeMethod(configurationService.GetCurrency, dto);

            if (response is SymbolConfigurationDTO)
            {
                return(new JsonResult(response as SymbolConfigurationDTO));
            }

            return(response as IActionResult);
        }
Esempio n. 6
0
        public void Add_And_Delete_New_Configuration()
        {
            // Arrange
            var repository = new SymbolConfigurationRepository();
            var allData    = repository.GetAll();

            foreach (var data in allData)
            {
                repository.Delete(data.Id);
            }

            // Act
            var dto = new SymbolConfigurationDTO("EUR", "PLN");

            var entity = repository.Add(dto);

            repository.Delete(entity.Id);

            // Assert
            Assert.False(repository.GetAll().Any());
        }
Esempio n. 7
0
 object InvokeMethod(Func <SymbolConfigurationDTO, SymbolConfigurationDTO> method, SymbolConfigurationDTO dto)
 {
     try
     {
         return(method(dto));
     }
     catch (EntityNotFoundException entityNotFound)
     {
         return(BadRequest(new ErrorModel(entityNotFound.Message)));
     }
     catch (ConfigurationSetupException configurationSetupException)
     {
         return(BadRequest(new ErrorModel(configurationSetupException.Message)));
     }
     catch (FixerException fixerException)
     {
         return(BadRequest(new ErrorModel(fixerException.Message)));
     }
     catch (Exception)
     {
         // Some logging
         return(new StatusCodeResult(500));
     }
 }
Esempio n. 8
0
        public SymbolConfigurationDTO GetCurrency(SymbolConfigurationDTO model)
        {
            var entity = Repository.Get(model.Id);

            return(new SymbolConfigurationDTO(entity.Id, entity.BaseSymbol, entity.TargetSymbol));
        }
Esempio n. 9
0
 public SymbolConfigurationDTO DeleteCurrency(SymbolConfigurationDTO model)
 {
     Repository.Delete(model.Id);
     return(model);
 }