/// <summary> /// Delete Rule /// </summary> /// <param name="request">rule request.</param> /// <returns>Rule message.</returns> public RuleMessage DeleteRule(RuleRequest request) { RuleMessage message = new RuleMessage(); try { request.FindRuleDto = FindRuleDto.RuleId; RuleResponsePivot response = _serviceRule.FindRules(request.ToPivot()); if (response?.RulePivot != null) { _serviceRule.DeleteRule(request.ToPivot()); message.OperationSuccess = true; } else { message.ErrorMessage = RuleMessageResource.NotFound; message.ErrorType = ErrorType.FunctionalError; message.OperationSuccess = false; } } catch (Exception e) { message.ErrorType = ErrorType.TechnicalError; message.ErrorMessage = e.Message; } return(message); }
/// <summary> /// Search Rule /// </summary> /// <param name="request">rule request.</param> /// <returns>Rule message.</returns> public RuleMessage FindRules(RuleRequest request) { RuleMessage message = new RuleMessage(); try { message = _serviceRule.FindRules(request.ToPivot()).ToMessage(); message.OperationSuccess = true; } catch (Exception e) { message.ErrorType = ErrorType.TechnicalError; message.ErrorMessage = e.Message; } return(message); }
/// <summary> /// Create new Rule. /// </summary> /// <param name="request">rule request.</param> /// <returns>Rule message.</returns> public RuleMessage CreateRule(RuleRequest request) { RuleMessage message = new RuleMessage(); try { message = _serviceRule.CreateRule(request.ToPivot()).ToMessage(); if (message?.RuleDto != null) { //create user rule. UserMessage userMessage = _serviceUser.GetAllUsers().ToMessage(); if (userMessage?.UserDtoList != null) { foreach (var user in userMessage.UserDtoList) { _serviceUserRule.CreateUserRule(new UserRuleRequestPivot() { UserRulePivot = new UserRulePivot() { RuleId = message.RuleDto.RuleId, UserRuleStatus = false, UserId = user.UserId } }); } } message.OperationSuccess = true; } else { if (message != null) { message.ErrorMessage = RuleMessageResource.ServiceResponseNull; message.ErrorType = ErrorType.TechnicalError; message.OperationSuccess = false; } } } catch (Exception e) { message.ErrorType = ErrorType.TechnicalError; message.ErrorMessage = e.Message; } return(message); }