Esempio n. 1
0
        public async Task <IActionResult> DestroySetting([DataSourceRequest] DataSourceRequest request, GlobalSettingViewModel viewModel)
        {
            var model = db.GlobalSettings.First(n => n.GlobalSettingId == viewModel.GlobalSettingId);

            if (ModelState.IsValid)
            {
                db.GlobalSettings.Remove(model);
                await db.SaveChangesAsync();
            }

            return(Json(await new[] { viewModel }.ToDataSourceResultAsync(request, ModelState)));
        }
Esempio n. 2
0
        public async Task <IActionResult> UpdateSetting([DataSourceRequest] DataSourceRequest request, GlobalSettingViewModel viewModel)
        {
            var model = db.GlobalSettings.First(n => n.GlobalSettingId == viewModel.GlobalSettingId);

            if (ModelState.IsValid)
            {
                await this.TryUpdateModelAsync <GlobalSettingViewModel, GlobalSetting>(model, "", m => { return(m.ElementType == null); });

                await db.SaveChangesAsync();
            }

            return(Json(await new[] { model.ToViewModel <GlobalSetting, GlobalSettingViewModel>() }.ToDataSourceResultAsync(request, ModelState)));
        }