public async Task <IActionResult> Add([FromBody] AddLineModel model) { try { IMerchantConfigurationLine cfgLine = await _configurationService.AddAsync(Mapper.Map <MerchantConfigurationLine>(model)); return(Ok(Mapper.Map <LineModel>(cfgLine))); } catch (EntityAlreadyExistsException e) { _log.Error(e, $"PartitionKey = {e.PartitionKey}, RowKey = {e.RowKey}"); return(BadRequest(ErrorResponse.Create(e.Message))); } catch (InvalidInputException e) { _log.Error(e, model.ToDetails()); return(BadRequest(e.ToErrorResponse())); } catch (ValidationRuleNotFoundException e) { _log.Error(e, model.ToDetails()); return(NotFound(ErrorResponse.Create($"Rule with id {model.RuleId} not found"))); } catch (InputNotRequiredException e) { _log.Error(e, e.Message, $"ruleId = {e.RuleId}"); return(BadRequest(ErrorResponse.Create(e.Message))); } }
public async Task UpdateAsync(IMerchantConfigurationLine src) { string pKey = MerchantConfigurationLineEntity.ByMerchant.GeneratePartitionKey(src.MerchantId); string rKey = MerchantConfigurationLineEntity.ByMerchant.GenerateRowKey(src.RuleId); MerchantConfigurationLineEntity updatedEntity = await _storage.MergeAsync(pKey, rKey, entity => { if (src.RuleInput != null) { entity.RuleInput = src.RuleInput; } if (src.Enabled.HasValue) { entity.Enabled = src.Enabled.Value; } return(entity); }); if (updatedEntity == null) { throw new EntityNotFoundException(pKey, rKey); } }
public async Task <IMerchantConfigurationLine> AddAsync(IMerchantConfigurationLine src) { MerchantConfigurationLineEntity entity = MerchantConfigurationLineEntity.ByMerchant.Create(src); await _storage.InsertThrowConflict(entity); return(Mapper.Map <MerchantConfigurationLine>(entity)); }
public async Task <IMerchantConfigurationLine> AddAsync(IMerchantConfigurationLine src) { var rule = _componentContext.ResolveNamed <IValidationRule>(src.RuleId); if (rule == null) { throw new ValidationRuleNotFoundException(src.RuleId); } if (!string.IsNullOrEmpty(src.RuleInput)) { IEnumerable <ValidationResult> validationErrors = rule.ValidateInput(src.RuleInput).ToList(); if (validationErrors.Any()) { throw new InvalidInputException(src.RuleId, validationErrors); } } return(await _repository.AddAsync(src)); }