Пример #1
0
        /// <summary>
        /// Update api resource
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public virtual async Task <ResultModel> UpdateApiResourceAsync(ApiResource model)
        {
            var data = await _clientsContext.ApiResources.FirstOrDefaultAsync(x => x.Id == model.Id);

            if (data == null)
            {
                return(new InvalidParametersResultModel());
            }

            data.Name        = model.Name;
            data.Enabled     = model.Enabled;
            data.Description = model.Description;

            _clientsContext.ApiResources.Update(data);
            var dbResult = await _clientsContext.PushAsync();

            if (dbResult.IsSuccess)
            {
                await ResetCacheAsync();
            }
            return(dbResult);
        }
Пример #2
0
        public async Task <JsonResult> Delete(int?id)
        {
            if (!id.HasValue)
            {
                return(Json(new { success = false, message = "Id not found" }));
            }

            var tenant = _context.ApiResources.AsNoTracking().SingleOrDefault(x => x.Id == id);

            if (tenant == null)
            {
                return(Json(new { success = false, message = "Api resource not found" }));
            }

            _context.ApiResources.Remove(tenant);
            var dbResult = await _context.PushAsync();

            return(Json(dbResult.IsSuccess
                ? new { success = true, message = "Api resource deleted !" }
                : new { success = false, message = "Error on save in DB" }));
        }