public ValidationResult ValidateResource(EditRuleDTO editRuleDTO) { var result = new ValidationResult(); if (editRuleDTO != null) { var validator = new RuleValidator(); var vr = validator.Validate(editRuleDTO); if (vr.IsValid) { result.IsValid = true; return(result); } if (vr.Errors.Any()) { foreach (var error in vr.Errors) { result.ErrorMessages.Add(error.PropertyName, error.ErrorMessage); } } } return(result); }
// edit public void Update(int Id, EditRuleDTO editRuleDTO) { var updateRule = _ruleRepository.FindById(Id); if (updateRule != null && editRuleDTO != null) { _ruleRepository.Update(Id, _mapper.Map(editRuleDTO, updateRule)); } }
// add public RuleDTO Add(EditRuleDTO editRuleDTO) { if (editRuleDTO == null) { throw new ArgumentException(); } var currentRule = _mapper.Map <Rule>(editRuleDTO); try { _ruleRepository.Insert(currentRule); } catch (Exception) { throw; } return(_mapper.Map <RuleDTO>(currentRule)); }
public void Update(int ruleId, [FromBody] EditRuleDTO ruleDTO) { try { var result = _ruleService.ValidateResource(ruleDTO); if (!result.IsValid) { } if (result.IsValid) { _ruleService.Update(ruleId, ruleDTO); } } catch (Exception) { // Implement logging MS //throw StatusCode(500, "Internal server error"); } }