public PermissionDtoContainer AddOperations(SecurityResourceDto resource, List <OperationDto> operationDtos) { PermissionDtoContainer responseContainer = new PermissionDtoContainer(); PermissionTDataAccess rtoDa = new PermissionTDataAccess(); List <PermissionDto> insertList = new List <PermissionDto>(); foreach (var operationDto in operationDtos) { var relations = rtoDa.GetSingle(it => it.ResourceId == resource.SecurityResourceId && it.OperationId == operationDto.OperationId); if (relations == null) { PermissionDto dto = new PermissionDto() { ResourceId = resource.SecurityResourceId, OperationId = operationDto.OperationId }; insertList.Add(dto); responseContainer.PermissionDtoList.Add(dto); } //else //{ // PermissionDto response = new PermissionDto(); // resource.SetIdentity(operationDto.Id); // response.Response.AddBusinessException("ارتباط قبلا تعریف شده است!", BusinessExceptionEnum.Operational); //} } if (insertList.Count > 0) { rtoDa.Insert(insertList); } return(responseContainer); }
public PermissionDto AddOperation(SecurityResourceDto resource, OperationDto operationDto) { PermissionDto response = new PermissionDto(); PermissionTDataAccess rtoDa = new PermissionTDataAccess(); var relations = rtoDa.GetSingle(it => it.ResourceId == resource.SecurityResourceId && it.OperationId == operationDto.OperationId); if (relations == null) { response = new PermissionDto() { ResourceId = resource.SecurityResourceId, OperationId = operationDto.OperationId }; rtoDa.Insert(response); } else { response.Response.AddBusinessException("ارتباط قبلا تعریف شده است!", BusinessExceptionEnum.Operational); } return(response); }