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); }
public SymbolConfiguration Update(SymbolConfigurationDTO model) { var symbolConfiguration = Get(model.Id); symbolConfiguration.UpdateSymbols(model.BaseSymbol, model.TargetSymbol); return(symbolConfiguration); }
public SymbolConfiguration Add(SymbolConfigurationDTO model) { var symbolConfiguration = new SymbolConfiguration(Guid.NewGuid(), model.BaseSymbol, model.TargetSymbol); dbList.Add(symbolConfiguration); return(symbolConfiguration); }
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); }
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); }
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()); }
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)); } }
public SymbolConfigurationDTO GetCurrency(SymbolConfigurationDTO model) { var entity = Repository.Get(model.Id); return(new SymbolConfigurationDTO(entity.Id, entity.BaseSymbol, entity.TargetSymbol)); }
public SymbolConfigurationDTO DeleteCurrency(SymbolConfigurationDTO model) { Repository.Delete(model.Id); return(model); }