コード例 #1
0
        public static EndpointRuleEntity Patch(this EndpointRuleEntity entity, EndpointRuleDto dto)
        {
            entity.Order       = dto.Order;
            entity.Name        = dto.Name;
            entity.Path        = dto.Path;
            entity.Enabled     = dto.Enabled;
            entity.Hostname    = dto.Hostname;
            entity.Scheme      = string.Join(";", dto.Scheme);
            entity.HttpMethods = string.Join(";", dto.HttpMethods);

            entity.Actions     = dto.Actions.Select(dtoAction => dtoAction.ToEntity()).ToList();
            entity.Permissions = dto.Permissions.Select(dtoPermission => dtoPermission.ToEntity()).ToList();

            return(entity);
        }
コード例 #2
0
        public async Task <ActionResult> Add([FromBody] EndpointRuleDto rule)
        {
            var entity = _mapper.Map <EndpointRuleEntity>(rule);

            foreach (var endpointActionEntity in entity.Actions)
            {
                UpdateAction(endpointActionEntity);
            }
            await _endpointRuleRepository.AddAsync(entity);

            //var dbModel = _mapper.Map<MiddlerRuleDbModel>(rule);
            //UpdateActions(dbModel);
            //await Repo.AddAsync(dbModel);
            return(Ok());
        }
コード例 #3
0
        public async Task <ActionResult <EndpointRuleDto> > Update(Guid id, [FromBody] EndpointRuleDto ruleDto)
        {
            var ruleInDb = await _endpointRuleRepository.Find(id);

            _mapper.Map(ruleDto, ruleInDb);
            foreach (var endpointActionEntity in ruleInDb.Actions)
            {
                endpointActionEntity.EndpointRuleEntityId = id;
                UpdateAction(endpointActionEntity);
            }


            await _endpointRuleRepository.UpdateAsync(ruleInDb);

            var updated = await _endpointRuleRepository.GetByIdAsync(id);

            return(Ok(updated.ToEndpointRuleDto(_internalHelper)));
        }
コード例 #4
0
        public static EndpointRuleDto ToEndpointRuleDto(this EndpointRuleEntity entity, InternalHelper internalHelper)
        {
            if (entity == null)
            {
                return(null);
            }

            var dto = new EndpointRuleDto();

            dto.Id          = entity.Id;
            dto.Name        = entity.Name;
            dto.Enabled     = entity.Enabled;
            dto.Hostname    = entity.Hostname;
            dto.Path        = entity.Path;
            dto.Order       = entity.Order;
            dto.Scheme      = MappingHelper.Split(entity.Scheme);
            dto.HttpMethods = MappingHelper.Split(entity.HttpMethods);
            dto.Actions     = entity.Actions.OrderBy(a => a.Order).Select(a => a.ToEndpointRuleDto(internalHelper)).ToList();
            dto.Permissions = entity.Permissions.OrderBy(a => a.Order).Select(ToDto).ToList();
            return(dto);
        }