示例#1
0
        public async Task <int> IncrementQueryCount()
        {
            var statistics = await context.Statistics.FirstOrDefaultAsync();

            if (statistics == null)
            {
                statistics = new StatisticsModel();

                context.Add(statistics);

                await context.SaveChangesAsync();
            }

            statistics.QueryCount += 1;

            context.Update(statistics);

            await context.SaveChangesAsync();

            return(statistics.QueryCount);
        }
示例#2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Key,Name,Description")] SaMiKeyModel saMiKeyModel)
        {
            if (id != saMiKeyModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var protector = protectionProvider.CreateProtector(purposes);

                    saMiKeyModel.Key = protector.Protect(saMiKeyModel.Key);

                    context.Update(saMiKeyModel);

                    await context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SaMiKeyModelExists(saMiKeyModel.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(RedirectToAction(nameof(Index)));
            }

            return(View(saMiKeyModel));
        }