Ejemplo n.º 1
0
        public async Task <ApiResourceDTO> AddAsync(ApiResourceDTO dto)
        {
            var entity = dto.ToEntity();
            await Apis.AddAsync(entity);

            await Context.SaveChangesAsync();

            return(entity.ToDTO());
        }
        public async Task <IActionResult> CreateApiResource([FromBody] ApiResourceDTO apiResource)
        {
            var createdResource = await _apiResourceManager.Add(Mapper.Map <ApiResource>(apiResource));

            if (createdResource.Item1 == null)
            {
                return(BadRequest(new BadRequestResponse(ModelState, ExceptionKeyHelper.GetString(createdResource.Item2.Value))));
            }
            return(CreatedAtAction("GetByName", new { apiRessourceName = createdResource.Item1.Name }, new CreatedResponse(Mapper.Map <ApiResourceDTO>(createdResource.Item1), 1)));
        }
Ejemplo n.º 3
0
        public async Task Create([FromBody] ApiResourceDTO input)
        {
            if (await context.ApiResources.AnyAsync(x => x.Name == input.Name))
            {
                throw new Exception("已存在相同名称的资端");
            }
            var add = (new ApiResource(input.Name, input.DisplayName)).ToEntity();

            context.ApiResources.Add(add);
            await context.SaveChangesAsync();
        }
Ejemplo n.º 4
0
        public async Task <ApiResourceDTO> UpdateAsync(ApiResourceDTO dto)
        {
            var entity = dto.ToEntity();

            Apis.Attach(entity);
            await CleanupApiResourceAsync(entity);

            Apis.Update(entity);
            await Context.SaveChangesAsync();

            return(entity.ToDTO());
        }
Ejemplo n.º 5
0
        public async Task Update([FromBody] ApiResourceDTO input)
        {
            var apiresource = await context.ApiResources.FirstOrDefaultAsync(x => x.Name == input.Name);

            if (apiresource == null)
            {
                throw new Exception("不存在该资源");
            }
            context.Entry(apiresource).State = EntityState.Deleted;
            var add = (new ApiResource(input.Name, input.DisplayName)).ToEntity();

            context.ApiResources.Add(add);
            await context.SaveChangesAsync();
        }
Ejemplo n.º 6
0
        public async Task <ActionResult <ApiResourceDTO> > UpdateApiResourceAsync([FromBody] ApiResourceDTO dto)
        {
            var result = await apiResourceService.UpdateAsync(dto);

            return(Ok(result));
        }
Ejemplo n.º 7
0
 public static ApiResource ToEntity(this ApiResourceDTO dto)
 {
     return(dto == null ? null : Mapper.Map <ApiResource>(dto));
 }